Cannot resolve symbol 'GoogleApiClient' - android-studio

I am trying to upgrade my Google Play Services library so I can use the newest Android Gradle (3.2) and Android SDK version (28). The issue is all of my GMS imports cannot be resolved.
Examples:
import com.google.android.gms.common.api.GoogleApiClient;
and
import com.google.android.gms.games.Games;
I've already looked at various questions that have issues with importing these libraries but none are up-to-date or appear to fix my issue. I've tried invalidating cache/restart, clean/rebuild project. Currently I am importing a google-play-services_lib library, which has the bundled GMS as a dependency: com.google.android.gms:play-services:12.0.1
My project build.gradle:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://jitpack.io' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
}
apply plugin: 'com.android.application'
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
compileSdkVersion 28
defaultConfig {
applicationId "com.example.exampleapp"
minSdkVersion 14
targetSdkVersion 28
versionCode 34 // increment with every release
versionName '3.0.5' // change with every release
setProperty("archivesBaseName", "example_$versionName")
}
signingConfigs {
release {
keyAlias = "example key alias"
}
}
buildTypes {
release {
minifyEnabled true
}
}
}
dependencies {
implementation project(':google-play-services_lib')
implementation project(':appcompat_v7')
}
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
My module/app build.gradle:
buildscript {
repositories {
google()
jCenter()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v4:22.0.0'
compile 'com.google.android.gms:play-services:12.0.1'
}
android {
compileSdkVersion 28
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Hopefully there is a way to resolve these import errors, which seems to be a disconnect between the gradle building of support libraries and the actual project itself...

Found it. For a migration from way-way back (like target API <= 21), get rid of using the bundle/manual library and stick with a newer Gradle version:
Remove the meta tag from Android Manifest that specifies a Google Play Services version (the bundled version)
Remove your google-play-services_lib
Add the necessary GMS dependencies to the project-level build.gradle, whether manually or in File → Project Structure → MyApp Module → Dependencies tab and add library, even if it doesn't show in the new Android Studio's library search.
Example: implementation 'com.google.android.gms:play-services-base:16.0.1'
I know this was fairly obvious but this might be a good post for migrating somewhat-old Android apps that use GMS to newer versions. This at least lets you pick which GMS modules to use rather than the bulky bundle.

Related

How to apply JaCoCo to build.gradle?

I wanted to add JaCoCo to an existing Android Studio Project. In my settings.gradle I edited:
pluginManagement {
gradle.ext.kotlin_version = "1.6.0"
repositories {
google()
mavenCentral()
}
def versionsProp = new Properties()
versionsProp["myapp.version.level"] = "7.1.0-beta05"
def versionsPropFile = file("local.properties")
if (versionsPropFile.canRead()) {
versionsProp.load(new FileInputStream(versionsPropFile))
}
def levelVersion = versionsProp["myapp.version.level"]
plugins {
id("com.android.application") version "$levelVersion"
id("com.android.library") version "$levelVersion"
id("org.jetbrains.dokka") version "1.4.30"
id("org.jetbrains.kotlin.android") version "$gradle.ext.kotlin_version"
id("org.jacoco.core") version "0.8.7"
} }
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
mavenLocal()
} }
rootProject.name = "TestApp"
include ":app"
include ":mylib_1"
include ":mylib_2"
include ":docs"
Especially I added JaCoCo in plugins section. According to this medium article :
Now inside each module’s build.gradle file apply the newly created
jacoco.gradle as such: apply from: "$project.rootDir/jacoco.gradle"
But in my app modules build gradle (I've shortened away stuff commented there) I have follwing structure:
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}
android {
compileSdkVersion = 31
buildToolsVersion = "31.0.0"
defaultConfig {
applicationId = "org.example.myapp"
// minSdkVersion(21), targetSdkVersion(31) ..
}
// buildTypes, flavorOptions, compose options
// compile options, kotlinOptions, buildFeatures, packagingOptions, lintOptions
}
dependencies {
implementation(fileTree(include: ["*.jar"], dir: "libs"))
implementation("androidx.activity:activity-compose:$compose_activity_version")
implementation("androidx.appcompat:appcompat:$appcompat_version")
testImplementation("junit:junit:4.13.2")
implementation(project(":org_mylib_1"))
implementation(project(":org_mylib_2"))
}
So where or how am I supposed to add the apply from: "$project.rootDir/jacoco.gradle"?

Android Gradle Failed to resolve

I am getting this error in the gradle file:
Error: Failed to resolve: com.google.android.gms:play-services-measurement:10.2.4
-Install Repository and sync project
-Open File
-Show in Project Structure dialog
But I don't use the play-services-measurement in my app.
In the other hand, if I click on the link "Install Repository and sync project" nothing happens.
Any could help me with this? I have been wasting days with this issue.
This is my full gradle file:
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileOptions {
encoding "UTF-8"
}
lintOptions {
disable 'MissingTranslation'
abortOnError false
}
defaultConfig {
applicationId "xxx.yyy.zzz"
minSdkVersion 9
targetSdkVersion 25
versionCode 120
versionName "1.20"
multiDexEnabled true
//Enabling multi dex support due to exceeding the 65K methods dex limit imposed by Android: http://stackoverflow.com/questions/29756188/java-finished-with-non-zero-exit-value-2-android-gradle
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def formattedDate = new Date().format('yyyyMMddHHmmss')
def newName = output.outputFile.name
newName = newName.replace("app-", "MyAppName")
newName = newName.replace("-release", "-release" + formattedDate)
//noinspection GroovyAssignabilityCheck
output.outputFile = new File(output.outputFile.parent, newName)
}
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':simple-crop-image-lib')
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-messaging:10.2.4'
compile 'com.google.android.gms:play-services:10.2.4' //8.3.0' 10.2.4' 9.0.0' 9.6.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:mediarouter-v7:25.3.1'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
//For soap:
compile files('libs/ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar')
}
apply plugin: 'com.google.gms.google-services'
Update Google Repository in Android SDK. Works for me with version 47.
From the firebase doc:
dependencies {
// ...
compile 'com.google.firebase:firebase-core:10.2.4'
compile 'com.google.firebase:firebase-messaging:10.2.4'
// Getting a "Could not find" error? Make sure you have
// the latest Google Repository in the Android SDK manager
}
For me worked to remove these lines from the "app build.gradle":
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
}
}
And add these to the "project build.gradle":
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

Compile two apps, but running only one module with Android Studio

I have two android projects 'East' & 'ChoosePDF' in Eclipse. 'East' is the main app, the other is a pdf library.
I try to export them from Eclipse to Android Studio.
When I try to run 'East' module, there are two apps installed in device. 'ChoosePDF' is also installed as an app, which should be only complied as a library.
In the 'app managerment' setting, it shows as one app. But in device's desktop, these are two same icons.
This is the project's build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
project's settings.gradle is:
include ':ChoosePDF'
include ':East'
Here is module 'East's build.gradle, which is the main project in Eclipse.
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':ChoosePDF')
}
android {
compileSdkVersion 21
buildToolsVersion "23.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
And this is the dependency library's build.gradle.
apply plugin: 'com.android.library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "23.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
I really don't know how it happens. Try to comment out the 'ChoosePDF' in settings.gradle, doesn't work. Try to remove something in 'ChoosePDF's build.gradle, doesn't work.
Really need help to fix it, thanks.

The project is using an unsupported version of the Android Gradle plug-in (0.12.2). The recommended version is 1.3.0 in Android studio 1.4.1

The problem worry me few days, I download the newest Android studio, and import the source code of library project from my old eclipse project, I tried solve the problem by many post, but still bad luck, there is my build.gradle, the content of android block is generate by android studio.
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0' }
}
android {
compileSdkVersion 20
buildToolsVersion "21.1.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
This is my gradle-wrapper.properties, the code is generate by Android studio.
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
and my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="es.disegnator"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="23" />
It still show the message:
Gradle sync failed: The project is using an unsupported version of the Android Gradle plug-in (0.12.2). The recommended version is 1.3.0.
Please help me solve the problem.

Pulltorefresh add to gradle

can anyone help me add this library in build.gradle Android Studio.
https://github.com/chrisbanes/Android-PullToRefresh
I know it is deprecated but I want to use it, I would appreciate if someone could help me
what to write in
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile 'com.android.support:appcompat-v7:+'
compile '????'
}
as mentioned I want to use the deprecated library not new Actionbar-Pulltorefresh. tried to google it but couldn't find any help.
I suggest you to use ActionBarPullToRefresh (same author).
However, if you would like to use PullToRefresh, you have to clone the lib locally in a folder, and then add it as local dependency. This lib isn't on Central Maven as aar.
root
app
build.gradle
lib
pull
src
res
build.gradle
settings.gradle
In you app/build.gradle you have to add:
dependencies {
// Library
compile project(':lib:pull')
}
In lib/pull/build.gradle you have to define it as library and specify the right sourceset (it is a gist):
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['aidl']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
In settings.gradle:
include ':lib:pull' ,':app'
Easiest way to add ActionBar-PullToRefresh to your project is via Gradle, you just need to add the following dependency to your build.gradle
dependencies {
repositories {
mavenCentral()
}
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
Rest gradle will do all work for you.
I've succesfully imported the libproject in Android Studio 1.0. The steps are the following
1.- Download and install PullToRefresh from the official GitHub. Unzip it.
2.- Create an empty Android Studio project. Mine is named "PrjLibDeps"
3.- In project's root folder, create a folder named "libs". Inside libs/, copy a "pulltorefresh" folder containing the unzipped file. Structure remains as shown below:
PrjLibdeps
| settings.gradle
| build.gradle
| libs
| pulltorefresh
| src, res, LICENSE, pom.xml...
| app/
| build.gradle
| src
| ...
4.- Create a build.gradle file inside "pulltorefresh" folder. Copy-paste this sample code and set proper values to compileSdkVersion, buildToolsVersion, minSdkVersion, targetSdkVersion (just copy them from app/build.gradle)
apply plugin: 'com.android.library'
dependencies {
compile 'com.android.support:support-v4:21.0.3'
}
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 20
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
5.- on app/build.gradle
dependencies {
compile project(":PullToRefresh")
}
6.- Now, on project_root/settings.gradle:
include ‘:app', ':PullToRefresh'
project (':PullToRefresh').projectDir = new File('libs/pulltorefresh')
7.- "Sync now"
8.- CMD+F9 (Make project)
Hope it helps!
more detailed info in my blog

Resources