Vyacheslav
Vyacheslav

Reputation: 27211

java.lang.NoClassDefFoundError for any google-play-services feature

I'm using the last version of Eclipse, ADT and the newest Android SDK. If I'm trying to use something in a simple HelloWorld Android project Google Play feature, for instance,

int res = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

the app crashes with

04-27 21:52:23.905: D/ActivityThread(4379): handleBindApplication:my.app.test
04-27 21:52:23.905: D/ActivityThread(4379): setTargetHeapUtilization:0.75
04-27 21:52:23.905: D/ActivityThread(4379): setTargetHeapMinFree:2097152
04-27 21:52:23.945: I/dalvikvm(4379): Could not find method com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable, referenced from method my.app.test.MainActivity.onCreate
04-27 21:52:23.945: W/dalvikvm(4379): VFY: unable to resolve static method 29: Lcom/google/android/gms/common/GooglePlayServicesUtil;.isGooglePlayServicesAvailable (Landroid/content/Context;)I
04-27 21:52:23.945: D/dalvikvm(4379): VFY: replacing opcode 0x71 at 0x0009
04-27 21:52:23.975: D/AndroidRuntime(4379): Shutting down VM
04-27 21:52:23.975: W/dalvikvm(4379): threadid=1: thread exiting with uncaught exception (group=0x4162cd58)
04-27 21:52:23.975: E/AndroidRuntime(4379): FATAL EXCEPTION: main
04-27 21:52:23.975: E/AndroidRuntime(4379): Process: my.app.test, PID: 4379
04-27 21:52:23.975: E/AndroidRuntime(4379): java.lang.NoClassDefFoundError: com.google.android.gms.common.GooglePlayServicesUtil
04-27 21:52:23.975: E/AndroidRuntime(4379):     at my.app.test.MainActivity.onCreate(MainActivity.java:17)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at android.app.Activity.performCreate(Activity.java:5231)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at android.app.ActivityThread.access$800(ActivityThread.java:138)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at android.os.Looper.loop(Looper.java:136)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at android.app.ActivityThread.main(ActivityThread.java:5095)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at java.lang.reflect.Method.invokeNative(Native Method)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at java.lang.reflect.Method.invoke(Method.java:515)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
04-27 21:52:23.975: E/AndroidRuntime(4379):     at dalvik.system.NativeStart.main(Native Method)
04-27 21:52:23.985: I/Process(4379): Sending signal. PID: 4379 SIG: 9

I'm really do not understand why it doesn't work. I've added via File>Import> [Copy from lib source] . I've tried to use both Android 5.1.1 and GoogleAPIs. That I linked google-play-service_lib as lib project to my helloworld project. After that I added in Properties> Java Build Path > Libraries >add jars (the lib file). Order and Export checked boxes are checked too. In Android Manifest I added

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

In brief, I did directly what writen in official manual and more

I clearnd, restarted etc...... BUT IT DOESN'T WORK. OMG WHY? What is the reason? I tested on different devices and different machines. The same stupid error!!

Upvotes: 1

Views: 789

Answers (2)

Vyacheslav
Vyacheslav

Reputation: 27211

I wasted a lot of time of findout the solution. The core of bug is Android SDK updating went wrong, old version of Eclipse, not enought memory for Eclipse Java Machine (more detailed about memory bug here).

Even I've tryed to update build tools, API, etc. it didn't work. But I just downloaded new SDK and fully reinstalled and this helped. Do not forget to install new Eclipse and ADT. Do not forget about memory increasing in eclipse.ini file.

Upvotes: 0

smoyer
smoyer

Reputation: 8222

You probably need to add a reference to the project in Project Settings->Android->Library.

Look at the "Referencing a library section" here. Add your project reference there as well and you should be alright.

Upvotes: 1

Related Questions