user3846566
user3846566

Reputation: 11

GooglePlayServices.isGOoglePlayServicesAvailable NoClassDefFoundError

I've looked around here for resolving the "NoClassDefFoundError" exception when trying to use GCM, and the results usually tell me that I added the google-play-services_lib incorrectly.

I imported the Google Play Services Library from File->Import...->Android->Existing Android Code Into Workspace and selected /extras/google/google_play_services/libproject/google-play-services_lib

Import Google Play Services Library

I added the project in Project->Properties under Reference I added google-play-services_lib.

Android Properties

This project has been successfully built in the past, I updated Eclipse and all the SDK components and this is when it stopped working. I don't remember these two steps in the original setup of GCM but I did them anyways from

Add to AndroidManifest

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

Add to proguard-project.txt

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

I'm completely lost as to why this isn't working. I verified that Eclipse is copying the google-play-services_lib.jar and the google-play-services.jar files in Libraries and Order and Export

I have deleted both projects google-play-services_lib and my Project, removed all eclipse build file Lint files .classpath .project project.properties .settings etc, cleaned rebuilt, deleted google play services from SDK manager, re downloaded, checked Copy Projects to Workspace for Google Play Services lib, I'm really out of ideas as to why this isn't working. I tried it on a few different devices and a few different emulator instances all with the same result.

EDIT Trace included as the code that caused the error

 Thread [<1> main] (Suspended (exception NoClassDefFoundError)) 
<VM does not provide monitor information>   
MainActivity.checkPlayServices() line: 173  
MainActivity.onCreate(Bundle) line: 47  
MainActivity(Activity).performCreate(Bundle) line: 5248 
Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1110   
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2173    
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2269 
ActivityThread.access$800(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 139    
ActivityThread$H.handleMessage(Message) line: 1210  
ActivityThread$H(Handler).dispatchMessage(Message) line: 102    
Looper.loop() line: 136 
ActivityThread.main(String[]) line: 5102    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 515  
ZygoteInit$MethodAndArgsCaller.run() line: 785  
ZygoteInit.main(String[]) line: 601 
NativeStart.main(String[]) line: not available [native method]  

Code

private void checkPlayServices(){
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if(resultCode!=ConnectionResult.SUCCESS){
        Intent intent = new Intent(this,ErrorActivity.class);
        startActivity(intent);
    }
}

Upvotes: 0

Views: 345

Answers (1)

user3846566
user3846566

Reputation: 11

Well I went the route of completely removing eclipse and the android SDK. I redownloaded and now everything works. Must have been a botched update.

Upvotes: 1

Related Questions