Adding Google play services library eclipse

Started by
3 comments, last by TechnoGoth 10 years, 3 months ago

I copied the google-play-services_lib folder to my projects directory following the instructions here

https://developer.android.com/google/play-services/setup.html#Setup

But it gave me these errors

[2014-01-06 11:21:06 - google-play-services_lib] Project has no target set. Edit the project properties to set one.
[2014-01-06 11:21:06 - google-play-services_lib] Project has no target set. Edit the project properties to set one.
[2014-01-06 11:21:06 - google-play-services_lib] Parser exception for /google-play-services_lib/AndroidManifest.xml: Premature end of file.
[2014-01-06 11:21:07 - google-play-services_lib] Parser exception for /google-play-services_lib/AndroidManifest.xml: Premature end of file.
[2014-01-06 11:24:03 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Parser exception for C:\Users\polyfrag\Desktop\Projects\google-play-services_lib\AndroidManifest.xml: Premature end of file.
I looked in the AndroidManifest.xml and it's empty. I coped the contents from the original location and it's still showing a red excalamation mark near the project icon.

<?xml version="1.0" encoding="utf-8"?>

package="com.google.android.gms"
android:versionCode="4030530"
android:versionName="4.0.30 (889083-30)" >
<uses-sdk android:minSdkVersion="8"/>
</manifest>

I tried adding the library to the android project I'm working on but it doesn't show up in the list of libraries. What do I need to do. Trying to add ads to my app.

Advertisement
I deleted the google play services lib in the SDK manager and reinstalled it, now it complains because the project description '.project' file is missing. Can somebody at least give me the contents of their google-play-services_lib/.project file if they don't know what's wrong?

Did you follow the instructions on the site?

I haven't done it in a while but as I recall you import into your workspace as separate project and add it as a reference library project to the project that you want to use it in.

These are basic steps you need to do:

import the library project into your workspace. Click File > Import, select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.

See the Referencing a Library Project for Eclipse or Referencing a Library Project on the Command Line for more information on how to do this.

Note: You should be referencing a copy of the library that you copied to your development workspace—you should not reference the library directly from the Android SDK directory.

After you've added the Google Play services library as a dependency for your app project, open your app's manifest file and add the following tag as a child of the <application> element:

<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

I just added the google play services .jar to my project's /libs/ folder and hard-coded the "com.google.android.gms.version" value from google play service lib's /res/values.xml file.

But I didn't see that "Setting up a library project" page and might have to follow that.

Ya, the android documentation isn't great.

Also, is your google play services project building successfully?

You'll want to add the following as well to your starting activity in your app:

It's buried somewhere on the site. What it does is ensures that the google play services are available and up to date on the device when the the application starts you should also use it before any calls to the google play services to prevent the application from crashing. It displays an error dialog that can kick off the the update process on failure.


private boolean googlePlayServicesConnected()
	{
		// Check that Google Play services is available
		int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
		// If Google Play services is available
		if (ConnectionResult.SUCCESS == resultCode)
		{
             		// Continue
			return true;
			
		} else // Google Play services was not available for some reason
		{

			Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, CONNECTION_FAILURE_RESOLUTION_REQUEST);

			// If Google Play services can provide an error dialog
			if (errorDialog != null)
			{
				// Create a new DialogFragment for the error dialog
				ErrorDialogFragment errorFragment = new ErrorDialogFragment();
				// Set the dialog in the DialogFragment
				errorFragment.setDialog(errorDialog);
				// Show the error dialog in the DialogFragment
				errorFragment.show(getFragmentManager(), "Google Services Error");
			}

			return false;
		}
	}

This topic is closed to new replies.

Advertisement