Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add google-play-services.jar project dependency so my project will run and present map

Tags:

I have following problem: I try to use SupportMapFragment from com.google.android.gms.maps.SupportMapFragment which is part of Google Maps Android API v2.

My first approach was to add project to Eclipse from android-sdk\extras\google\google_play_services\libproject\google-play-services_lib location and set it as referenced project in Properties -> Project References menu of MyApp. I also added project to Java Build Path / Projects. Error indicators disappeared from Eclipse but when I tried to run my app I got NoClassDefFoundError exception.

So my second approach was to copy jar file from google-play-services_lib/libs to my project's libs directory. MyApp succesfully started but in LogCat I can see dead code ... something message so I guess that jar file has to be referenced in another way.

And now I am confused and tired..
Maybe someone more experienced in Android can tell me what should I do ?

like image 785
MichK Avatar asked Dec 05 '12 03:12

MichK


People also ask

How do I import Google Play Services?

To do this, select File > Import, and then select Android > Existing Android Code into Workspace, and browse to the google-play-services_lib project. After google-play-services_lib is successfully imported into your workspace, it needs to be marked as an Android library project.

Why Google Play Services is not supported by my device?

Go To Settings> Security > Device Administators> Disable Android Device manager. Now Go to Apps and Disable Google Play Services and Clear Its data, Clear Data of Play Store too. Reboot device andd Enable Google Play Services.

What is Google Play Services API?

Google Play services powers a broad set of APIs and services on Android to help you build your app, enhance privacy and security, engage users, and grow your business.


1 Answers

The quick start guide that keyboardsurfer references will work if you need to get your project to build properly, but it leaves you with a dummy google-play-services project in your Eclipse workspace, and it doesn't properly link Eclipse to the Google Play Services Javadocs.

Here's what I did instead:

  1. Install the Google Play Services SDK using the instructions in the Android Maps V2 Quick Start referenced above, or the instructions to Setup Google Play Services SDK, but do not follow the instructions to add Google Play Services into your project.

  2. Right click on the project in the Package Explorer, select Properties to open the properties for your project.

  3. (Only if you already followed the instructions in the quick start guide!) Remove the dependency on the google-play-services project:

    • Click on the Android category and remove the reference to the google-play-services project.

    • Click on the Java Build Path category, then the Projects tab and remove the reference to the google-play-services project.

  4. Click on the Java Build Path category, then the Libraries tab.

  5. Click Add External JARs... and select the google-play-services.jar file. This should be in [Your ADT directory]\sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs.

  6. Click on the arrow next to the new google-play-services.jar entry, and select the Javadoc Location item.

  7. Click Edit... and select the folder containing the Google Play Services Javadocs. This should be in [Your ADT directory]\sdk\extras\google\google_play_services\docs\reference.

  8. Still in the Java Build Path category, click on the Order and Export tab. Check the box next to the google-play-services.jar entry.

  9. Click OK to save your project properties.

Your project should now have access to the Google Play Services library, and the Javadocs should display properly in Eclipse.

like image 55
b1tw153 Avatar answered Sep 30 '22 23:09

b1tw153