【问题标题】:NoClassDefFoundError: com.google.firebase.FirebaseOptionsNoClassDefFoundError:com.google.firebase.FirebaseOptions
【发布时间】:2016-10-02 14:15:32
【问题描述】:

我继续在我正在使用的其他测试设备 (4.4.2) 上获取 NoClassDefFoundError。但在我的测试设备(Android 5.1)上运行良好。

我尝试了谷歌搜索的解决方案,但似乎没有任何效果。

我正在使用 Firebase 实时数据库。有人可以帮忙吗?

这是错误日志:

06-03 01:36:29.607 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseOptions', referenced from method com.google.firebase.FirebaseApp.<init> 06-03 01:36:29.617 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApp$zzb', referenced from method com.google.firebase.FirebaseApp.zzaJ 06-03 01:36:29.621 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApiNotAvailableException', referenced from method com.google.firebase.FirebaseApp.getToken 06-03 01:36:29.629 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApp$zza', referenced from method com.google.firebase.FirebaseApp.zza 06-03 01:36:29.639 2655-2655/mobapps.mypersonal.biz.grouptracker E/AndroidRuntime: FATAL EXCEPTION: main
    Process: mobapps.mypersonal.biz.grouptracker, PID: 2655
    java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions
        at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
        at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1656)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1627)
        at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
        at android.app.ActivityThread.installProvider(ActivityThread.java:5079)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:4653)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4593)
        at android.app.ActivityThread.access$1500(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5363)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
        at dalvik.system.NativeStart.main(Native Method)

【问题讨论】:

    标签: android firebase firebase-realtime-database firebase-authentication


    【解决方案1】:

    这就是为我解决问题的方法:

    1. 添加编译'com.android.support:multidex:1.0.2'到 应用程序/build.gradle。

    2. android:name="android.support.multidex.MultiDexApplication" 添加到 AndroidManifest.xml 中的应用程序标签中。

      如果您使用的是自定义应用程序类,请跳过 AndroidManifest.xml 并让您的 Application 类扩展 MultiDexApplication 而不是 Application。

    【讨论】:

      【解决方案2】:

      较新版本报告了此错误,主要围绕修订版 28,29 并在较新的 Play 服务版本中得到解决,因此如果您遇到此问题,请确保您的 Android 工作室中已更新版本的 Google Play 服务。因为旧版本有它。更新 Play 服务版本..

      按照以下步骤操作:

      1. 转到 Android SDK 管理器
      2. 到Extra这里你会发现如下图所示,将其更新到最新版本并尝试运行项目。

      如果您在应用程序中使用了 MultiDex,请确保您已正确完成。

      在您的 App 级 Build.Gradle 文件中使用此代码 multiDexEnabled true

       defaultConfig {
              applicationId "com.reversebits.tapanhp.saffer"
              minSdkVersion 17
              targetSdkVersion 23
              versionCode 1
              versionName "1.0"
              multiDexEnabled true
          }
      

      在同一文件中的dependencies 中应用 MultiDex 依赖项

      dependencies {
          compile fileTree(dir: 'libs', include: ['*.jar'])
      
          testCompile 'junit:junit:4.12'
      
          compile 'com.google.android.gms:play-services:9.4.0'
          compile 'com.android.support:multidex:1.0.1'
      }
      

      然后在您的 AndroidMenifest.xml 文件中确保 Application 标签的名称为 MultiDexApplication

      <application
              android:name="android.support.multidex.MultiDexApplication"
              android:allowBackup="true">
      

      注意

      如果您有自己的应用程序类并且您在清单文件中使用它,那么您可以在应用程序类中初始化多索引,如下所示,

      public class AppClass extends Application {
      
          //this will initialize multidex in your own Application class
          @Override
          protected void attachBaseContext(Context base) {
              super.attachBaseContext(base);
              MultiDex.install(this);
          }
      
      }
      

      【讨论】:

        【解决方案3】:

        感谢上面的TapanHP,我很快就为我完成了这项工作:

        简答:

        我在我的app/build.gradle 文件中设置了multiDexEnabled= true,这在上面的 Android 5.xx 上运行良好,但任何带有 4.xx(kit kat)的测试设备都会抛出一个严重错误“不幸的是,YourAppName 有停止了。"

        调试器显示:

        Could not find class 'com.google.firebase.FirebaseOptions' ....
        

        注意:我还有一个扩展 Application 的自定义类。

        我的解决方案: 将以下代码添加到我的自定义应用程序类中

        import android.support.multidex.MultiDex;
        public class YourCustomApplication extends Application {
        
            @Override
            protected void attachBaseContext(Context base) {
                super.attachBaseContext(base);
                MultiDex.install(this);
            }
        
        ...
        } 
        

        不再有严重的崩溃。

        【讨论】:

          【解决方案4】:

          我有同样的问题,我已经解决了:

          https://stackoverflow.com/a/37364044

          您必须将android:name=".app" 替换为android:name="android.support.multidex.MultiDexApplication"

          【讨论】:

            猜你喜欢
            • 2016-09-28
            • 2016-12-14
            • 2017-01-20
            相关资源
            最近更新 更多