72

I have updated my application to the new firebase using the this and now when i compile my project i get the following exception.

Here is my 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.access$1500(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)

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

Not sure where i am getting this exception from. any help will be highly appreciated. Thank you

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
M.Waqas Pervez
  • 2,492
  • 2
  • 19
  • 33
  • 8
    Which version of android are you testing on? I'm facing the same issue on KitKat, but my app runs fine on Lollipop / Marshmallow. Also, please post code or it would be very hard to help you. – chaitan94 May 21 '16 at 11:45
  • Hi, I have update google play services to 30 and google repository to 28. I have initialized Multidex.install(this) in my custom application file. I am still getting the same error on kitkat but it works fine on later versions. – arkit Jun 10 '16 at 08:21
  • 1
    Did you solve the problem for KitKat devices? – guilherme.minglini Jun 15 '16 at 14:15
  • 2
    @guilherme.minglini yeah i did following BKC answer. i have tested it on devices with jellybean to marshmellow and works fine. – M.Waqas Pervez Jun 15 '16 at 17:02

15 Answers15

141

This worked for me:

  1. If you haven't already, update your 'Google Play Services' to Revision 30 from Android SDK Manager > Extras.

Android SDK Manager > Extras > Google Play Services

  1. And then add the line compile 'com.android.support:multidex:1.0.1' to your dependancies (or simply remove multiDexEnabled true if not required)

  2. Add this attribute to the application tag in manifest: android:name="android.support.multidex.MultiDexApplication"
    If you already have a custom application class defined in Android Manifest, extend it from MultiDexApplication instead of Application

Hope it helped!

Anton
  • 4,395
  • 7
  • 32
  • 46
chaitan94
  • 2,153
  • 1
  • 18
  • 19
  • 2
    I alread have a custom App in my project that extends the ORM application class. How should manage the need of android:name="android.support.multidex.MultiDexApplication"? Can you describe why this error is happening? – E. Fernandes May 23 '16 at 20:43
  • 1
    @EdgarDaSilvaFernandes All that "android.support.multidex.MultiDexApplication" Does is this one line. "MultiDex.install(this);" – Sanket Berde May 24 '16 at 18:07
  • 7
    Hi, I have update google play services to 30 and google repository to 28. I have initialized Multidex.install(this) in my custom application file. I am still getting the same error on kitkat but it works fine on later versions. – arkit Jun 10 '16 at 07:57
  • As well as following all the instruction above, I also updated to 24.0.0 of the SDK, not sure if that made a difference. But all works now. – Ed Manners Jun 16 '16 at 17:07
  • 3
    I have 31 rev. of Play Services but not working on pre 18 API devices – Sandeep Rana Jul 12 '16 at 12:21
46

Using latest Google Play services but was not working. For me this procedure is working:

  1. Updated my Application class:

    public class App extends Application {
      @Override
      protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
     }
    }
    
  2. Updated build.gradle file:

    defaultConfig {
        ...
        multiDexEnabled true
    }
    
  3. Included dependencies:

    dependencies {
      compile 'com.android.support:multidex:1.0.0'
    }
    
Christos Lytras
  • 36,310
  • 4
  • 80
  • 113
enam
  • 952
  • 11
  • 11
22

It is so simple to fix guys.If you are using player-services and firebase both in your project make sure that you don't import all the available services in the google.Just import the APIs what you actually need. For example:

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

Doing this way it can give you noclassdeffounderror .To fix this

remove play-services and sync your project. If you have dependency like using ads or maps in your app then define the specific API. like:

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

Note: Maximum don't try to use multiDexEnabled true. This should be your last step to fix something.

Hope this is helpful.

Rushi Ayyappa
  • 2,708
  • 2
  • 16
  • 32
  • 1
    Almost all comments and responses usually suggest the multidex enabling, in my case specifying that I was only using maps the only needed step, as described in this answer. – Alexander Fradiani Oct 27 '16 at 17:25
  • Works perfect, simply changed from 'com.google.android.gms:play-services:10.0.1' to 'com.google.android.gms:play-services-ads:10.0.1' – AlexS Dec 16 '16 at 22:21
17

I downgraded my google play-service dependency from

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

to

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

which solved this issue for me.

Please refer to the following Stack Overflow link for further description.


Please Note: On upgrading to the latest google play-service
compile 'com.google.android.gms:play-services:9.4.0' it solved this issue as well.

Or you could selectively import certain services that you require, instead of importing all google play services.

Community
  • 1
  • 1
Arshak
  • 3,197
  • 1
  • 25
  • 33
  • 1
    *Upgrading* from 8.4.0 to 9.2.0 fixed it for me (using com.google.android.gms:play-services-gcm, and also just having upgraded play services to revision 32, but that change on its own did not fix it, so I don't know if it is relevant) – Divisible by Zero Aug 08 '16 at 16:21
13

Step1: Fix multidex

Application class:

public class StudyNApplication extends Application {

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

Grade file

defaultConfig { 
...
multiDexEnabled true
}

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

Step2: Fix java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions

Remove

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

Add two lib:

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

It worked fine.

sonnv1368
  • 1,547
  • 12
  • 17
5

Don't forget it.

android:name="android.support.multidex.MultiDexApplication"
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
bb14816
  • 473
  • 1
  • 5
  • 14
3

I solved by adding this and lowering the play-service dependancy to 8.4.0 compile 'com.google.android.gms:play-services:8.4.0'

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

and add the following to the manifest

android:name="android.support.multidex.MultiDexApplication"
Abednego
  • 599
  • 10
  • 17
1

I was facing the same error when I incremented the targetSDKVersion from 22 to 23 I spent minimum a whole day to resolve the issue. Now finally i find the result that use different play service api in your build.gradle file Source: https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project

I added only relevant Api's and my app is working fine.

1

Configure your app for multidex to resolve this issue.

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. Modify the module-level build.gradle and add the multidex library as a dependency, as shown below:

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

  2. If you do not override the Application class, edit your manifest file to set android:name in the application tag as follows

    <?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. If you do override the Application class Extend MultiDexApplication

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

    2.1.2. Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:

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

for more mdex-gradle

Hope this will be help others who are facing same issue.

Rupesh Yadav
  • 12,096
  • 4
  • 53
  • 70
0

I think I've found a solution for this issue at this answer, please give it a look and thank @Gabriele Mariotti, he wrote:

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'
Community
  • 1
  • 1
0
 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(**R.string.default_web_client_id**))
            .requestEmail()
            .build();

In my same case i changed requestIdToken and it worked.

ugurozgen
  • 81
  • 9
0
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'    
}  

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

Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
0

try to solve...

in Gradle file

multiDexEnabled true

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

Manifest file

application tag add this line

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

Community
  • 1
  • 1
0

Before doing all those hectic solutions, try to Clean Project or Rebuild Project from Android Studio.

java.lang. NoClassDefFoundError

Exceptions is thrown when you change any Class name in your project but it couldn't get the changes you made in Runtime.

Al Walid Ashik
  • 1,545
  • 20
  • 32
-1

Downgrade your dependency in build.gradle file:

from:

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

to:

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

This worked in my case, hope same for you.

Garg
  • 2,731
  • 2
  • 36
  • 47