The import com.google.android.gms cannot be resolved - android

I am new to Android development. By following this tutorial I got errors The import com.google.android.gms cannot be resolved when I wrote the code into the MainActivity.java:
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
By searching for various fixes I made sure to try these out:
I have downloaded Google API's for a particular API level through
Android SDK manager.
I checked off Google API as project build target.
I have added <uses-library android:name="com.google.android.maps" />
line into the AndroidManifest.xml as a child of <application> tag.
I cleaned the project by selecting Project->Clean... and built it
from scratch.
I included .jar file for maps by right-clicking on my project, went
to build path and added external archive locating it in my SDK: android-sdk-windows\add-ons\addon_google_apis_google_inc_8\libs\maps
Unfortunately, none of the above have helped.

Another way is to let Eclipse do the import work for you. Hover your mouse over the com.google.android.gms import that can not be resolved and towards the bottom of the popup menu, select the Fix project setup... option as below. Then it'll prompt to import the google play services library. Select that and you should be good to go.

I checked off Google API as project build target.
That is irrelevant, as that is for Maps V1, and you are trying to use Maps V2.
I included .jar file for maps by right-clicking on my project, went to build path and added external archive locating it in my SDK: android-sdk-windows\add-ons\addon_google_apis_google_inc_8\libs\maps
This is doubly wrong.
First, never manually modify the build path in an Android project. If you are doing that, at best, you will crash at runtime, because the JAR you think you put in your project (via the manual build path change) is not in your APK. For an ordinary third-party JAR, put it in the libs/ directory of your project, which will add it to your build path automatically and add its contents to your APK file.
However, Maps V2 is not a JAR. It is an Android library project that contains a JAR. You need the whole library project.
You need to import the android-sdk-windows\add-ons\addon_google_apis_google_inc_8 project into Eclipse, then add it to your app as a reference to an Android library project.

From my experience (Eclipse):
Added google-play-services_lib as a project and referenced it from my app.
Removed all jars added manually
Added google-play-services.jar in the "libs" folder of my project.
I had some big issues because I messed up with the Order and Export
tab, so the working solution is (in this order): src, gen, Google APIs, Android Dependencies, Android Private Libraries (only this one checked to be exported).

In my case or all using android studio
you can import google play service
place in your build.gradle
compile 'com.google.android.gms:play-services:7.8.0'
or latest version of play services depend in time you watch this answer
More Specific import
please review this individual gradle imports
https://developers.google.com/android/guides/setup
Google Maps
com.google.android.gms:play-services-maps:7.8.0
error may occurred
if you face error while you sync project with gradle files
make sure you install latest update
1- Android Support Repository.
2- Android Support Library.
3- Google Repository.
4-Google Play Services.
You may need restart your android studio to response

Note that once you have imported the google-play-services_lib project into your IDE, you will also need to add google-play-services.jar to:
Project=>Properties=>Java build path=>Libraries=>Add JARs

Above solutions should solve your problem. If these do not, make sure you update your Android sdk using SDK manager and install the latest lib project and then repeat the above steps again.

once again Make sure these 2 things happen correctly nothing more than that.
(FOR ECLIPSE USERS)
1) copy the jar file from --> C:\Users(your-username)\android-sdks\extras\google\google_play_services\libproject\google-play-services_lib\libs\ google-play-services.jar
2) Right Click Project--> Build Path -> Add External Archive-> google-play-services.jar

In Android Studio goto:
File -> Project Structure... -> Notifications (last entry) -> check Google Cloud Messaging
Wait a few seconds and you're done :)
import com.google.android.gms.gcm.GcmListenerService should be resolved properly

I too had the same issue. Got it resolved by compiling with the latest sdk tool versions.(Play services,build tools etc). Sample build.gradle is shown below for reference.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.abc.bcd"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:appcompat-v7:23.0.1'
}

Supposing that you are using ECLIPSE:
Right click PROJECT
PROPERTIES
ANDROID
If you have a version of ANDROID checked, you must change it to a GOOGLE API.
Choose a version of GOOGLE APIS compatible with your project's target version.

In my case just add the below code to the build.gradle(:app)
implementation 'com.google.android.gms:play-services-location:16.0.0'

In my case only after I added gcm.jar to lib folder, it started to work.
It was here: C:\adt-bundle-windows-x86_64-20131030\sdk\extras\google\gcm\gcm-client\dist
So the google-play-services.jar didn't work...

I had the same problem so that the dumb API I decided as follows
changing the import line
import com.google.android.gms.maps.model.LatLng;

Related

Error adding Google AdMob on Android libraries - LIBGDX project

I would like to add the Google library to my project libgdx in Android Studio. Currently I have done:
opened the SDK manager and downloaded play-services from the SDK manager,
added the compile string in build.gradle:
compile 'com.google.android.gms:play-services:8.4.0'
Clicked on File -> Project Structure -> choose the project and added the library play-services 8.4.0.
When I do the sync it gives me this error:
If I click on Install and sync repository project I get an error, this:
Another test:
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
If you manually add this library, after all the steps listed... I do not recognize them and it always fails. How do I add? Thank you.
also tried to Add Google Play Services to my project, but with unsuccess :(
My goal is to use AdMob banner.
Looks like at least a few people have had this error before:
Failed to resolve: com.google.android.gms:play-services-gcm:7.5.+
I would try opening the full-on SDK manager (Tools >> Android >> SDK Manager). You can manually download the Google Repository (and any other dependencies) using it.

Android Studio - Top Level Exception - Support Lib via maven

i'm working with android studio and i have an issue... i import 2 libraries (facebook SDK and Aws) that both use and import the android support v4 libs, doing that gradle can't compile anything giving a bad top-level exception (dexDebug).
In others answer i saw that i can solve this situation in 2 ways, removing one of the libs (but i can't because i need both) or using the "multipledex = true" in build.gradle that give me another error for the length of the command.
So, what i should do? Shall i stop using AS and go back to Eclipse? Or anybody have a solution?
Thanks,
Andrea
Don't import the support library by copying its jar as you used to in Eclipse. In Gradle, access it via its Maven coordinates and the build system will ensure that only one copy gets linked into your project:
dependencies {
compile 'com.android.support:support-v4:X.X.X'
}
where X.X.X is the right version number for your SDK installation. If you manage the dependency via Project Structure > (your module) > Dependencies > + > Library dependency it will help you get the version number right.

Cannot resolve symbol 'google' [duplicate]

I am new to Android development. By following this tutorial I got errors The import com.google.android.gms cannot be resolved when I wrote the code into the MainActivity.java:
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
By searching for various fixes I made sure to try these out:
I have downloaded Google API's for a particular API level through
Android SDK manager.
I checked off Google API as project build target.
I have added <uses-library android:name="com.google.android.maps" />
line into the AndroidManifest.xml as a child of <application> tag.
I cleaned the project by selecting Project->Clean... and built it
from scratch.
I included .jar file for maps by right-clicking on my project, went
to build path and added external archive locating it in my SDK: android-sdk-windows\add-ons\addon_google_apis_google_inc_8\libs\maps
Unfortunately, none of the above have helped.
Another way is to let Eclipse do the import work for you. Hover your mouse over the com.google.android.gms import that can not be resolved and towards the bottom of the popup menu, select the Fix project setup... option as below. Then it'll prompt to import the google play services library. Select that and you should be good to go.
I checked off Google API as project build target.
That is irrelevant, as that is for Maps V1, and you are trying to use Maps V2.
I included .jar file for maps by right-clicking on my project, went to build path and added external archive locating it in my SDK: android-sdk-windows\add-ons\addon_google_apis_google_inc_8\libs\maps
This is doubly wrong.
First, never manually modify the build path in an Android project. If you are doing that, at best, you will crash at runtime, because the JAR you think you put in your project (via the manual build path change) is not in your APK. For an ordinary third-party JAR, put it in the libs/ directory of your project, which will add it to your build path automatically and add its contents to your APK file.
However, Maps V2 is not a JAR. It is an Android library project that contains a JAR. You need the whole library project.
You need to import the android-sdk-windows\add-ons\addon_google_apis_google_inc_8 project into Eclipse, then add it to your app as a reference to an Android library project.
From my experience (Eclipse):
Added google-play-services_lib as a project and referenced it from my app.
Removed all jars added manually
Added google-play-services.jar in the "libs" folder of my project.
I had some big issues because I messed up with the Order and Export
tab, so the working solution is (in this order): src, gen, Google APIs, Android Dependencies, Android Private Libraries (only this one checked to be exported).
In my case or all using android studio
you can import google play service
place in your build.gradle
compile 'com.google.android.gms:play-services:7.8.0'
or latest version of play services depend in time you watch this answer
More Specific import
please review this individual gradle imports
https://developers.google.com/android/guides/setup
Google Maps
com.google.android.gms:play-services-maps:7.8.0
error may occurred
if you face error while you sync project with gradle files
make sure you install latest update
1- Android Support Repository.
2- Android Support Library.
3- Google Repository.
4-Google Play Services.
You may need restart your android studio to response
Note that once you have imported the google-play-services_lib project into your IDE, you will also need to add google-play-services.jar to:
Project=>Properties=>Java build path=>Libraries=>Add JARs
Above solutions should solve your problem. If these do not, make sure you update your Android sdk using SDK manager and install the latest lib project and then repeat the above steps again.
once again Make sure these 2 things happen correctly nothing more than that.
(FOR ECLIPSE USERS)
1) copy the jar file from --> C:\Users(your-username)\android-sdks\extras\google\google_play_services\libproject\google-play-services_lib\libs\ google-play-services.jar
2) Right Click Project--> Build Path -> Add External Archive-> google-play-services.jar
In Android Studio goto:
File -> Project Structure... -> Notifications (last entry) -> check Google Cloud Messaging
Wait a few seconds and you're done :)
import com.google.android.gms.gcm.GcmListenerService should be resolved properly
I too had the same issue. Got it resolved by compiling with the latest sdk tool versions.(Play services,build tools etc). Sample build.gradle is shown below for reference.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.abc.bcd"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:appcompat-v7:23.0.1'
}
Supposing that you are using ECLIPSE:
Right click PROJECT
PROPERTIES
ANDROID
If you have a version of ANDROID checked, you must change it to a GOOGLE API.
Choose a version of GOOGLE APIS compatible with your project's target version.
In my case just add the below code to the build.gradle(:app)
implementation 'com.google.android.gms:play-services-location:16.0.0'
In my case only after I added gcm.jar to lib folder, it started to work.
It was here: C:\adt-bundle-windows-x86_64-20131030\sdk\extras\google\gcm\gcm-client\dist
So the google-play-services.jar didn't work...
I had the same problem so that the dumb API I decided as follows
changing the import line
import com.google.android.gms.maps.model.LatLng;

Can't import ActionBarCompat from Android Support Library using Android Studio

I am using Android Studio and have followed this article from google as well as some other articles discussing how to use the new ActionBarCompat.
I have downloaded the support library (Rev. 18) in Android SDK Manager and added the following in my build.gradle
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile 'com.android.support:appcompat-v7:18.0.0'
}
Now I'm trying to import the Support Library API and extend ActionBarActivity in my code,
however, this is what showed up
which is not what it is supposed to be
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
Any Help?
I have the same problem. I followed this step to solved it, in Android Studio - Tools -> Android -> Sync Project with Gradle Files.
Edit:
Sorry, I forgot add this:
After Sync Project with Gradle Files follow this steps:
Right mouse click for your project and select Open Module Settings
After that, select dependencies tab
In the end - selec your library:
This should work.

Android Studio with Google Play Services

I'm trying to test Google Play Services with the new Android Studio.
I have a project with a dependency to the google_play_services.jar.
But when I try to Rebuild the project I get the following errors:
Information:[TstGP3-TstGP3] Crunching PNG Files in source dir: C:\Users\ans\AndroidStudioProjects\TstGP3\TstGP3\src\main\res
Information:[TstGP3-TstGP3] To destination dir: C:\Users\ans\AndroidStudioProjects\TstGP3\build\classes\res-cache\TstGP3-TstGP3
Information:Compilation completed with 2 errors and 0 warnings in 2 sec
Information:2 errors
Information:0 warnings
C:\Users\ans\.AndroidStudioPreview\system\compiler\tstgp3.3f17bd41\.generated\Android_BuildConfig_Generator\TstGP3-TstGP3.74fc5b25\production\com\example\tstgp3\BuildConfig.java
Error:Error:line (4)error: duplicate class: com.example.tstgp3.BuildConfig
C:\Users\ans\.AndroidStudioPreview\system\compiler\tstgp3.3f17bd41\.generated\aapt\TstGP3-TstGP3.74fc5b25\production\com\example\tstgp3\R.java
Error:Error:line (10)error: duplicate class: com.example.tstgp3.R
It seems that it has two BuildConfig files and also two R classes. How can I resolve the issue?
EDIT:
I have noticed that the compiler compiles two R.java files: the one that is in my project folder and another one that is located in the folder %USERPROFILE%.AndroidStudioPreview
So, I tried to exclude this "Preview" folder in the compiler settings and now it's working.
This issue only occurs after I have started to use Google Play Services classes in my project.
I will appreciate if someone can explain the reason behind this problem.
All those answers are wrong, since the release of gradle plugin v0.4.2 the setup of google play services under android studio is straight forward. You don't need to import any jar or add any project library nor add any new module under android studio. What you have to do is to add the correct dependencies into the build.gradle file. Please take a look to those links: Gradle plugin v0.4.2 update, New Build System, and this sample
The Correct way to do so is as follows:
First of all you have to launch the sdk manager and download and install the following files located under "extras": Android support repository, Google play services, Google repository.
Restart android studio and open the build gradle file. You must modify your build.gradle file to look like this under dependencies:
dependencies {
compile 'com.google.android.gms:play-services:6.5.87'
}
And finally syncronise your project (the button to the left of the AVD manager).
Since version 6.5 you can include the complete library (very large) or just the modules that you need (Best Option). I.e if you only need Google Maps and Analytics you can replace the previous example with the following one:
dependencies {
compile 'com.google.android.gms:play-services-base:6.5.87'
compile 'com.google.android.gms:play-services-maps:6.5.87'
}
You can find the complete dependency list here
Some side notes:
Use the latest play services library version. If it's an old version, android studio will highlight it. As of today (February 5th is 6.5.87) but you can check the latest version at Gradle Please
After a major update of Android Studio, clean an rebuild your project by following the next instructions as suggested in the comments by #user123321
cd to your project folder
./gradlew clean
./gradlew build
Go to File -> Project Structure
Select 'Project Settings'
Select 'Dependencies' Tab
Click '+' and select '1.Library Dependencies'
Search for : com.google.android.gms:play-services
Select the latest version and click 'OK'
Voila! No need to fight with Gradle :)
EDITED: This guy really brought it home and has a good little tutorial
http://instantiatorgratification.blogspot.com/2013/05/google-play-services-with-android-studio.html
one side note: I had played around so much that I needed to do a gradlew clean to get it to run succesfully
If you have imported your project or are working from the Sample Maps application located in \extras\google\google_play_services\samples\maps check out this tutorial.
https://stackoverflow.com/a/16598478/2414698
If you are creating a new project from scratch then note Xav's comments on that same post. He describes that Android Studio uses a different compiler and that you have to modify the build.gradle file manually. I did this with success. I copied
google-play-services.jar
google-play-services.jar.properties
into my lib directory and added the following to my build.gradle file
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/google-play-services.jar')
}
Also, if this is a new project check out this post, too.
https://stackoverflow.com/a/16671865/2414698
Most of these answers only address compile-time dependencies, but you'll find a host of NoClassDef exceptions at runtime. That's because you need more than the google-play-services.jar. It references resources that are part of the library project, and those are not included correctly if you only have the jar.
What worked best for me was to first get the project setup correctly in eclipse. Have your project structured so that it includes both your app and the library, as described here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup
Then export your app project from eclipse, and import into Android Studio as described here: http://developer.android.com/sdk/installing/migrate.html. Make sure to export both your app project and the google play services library project. When importing it will detect the library project and import it as a module. I just accepted all defaults during the project import process.
Google Play services Integration in Android studio.
Step 1:
SDK manager->Tools Update this
1.Google play services
2.Android Support Repository
Step 2:
chance in build.gradle
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.0.+'
}
Step 3:
android.manifest.xml
<uses-sdk
android:minSdkVersion="8" />
Step 4:
Sync project file with grandle.
wait for few minute.
Step 5:
File->Project Structure find error with red bulb images,click on go to add dependencies select your app module.
Save
Please put comment if you have require help.
Happy coding.
None of the above solution worked for me. Not sure if it is specific to my setup or new release.
I am using Android Studio Beta 0.8.9 and I was not getting any com.google.android.gms:play-service in the library list on following this instruction:
Go to File -> Project Structure -> Select Project Settings -> Select 'Dependencies' Tab Click '+' -> 1.Library Dependencies -> Select com.google.android.gms:play-services:+
I had already done this:
First of all you have to launch the sdk manager and download and install the following files located under "extras": Android support repository, Google play services, Google repository.
What resolved it was to add from SDK Manager, "Google play services for Froyo" then repeating the first step.
Did not understand the reason properly but this worked.
PS: I just observed that even now when I search for play-services this does not come, but when I directly scroll and look through the list it is right there.
Follow this article -> http://developer.android.com/google/play-services/setup.html
You should to choose Using Android Studio
Example Gradle file:
Note: Open the build.gradle file inside your application module
directory.
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "{applicationId}"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:6.1.+'
}
You can find latest version of Google Play Services here: https://developer.android.com/google/play-services/index.html
I've got this working after doing the following:
Have the google-play-services-lib as a module (note difference between module and project), then add the google-play-services.jar to your models "libs" directory.
After that add the jar to your build path through making a library or add the jar to another library. I generally have a single IDEA library which I add all my /libs/*.jar files to.
Add the library to your modules build path through Module Settings (F4).
Add the google-play-services-lib as a module dependency to your project.
Done!
Note: This doesn't give me the runtime exceptions either, it works.
Open your project build.gradle file and add below line under dependencies module.
dependencies {
compile 'com.google.android.gms:play-services:7.0.0'
}
The below will be add Google Analytics and Maps if you don't want to integrate full library
dependencies {
compile 'com.google.android.gms:play-services-analytics:7.0.0'
compile 'com.google.android.gms:play-services-maps:7.0.0'
}
In my case google-play-services_lib are integrate as module (External Libs) for Google map & GCM in my project.
Now, these time require to implement Google Places Autocomplete API but problem is that's code are new and my libs are old so some class not found:
following these steps...
1> Update Google play service into SDK Manager
2> select new .jar file of google play service (Sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs) replace with old one
i got success...!!!
I copied the play libs files from the google-play-services_lib to my project libs directory:
google-play-services.jar
google-play-services.jar.properties.
Then selected them, right-click, "Add as libraries".

Categories

Resources