Android Studio cannot resolve symbol common - android

I followed the migration guide from Eclipse to Android Studio carefully and the only error that I am getting is "cannot resolve symbol common" and is happening on these lines:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
Does anyone know why this would be happening?

The build tool (gradle) can't find the google_play_services library, that define the relevant classes.
Update your build.gradle file, so that it finds the library (at the right path):
[EDIT 2: since 6.5, you can selectively add needed Google Play Services APIs ]
dependencies {
compile 'com.google.android.gms:play-services-base:9.4.0'
compile 'com.google.android.gms:play-services-XXX:9.4.0'
}
[EDIT: newer method, a 'native' support is now provided]
Open SDK Manager, download and install Google Play Services and Google Repository
Edit build.gradle to add:
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
}
[Old method]
Check that google-plays-services is a module in your project, and that its build.gradle contains:
dependencies {
compile files('libs/google-play-services.jar')
}
In your module build.gradle:
dependencies {
compile project(':google-play-services')
}

In my case problem solved using other way i.e. apply plugin.
Open your build.gradle(Module: app) file and add this line to the top below the first line.
apply plugin: 'com.google.gms.google-services'
Code looks like:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
and click on sync now. Problem solved.

Related

Checking for google play services with firebase [duplicate]

Declaring dependencies as
compile 'com.google.firebase:firebase-messaging:9.4.0'
I get "can not resolve symbol GoogleApiAvailability" message in the activity's import row
import com.google.android.gms.common.GoogleApiAvailability;
What is wrong?
not question's duplicate: Google Play Services are already on the latest version
Add this line to your build file dependencies:
compile 'com.google.android.gms:play-services-base:9.4.0'
play-services-base is the Play Services base client library and is listed in the Play Services Setup Guide.
I faced same problem but in my case problem solved by just changing the position of apply plugin: 'com.google.gms.google-services' in the build.gradle(Module: app) file.
Line
apply plugin: 'com.google.gms.google-services'
was written at the last in the gradle file. Remove this from here and add it to the top, below the line apply plugin: 'com.android.application'
Like this:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
and click on sync now. Problem solved.
For my case just adding this dependency worked -
implementation "com.google.android.gms:play-services-location:16.0.0
If your using the latest classpath 'com.google.gms:google-services:4.3.10', for checking the Google PlayServices Availability you can use GoogleApiAvailabilityLight

Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed

I just updated Google play services to the latest release - 23 - in the Android SDK Manager. Next I updated dependency in my project to:
com.google.android.gms:play-services-gcm:8.3.0
But I got:
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
:app:processDebugGoogleServices FAILED
Error:Execution failed for task ':app:processDebugGoogleServices'.
> Please fix the version conflict.
What is wrong? Do you have this problem also?
In your top-level build.gradle file you need to update the dependencies to use
classpath 'com.google.gms:google-services:1.5.0-beta2'
Extra Info:
The latest version of this can be found by looking at the entry on JFrog Bintray
Further Update:
Yes this has been updated since I answered the question. The latest version is:
classpath 'com.google.gms:google-services:3.0.0'
However, it's always worth following the provided link to find the latest version.
Working solution for 8.4.0 (maybe same for previous versions too with this crazy issue)
project build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:2.1.2'
}
app/mobile build.gradle
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'android-apt'
android {
...
...
...
}
dependencies {
// Google Play Services
compile 'com.google.android.gms:play-services-analytics:8.4.0'
// another play services in v8.4.0
}
apply plugin: 'com.google.gms.google-services' // why here on end? Because GOOGLE...
WARNING:
When you move apply plugin: 'com.google.gms.google-services' on top of build gradle, it can not compile...
The Google Play Services guides saved me from this problem
According to the guide,
In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.
From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:
compile 'com.google.android.gms:play-services:8.4.0'
with these lines:
compile 'com.google.android.gms:play-services-fitness:8.4.0'
compile 'com.google.android.gms:play-services-wearable:8.4.0'
I encountered this issue as well, although mine was
Found com.google.android.gms:play-services-gcm:8.4.0, but version
8.3.0 is needed
To fix, I combined Jeff Sutton and mtrakal's answers. I had to make sure I was using the latest Gradle plugin and Google Services versions in the project-level Gradle file (I had Gradle 1.5 and it didn't work):
classpath 'com.google.gms:google-services:2.0.0-beta6'
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
Then I put the apply plugin: 'com.google.gms.google-services' line in the last line of the app Gradle file.
In your top-level build.gradle file you need to change the dependencies to
classpath 'com.google.gms:google-services:+'
I am also getting the same of conflict com.google.android.gms:play-services-gcm:8.3.0 then
I have updated the google playservice tool then it has been resolved
From the SDK manager selected the tool and update now it resolve

Using google Place picker in android project

I am trying to learn Google's place picker
I have used the sample project from here
I have linked playservices library for the sample project
Resolved all the dependencies
Problem:
Some depedencies r not resolved ther are,
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
Question:
How to solve this
Should I need to add any other project references
follow this way :
Open the build.gradle file inside your application module directory.
Add a new build rule under dependencies for the latest version of play-services.
For example:
apply plugin: 'com.android.application'
...
dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:7.0.0'
}
Be sure you update this version number each time Google Play services is updated.
Save the changes and click Sync Project with Gradle Files in the toolbar.
Answering because I had te same problem.
I needed to add 'com.google.android.gms:play-services-places to my project.
in the app's build.gradle I added
dependencies {
...
compile 'com.google.android.gms:play-services-places:10.2.6'
}

Android Studio library "error: package does not exist"

I have created Android library as Android Studio module. Added as dependency to my root module. While coding I can import any class from library package but while I'm trying run the application I'm getting an error package some.mylibrary.project does not exist.
build.gradle root module
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:5.+'
compile project(':libraries:mylibrary')
}
android {
compileSdkVersion 17
buildToolsVersion "20.0.0"
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
abortOnError false
}
***
}
build.gradle library module
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'idea'
android {
compileSdkVersion 17
buildToolsVersion "20.0.0"
*****
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
settings.gradle
include ':libraries:mylibrary'
P.S. I have to mention that the project was exported from Eclipse IDE so the project structure is different from default one.
For Android Studio 2.2.2
Yes, in library module, it can't use the apply plugin: com.android.application statement in the module definition, yes, use apply plugin: com.android.library instead. (still in lib module)
But then you have to do the following:
Expose the same SDK versions in Gradle files for both modules.
Right click on your projects "app" module folder and click on -> open module settings
Click on the "dependencies" tab
Click on the + sign to add a new dependency and select "Module Dependency"
Look for the library you need and add it.
Also while naming your lib module avoid capitals.
If you have a library module, it can't use the apply plugin: 'com.android.application' statement in the module definition, or the build will silently fail as you're seeing. use apply plugin: 'com.android.library' instead.
A bug has been filed to request that the build system fail loudly instead of silently when this happens: https://code.google.com/p/android/issues/detail?id=76725
The answer above is somewhat lacking
If you project java add in Kotlin getting get this error
Tools Tab Kotlin and Configure Kotlin
(Select Android with Gradle) after select with Modules
Project build.gradle add
ext.kotlin_version = ‘1.3.21’
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Apps build.gradle
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Referance : https://medium.com/mindorks/enabling-kotlin-support-for-a-current-only-java-android-project-98c75e04384a
This error happens when you change the package name and try to run the code. this occurs because the android studio still has the cache of your package with an old name.
Also, cross-check all the imports as well as an imported package in your code so that no different package name exists. For example, is common this error is referring to another imported file near where the error is occurring. Check previous imports near.
To fix this error you can try to do an 'invalidate caches / Restart' option from the File menu in android studio. Choose “Invalidate and restart option” and close Android Studio.
Another reason for this error, is when one changes the project's path root folder or in any of the modules it depends. In this particular case, to fix this error you need to remove the affected modules, and re-add them again. Next don't forget to do an 'invalidate caches / Restart' option from the File menu in android studio. Choose “Invalidate and restart option” and close Android Studio.
Clean your project from android studio :
“Build -> Clean Project”. This will clear your build folders.
Remove your .gradle directory from the root of your project. It contains some Gradle cache files.
Delete also the .idea directory (make a backup before). It contains some project configuration files.
Restart Android Studio.
Finally
if the error still persists, you need to move the affected files to an external directory of the project's root folder. And on Android Studio, create manually each filename as previous, and copy the code inside from the old file. This will defiantly solve this error.
In build-gradle app, add this row:
implementation project(":your_name_library_here")
If you are facing this issue while using Kotlin and have
kotlin.incremental=true
kapt.incremental.apt=true
in the gradle.properties, then you need to remove this temporarily to fix the build.
After the successful build, you can again add these properties to speed up the build time while using Kotlin.
Reference: https://stackoverflow.com/a/58951797/3948854

Error:(2, 0) Plugin with id 'android-test' not found

I am trying to implement Android-DirectoryChooser in my app, but I am new to Android Studio and I have come to a problem that I am not sure how to resolve.
I have created a new folder inside my project called "libraries" and I have copied this library project inside this folder. I then added a dependency like this:
compile project('libraries:android-directorychooser')
I then synced gradle and I have gotten the following error:
Error:(2, 0) Plugin with id 'android-test' not found.
This is probably the problematic line in the project library build.gradle file:
apply plugin: 'android-test'
I've searched for a plugin named "android-test" but I've only found a library and it seems to be deprecated. How can I solve this?
Know you for what this plugin is necessary? When not remove it and your robolectric dependencies.
Plugin comes from https://github.com/robolectric/gradle-android-test-plugin
Robolectric is for unit tests, when you like to use it.(which I would recommend) then just add something like that
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.+'
}
}
to your lib module build.gradle file and the plugin should be found
Android-test is no longer a separate plugin. The standard 'android' plugin now includes testing features. See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing for more information.

Categories

Resources