Question

I am developing for Android 4+ with Eclipse Juno ADT bundle + Google Plugin for Eclipse. I need to programmatically log into a google account to use the Google Calendar API. For this I am making use of account manager. I get the following error:

05-05 13:28:55.605: E/AndroidRuntime(11186): FATAL EXCEPTION: main
05-05 13:28:55.605: E/AndroidRuntime(11186): java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker
05-05 13:28:55.605: E/AndroidRuntime(11186):    at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.newChooseAccountIntent(GoogleAccountCredential.java:171)
05-05 13:28:55.605: E/AndroidRuntime(11186): ...

Here is the code that causes it:

GoogleAccountCredential credential;

credential = GoogleAccountCredential.usingOAuth2(this, CalendarScopes.CALENDAR);

chooseAccount();

private void chooseAccount() {

  startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);

}

I have searched stackoverflow for solutions. The libs directory contains the calendar library files for eclipse I imported via google plugin for eclipse (which also put there the authentication etc... libraries):

android-support-v4.jar
google-api-client-1.14.1-beta.jar
google-api-client-android-1.14.1-beta.jar
google-api-services-calendar-v3-rev41-1.14.2-beta.jar
google-http-client-1.14.1-beta.jar
google-http-client-android-1.14.1-beta.jar
google-http-client-gson-1.14.1-beta.jar
google-http-client-jackson-1.14.1-beta.jar
google-http-client-jackson2-1.14.1-beta.jar
google-oauth-client-1.14.1-beta.jar
gson-2.1.jar
jackson-core-2.1.3.jar
jackson-core-asl-1.9.11.jar
jsr305-1.3.9.jar

These however do not seem to include

com.google.android.gms.common.AccountPicker

If I import this in my code the import line of code is flagged as an error. So what's up. I've copied this code from the Google Calendar Sample where it runs just fine:

http://samples.google-api-java-client.googlecode.com/hg/calendar-android-sample/

That code has exactly the same libs except:

  1. calendar lib is rev33 instead of rev41
  2. jackson and jackson-asl libraries are missing
  3. .properties file for each library file present in sample code but not in my code

So this should not be the problem. However, looking in the imports section of the code, the google calendar sample code has:

import com.google.android.gms.common.GooglePlayServicesUtil;

but if I try to insert this line of code in my code it is tagged as an error saying the import com.google.android.gms.common.GooglePlayServicesUtil cannot be resolved.

This post

java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker

says they were able to

import com.google.android.gms.common.AccountPicker;

But I'd like to know what library that came from.

I even tried looking in the original android calendar sample for the library from which I can include com.google.android.gms.common.* by inspecting one file at a time but could not find it. How is it possible?

What am I doing wrong?

Thanks very very much for all your help.

Was it helpful?

Solution

OK, I've found out what I was missing.

  1. Ensure you have downloaded the Android SDK Services -> Extras -> Google Play services

  2. Follow the instructions provided by the following link to add the google-play-services-lib library to your project:

http://developer.android.com/tools/projects/projects-eclipse.html#ReferencingLibraryProject

Best Regards

OTHER TIPS

I've run into a similar problem lately. My app (not in production yet) would suddenly (since the beginning of May) start throwing uncatchable 'NoClassDefFoundError' error when calling

GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE_FILE)

method. It was happening randomly, usually first time in the morning. I could fix it by re-installing my Google account. Not a good solution for production, though. I've spent frustrating couple of hours trying to resolve it until I finally realized I have another app that does not have the same problem in the same code sequence. So I diff-ed both of them and realized that the "good" one had a different sequence of entries in 'Package Explorer->Project->Properties->Java Build Path' The 'good' one had

'google-play-services.jar' BEFORE 'android-support-v4.jar',

where the 'bad' one had it backwards. So I switched the sequence (using UP, DOWN buttons in the dialog) and it seems to solve the problem. Yet another WT... ? moment! Does anybody have an opinion on this?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top