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 theAndroidManifest.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.
From my experience (Eclipse):
That is irrelevant, as that is for Maps V1, and you are trying to use Maps V2.
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.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
In my case or all using android studio
you can import google play service
place in your
build.gradle
or latest version of play services depend in time you watch this answer
please review this individual gradle imports
https://developers.google.com/android/guides/setup
Google Maps
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
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...