我正在使用最新版本的Eclipse,ADT和最新的Android SDK。例如,如果我尝试在简单的HelloWorld Android项目Google Play功能中使用某些功能,
int res = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
该应用程序崩溃
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
我真的不明白为什么它不起作用。我已经通过File> Import> [从lib源复制]添加了。我尝试使用Android 5.1.1和GoogleAPI。我将google-play-service_lib作为lib项目链接到我的helloworld项目。之后,我在“属性”>“ Java构建路径”>“库”>“添加罐子”(lib文件)中添加了。订单和导出复选框也被选中。在Android清单中,我添加了
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
简而言之,我直接做了官方手册中写的内容
我清理了一下,然后重新启动,等等……但是没有用。天哪?是什么原因?我在不同的设备和不同的机器上进行了测试。同样的愚蠢错误!
我浪费了很多时间来寻找解决方案。错误的核心是Android SDK更新出错,旧版本的Eclipse,没有足够的内存来容纳Eclipse Java Machine(此处有关于内存错误的更多详细信息)。
甚至我都尝试过更新构建工具,API等,但是它不起作用。但是我刚刚下载了新的SDK并完全重新安装,这有所帮助。不要忘记安装新的Eclipse和ADT。别忘了eclipse.ini文件中的内存增加