Getting Exception java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions after updating to the new firebase

Getting Exception java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions after updating to the new firebase

我已经使用 this 将我的应用程序更新到新的 firebase,现在当我编译我的项目时,出现以下异常。

这是我的 logcat:

11:57:54.533 27844-27844/com.example.dayshift_2.traveyy E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dayshift_2.traveyy, PID: 27844
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:1591)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1562)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:4871)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4466)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4406)
at android.app.ActivityThread.access00(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

我的Build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com.example.dayshift_2.traveyy"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE-FIREBASE.txt'
    exclude 'META-INF/NOTICE'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'

compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.google.firebase:firebase-database:9.0.0'
compile 'com.google.firebase:firebase-auth:9.0.0'
compile 'com.android.support:support-v13:23.3.0'
compile 'com.roughike:bottom-bar:1.2.1'
}


apply plugin: 'com.google.gms.google-services'

不确定我从哪里得到这个异常。任何帮助将不胜感激。 谢谢

这对我有用:

  1. 如果您还没有,请从 Android SDK Manager > Extras 将您的 'Google Play Services' 更新到修订版 30。

  1. 然后将行 compile 'com.android.support:multidex:1.0.1' 添加到您的依赖项中(或者如果不需要,只需删除 multiDexEnabled true

  2. 将此属性添加到清单中的应用程序标记:android:name="android.support.multidex.MultiDexApplication"
    如果您已经在 Android 清单中定义了自定义应用程序 class,请从 MultiDexApplication 扩展它而不是 Application

希望对您有所帮助!

使用最新的 Google Play 服务但无法正常工作。对我来说,这个程序是有效的:

  1. 更新了我的申请 class:

    public class App extends Application {
      @Override
      protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
     }
    }
    
  2. 已更新 build.gradle 文件:

    defaultConfig {
        ...
        multiDexEnabled true
    }
    
  3. 包含的依赖项:

    dependencies {
      compile 'com.android.support:multidex:1.0.0'
    }
    

降级我的google播放服务依赖来自

compile 'com.google.android.gms:play-services:9.2.0' 

compile 'com.google.android.gms:play-services:8.4.0' 

为我解决了这个问题。

请参考


请注意:升级到最新的google播放服务
compile 'com.google.android.gms:play-services:9.4.0'它也解决了这个问题。

或者您可以有选择地导入您需要的某些服务,而不是导入所有 google 播放服务。

修复非常简单 guys.If 您在项目中同时使用播放器服务和 firebase 确保您没有导入 google.Just 中的所有可用服务 导入 API这是你真正需要的。 例如:

 compile 'com.google.firebase:firebase-messaging:9.2.0'
 compile 'com.google.android.gms:play-services:9.2.0'

这样做会给你 noclassdefounderror 。解决这个问题

删除播放服务并同步您的项目。如果您有依赖性,例如在您的应用中使用广告或地图,请定义特定的 API。喜欢:

compile 'com.google.android.gms:play-services-maps:9.2.0'

注意:最大不要尝试使用multiDexEnabled true。这应该是您解决某些问题的最后一步。

希望对您有所帮助。

别忘了。

android:name="android.support.multidex.MultiDexApplication"

我想我已经在这个 找到了这个问题的解决方案,请看看并感谢 @Gabriele Mariotti,他写道:

在您的顶层 build.gradle 您必须添加:

buildscript {
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

然后在你的模块中 build.gradle:

apply plugin: 'com.android.application'

android {
  // ...
}

dependencies {
  // ... 

}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

我通过添加这个并将播放服务依赖性降低到 8.4.0 编译解决了 'com.google.android.gms:play-services:8.4.0'

    @Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(newBase);
    MultiDex.install(this);
}

并将以下内容添加到清单

android:name="android.support.multidex.MultiDexApplication"

当我将 targetSDKVersion 从 22 增加到 23 时,我遇到了同样的错误,我至少花了一整天的时间来解决这个问题。现在我终于在你的 build.gradle 文件中找到了使用不同播放服务 api 的结果 资源: https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project

我只添加了相关的 Api,我的应用运行良好。

第 1 步:修复 multidex

申请class:

public class StudyNApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        MultiDex.install(this);
    }
 }

成绩文件

defaultConfig { 
...
multiDexEnabled true
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

第 2 步:修复 java.lang.NoClassDefFoundError:com.google.firebase.FirebaseOptions

删除

compile 'com.google.android.gms:play-services:9.4.0'

添加两个库:

compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.google.android.gms:play-services-location:9.4.0'

它运行良好。

build.gradle 文件中降级你的依赖:

来自:

compile 'com.google.android.gms:play-services:9.4.0'

至:

compile 'com.google.android.gms:play-services:7.3.0'

这对我有用,希望你也一样。

 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(**R.string.default_web_client_id**))
            .requestEmail()
            .build();

在我的同一个案例中,我更改了 requestIdToken 并且它起作用了。

dependencies {
compile 'com.android.support:support-v4:25.0.1'
compile 'com.google.firebase:firebase-ads:9.0.2'
compile files('libs/StartAppInApp-3.5.0.jar')
compile 'com.android.support:multidex:1.0.1'    
}  

应用插件:'com.google.gms.google-services'.

尝试解决...

在 Gradle 文件中

multiDexEnabled true

compile 'com.android.support:multidex:1.0.1'

清单文件

应用标签添加这一行

android:name="android.support.multidex.MultiDexApplication"

为您的应用配置 multidex 以解决此问题。

For minSdkVersion 21 or above set multiDexEnabled to true in your module-level build.gradle file, as shown below:

android {
  defaultConfig {
    //...
    minSdkVersion 21 
    targetSdkVersion 26
    multiDexEnabled true
   }
  //...
 }

For minSdkVersion API 20 or lower

  1. 修改module-level build.gradle,添加multidex库作为依赖,如下图:

    android { defaultConfig { ... minSdkVersion 15 targetSdkVersion 26 multiDexEnabled true } //... } dependencies { compile 'com.android.support:multidex:1.0.1' }

  2. 如果您不覆盖 Application class,请编辑您的 manifest文件在application标签中设置android:name如下

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp"> <application android:name="android.support.multidex.MultiDexApplication"> //... </application> </manifest>

    2.1.1。如果您确实覆盖 Application class 扩展 MultiDexApplication

    public class MyApplication extends MultiDexApplication { //... }
    

    2.1.2。或者,如果您确实覆盖了 Application class 但无法更改基数 class,那么您可以改写 attachBaseContext() 方法并调用 MultiDex.install(this) 以启用 multidex:

    public class MyApplication extends SomeOtherApplication { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } }

更多mdex-gradle

希望这对面临同样问题的其他人有所帮助。

在执行所有这些繁琐的解决方案之前,请尝试从 Android Studio 清理项目重建项目

java.lang. NoClassDefFoundError

当您更改项目中的任何 Class 名称时会抛出异常,但它无法获取您在 Runtime[=] 中所做的更改19=].