Android NoClassDefFoundError: com.google.firebase.FirebaseOptions

﹥>﹥吖頭↗ 提交于 2019-11-29 10:23:43
Amit Basliyal

first update your Google Repository in your sdk second enable multidex like

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

compile with

compile 'com.android.support:multidex:1.0.1'
classpath 'com.google.gms:google-services:3.0.0' 

This bug is reported with newer versions mostly arround Revision 28,29 and its resolved in newer Play services versions so very first if you having this issue then make sure you have updated version of Google Play service in your Android studio.

Follow these steps:

  1. Go to Android SDK Manager
  2. Go to Extra

And update it to version 30 or later.

Then if you are using MultiDex in your Application then please use it only if it's compulsory.

Make sure you have follow these steps when integrating MultiDex.

In you App level Build.Gradle

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

Apply MultiDex dependency in dependencies

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

Then inside your AndroidMenifest.xml file make sure that Application tag have name of MultiDexApplication.

<application
        android:name="android.support.multidex.MultiDexApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

Note

if you have custom Application class and using it in your menifest file then you can initialize multidex in your Application class as follows,

public class AppClass extends Application {
    private static Context context;
    private static AppClass mInstance;

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

}

In your top-level build.gradle you have to add:

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

Then in your module build.gradle:

apply plugin: 'com.android.application'

android {
  // ...
}

dependencies {
  // ... 

}

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

1, Open your SDK Manager then install Google Play Services (rev 30) and Google Repository (rev 26).

2, Add classpath 'com.google.gms:google-services:3.0.0' to your build.gradle of project.

You should include Multidex library to your gradle.build

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

And as suggested by @Lollipop you need to download Google play Services and add classpath in your project. Since Firebase need this library to work properly.

EDIT

buildscript 
{ 
dependencies 
 { 
   classpath 'com.google.gms:google-services:3.0.0' 
 } 
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!