NoClassDefFoundError: com.google.firebase.FirebaseOptions

前端 未结 4 2722
有刺的猬
有刺的猬 2021-02-20 16:26

I keep on getting the NoClassDefFoundError on other test device (4.4.2) that I\'m using. But works fine on my test device (Android 5.1).

I tried the solutio

相关标签:
4条回答
  • 2021-02-20 17:03

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

    Follow these steps:

    1. Go to Android SDK Manager
    2. Go to Extra here you will find as shown in image below, update it to latest version and try to run project.

    Then if you are using MultiDex in your Application,then make sure you have correctly done it.

    In you App level Build.Gradle file use this code multiDexEnabled true

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

    Apply MultiDex dependency in dependencies inside Same file.

    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'
    }
    

    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">
    

    Note

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

    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);
        }
    
    }
    
    0 讨论(0)
  • 2021-02-20 17:08

    I have the same problem, with this I have solved:

    https://stackoverflow.com/a/37364044

    You must replace android:name=".app" with android:name="android.support.multidex.MultiDexApplication"

    0 讨论(0)
  • 2021-02-20 17:14

    Thanks to TapanHP above I got this working quickly for me:

    Short Answer:

    I had multiDexEnabled= true set in my app/build.gradle file and this ran fine on Android 5.x.x above but any test device with 4.x.x (kit kat) would throw a critical error "Unfortunately, YourAppName has stopped."

    Debugger showed:

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

    Note: I also have a custom class that extends Application.

    My Solution: Added the following code to my custom Application class

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

    No more critical crash.

    0 讨论(0)
  • 2021-02-20 17:16

    This is what solved the problem for me:

    1. Add compile 'com.android.support:multidex:1.0.2' to app/build.gradle.

    2. Add android:name="android.support.multidex.MultiDexApplication" to the application tag in AndroidManifest.xml.

      If you are using a custom Application class, skip the AndroidManifest.xml and make your Application class extend MultiDexApplication instead of Application.

    0 讨论(0)
提交回复
热议问题