我有一个之前正在运行的Android应用程序,我不得不在新PC上设置开发环境。一切都编译得很好(我正在使用Android Studio),但我收到以下错误:
11-26 15:25:22.737 15132-15132/com.sample E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gcm.GCMRegistrar
at com.sample.views.loginregistration.LoginManager.handleRegistration(LoginManager.java:147)
at com.sample.views.loginregistration.LoginViewFragment.onCreateView(LoginViewFragment.java:74)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:871)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:523)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5143)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
它说无法找到 gcm.jar ,这显然位于项目和名为 libs 的文件夹中。这些是人们在其他SO帖子中报告的常见问题。该应用程序基本上启动,然后当场崩溃...但我很困惑,因为设置是正确的。
还有什么可能是错的吗?
答案 0 :(得分:2)
这可能是build.gradle问题。你应该在build.gradle文件中有这个
dependencies {
compile files('libs/gcm.jar')
}
添加完毕后,转到Tools
- > Android
- > Sync Project with Gradle Files