33

I was getting this weird error on my google developer console. So i used google Cloud Test Lab to See whats really happening. turns out my app is failing on almost all devices

FATAL EXCEPTION: main
 Process: com.blackcurrantapps.iamin, PID: 16706
 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)

Here is a screenshot of the Test. enter image description here

Now Here's the funny part, I dont even use Firebase in my app at all. There is no reference to the word "Firebase" when i do a find in path on my entire application. I Do use google cloud services, login and Google app engine though.

Here's my build.gradle file:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'

    defaultConfig {
        applicationId "com.blackcurrantapps.iamin"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 11
        versionName "Fixed Check in Bug"
        multiDexEnabled = true
    }
    buildTypes {
        release {
            shrinkResources true
//            minifyEnabled true
//            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}
repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    maven { url "https://oss.sonatype.org/content/groups/public/" }
    maven { url "https://jitpack.io" }
    maven { url 'https://maven.fabric.io/public' }
}

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

    compile('com.mikepenz:materialdrawer:4.5.8@aar') {
        transitive = true
    }

    compile 'com.mikepenz:google-material-typeface:1.2.0.1@aar' //Google Material Design Icons
    compile 'com.mikepenz:fontawesome-typeface:4.4.0.1@aar'

    compile('com.vincentbrison.openlibraries.android:dualcache:2.2.2@jar') {
        transitive = true;
    }

    compile project(':htmlDialog')
    compile('com.twitter.sdk.android:twitter:1.8.0@aar') {
        transitive = true;
    }
    compile 'com.android.support:palette-v7:23.4.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.google.android.gms:play-services-maps:9.0.0'
    compile 'com.google.android.gms:play-services-gcm:9.0.0'
    compile 'com.google.android.gms:play-services-identity:9.0.0'
    compile 'com.google.android.gms:play-services-base:9.0.0'
    compile 'com.google.android.gms:play-services-plus:9.0.0'
    compile 'com.google.android.gms:play-services-analytics:9.0.0'
    compile 'com.google.android.gms:play-services-location:9.0.0'
    compile 'com.android.support:cardview-v7:23.4.0'
    compile 'com.rengwuxian.materialedittext:library:2.1.3'
    compile 'com.twotoasters.jazzylistview:library:1.2.1'
    compile 'com.twotoasters.jazzylistview:library-recyclerview:1.2.1'
    compile 'com.pnikosis:materialish-progress:1.7'
    compile 'com.getbase:floatingactionbutton:1.10.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.okhttp:okhttp:2.6.0'
    compile 'me.dm7.barcodescanner:zbar:1.8.3'
    compile 'net.glxn.qrgen:android:2.0'
    compile 'com.edmodo:cropper:1.0.1'
    compile 'com.github.PhilJay:MPAndroidChart:v2.1.6'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.pavelsikun:material-seekbar-preference:0.12.1+'

    compile project(path: ':backend', configuration: 'android-endpoints')
}

Can anyone help me out here ?

Sanket Berde
  • 6,555
  • 4
  • 35
  • 39

12 Answers12

19

Thanks for posting the question Sanket. I'm the PM on Firebase Test Lab (formerly Cloud Test Lab). Wanted to let you know that this is a bug on our end that should now be fixed.

It seems that your app is currently using the latest and greatest Google Play Services. We updated our devices to use them last week then we discovered a bug that had us revert to an older version. Right now, we re-deployed the latest Play services on our devices so rerunning your tests should work. If not, please let me know and we'll look into it and fix it.

Ahmed Mounir
  • 1,322
  • 2
  • 12
  • 19
  • 6
    It's not just the Google cloud test, actual user devices also don't have the latest Google play services (9.0) updated. I reverted my app to (8.4.4) and everything works fine. In the future do u suggest to keep the Google play services version one step lower than the latest one to avoid such problems? – Sanket Berde May 26 '16 at 07:37
  • I am also getting following error while running app on actual device: Could not find class 'com.google.firebase.FirebaseOptions', referenced from method com.google.firebase.FirebaseApp. Could not find class 'com.google.firebase.FirebaseApp$zzb', referenced from method com.google.firebase.FirebaseApp.zzaJ Could not find class 'com.google.firebase.FirebaseApiNotAvailableException', referenced from method com.google.firebase.FirebaseApp.getToken Could not find class 'com.google.firebase.FirebaseApp$zza', referenced from method com.google.firebase.FirebaseApp.zza – Manav Patadia Jun 01 '16 at 20:54
  • 4
    I am still experiencing the issue in real devices also. Is there another way of fixing it than updating the google play services of the phones? – bendaf Jun 10 '16 at 14:56
  • Hi, Brother i have updated the google play services also but i still getting same error. can u please give me any solution. – Alpan Aug 10 '16 at 12:59
  • I am also facing same issue with this dependency 'com.google.android.gms:play-services:9.4.0' . is there any solution? or what is the minimum version shall I use? – Prashanth Debbadwar Aug 15 '16 at 10:26
  • Instead of adding whole google support library I added what are required for me like gms and plus solved my issue – Prashanth Debbadwar Aug 15 '16 at 10:57
  • I am also facing the same issue, I am using firebase realtime database, core and authentication version 9.2.1, what version should i use to avoid this error. – Shahab Rauf Sep 05 '16 at 13:08
  • 1
    I have fixed: You can read my answer, thanks. http://stackoverflow.com/questions/37360126/getting-exception-java-lang-noclassdeffounderror-com-google-firebase-firebaseop/39404082#39404082 – sonnv1368 Sep 09 '16 at 04:56
  • Same issue. The application runs on my Marshmallow and lollypop real time devices. But it is failed to run in my Kitkat tablet. What is the exact solution for this problem @Ahmed Mounir – sudharsan chandrasekaran Oct 07 '16 at 09:21
  • Finally i found the solution. Make one simple change in manifest file. instead of calling your MyApplication extends Application class in tag, use this following property [android:name="android.support.multidex.MultiDexApplication"] – sudharsan chandrasekaran Oct 07 '16 at 10:49
  • @Ahmed Mounir **PM of Firebase Test Lab**, [This is really embarrassing for developers like us, Please correct this issue. As it still exists.](http://oi66.tinypic.com/2gx2nis.jpg) – Maveňツ Feb 21 '17 at 07:55
14

I found a solution that worked for me. I was importing whole google play services 9.0.1 library. The temporary workaround is to import only the APIs that your app actually needs. You can get the whole list of APIs here.

Swati Rawat
  • 1,729
  • 1
  • 19
  • 34
6

with my case: Use FCM and Google map

//for FCM
compile 'com.google.firebase:firebase-messaging:9.4.0'
//for Map
compile 'com.google.android.gms:play-services:9.4.0'

I have fixed: Removed

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

and Used

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
4

You'd try following Code snippet:

defaultConfig { 
    multiDexEnabled true
}

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

public class Controller extends Application {

 @Override
    protected void attachBaseContext(Context newBase)
 {
        super.attachBaseContext(newBase);
        MultiDex.install(this);
  } 
}
help-info.de
  • 6,695
  • 16
  • 39
  • 41
Suresh Sarak
  • 119
  • 1
  • 1
4

If this can help other I solved this using this, although this is nowhere linked with Firebase but it actually solved my crash

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

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

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

Sanket Berde
  • 6,555
  • 4
  • 35
  • 39
Devavrata
  • 301
  • 1
  • 3
  • 12
  • Worked for me, even without step #1 I just extended my Application calss from MultiDexApplication class and it worked (Kit-Kat 4.4) – Kirill Karmazin Jul 19 '17 at 18:08
3

You have to use the com.google.firebase:firebase-ads:9.0.2 AdMob on Android dependencies,

compile 'com.google.firebase:firebase-ads:9.0.2'

and remove your

play-services (com.google.android.gms: play-services:9.0.2)

It works for me!

MMe
  • 31
  • 2
2

Just downgrade the google play-service dependency to compile 'com.google.android.gms:play-services:8.3.0' and problem will be solved.

Amit Upadhyay
  • 7,179
  • 4
  • 43
  • 57
2

I hope it's not too late. Firebase was causing trouble, so I excluded it. I just added this on the module gradle:

configurations {
    all*.exclude group: 'com.google.firebase', module: 'firebase-common'
}
Lendl Leyba
  • 2,287
  • 3
  • 34
  • 49
1

Turns out my usage of MultiDex was wrong and that causes this error. This should have really been mentioned in the official documentation somewhere.


How to do it the right way :

In Gradle.build (app level)

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

In the Manifest, add

<application
        android:name=".Global"
...

In the Application class,

public class Global extends MultiDexApplication {
...
}
Sanket Berde
  • 6,555
  • 4
  • 35
  • 39
1

In Android 4.4 the solucion was similar like this(https://stackoverflow.com/a/38707231/3377472):

-I have Google Play services revision 33

1) Configure build.gradle and and dependencies

Enabled multidex support and add library of multidex

   android {
        compileSdkVersion 23
        buildToolsVersion '23.0.3'
        defaultConfig {
            applicationId "packagename"
            minSdkVersion 14
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"

            //------- Enabling multidex support----------.
            multiDexEnabled true
        }

        dexOptions {
            javaMaxHeapSize "3g"//use 3Gb of ram to launch android 
        }

        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        productFlavors {
        }
    }


dependencies {

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

      // if you are using google maps
      compile 'com.google.android.gms:play-services-maps:9.2.0'
      compile 'com.google.android.gms:play-services-location:9.2.0'
}

2)Edit Manifest, and add this android:name

<application
        android:name="android.support.multidex.MultiDexApplication"
        ...
        .....
        activity
             android:name="packagename.Application"
             ....
             ...
       </activity>

3)Application Class

-My application class is:

import android.support.multidex.MultiDex;

public class Application extends AppCompatActivity {


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


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //this is the solution 
        MultiDex.install(this);

        setContentView(R.layout.layout_example);
        ----
        ----
Community
  • 1
  • 1
Jorge T
  • 121
  • 1
  • 2
  • 9
0

Not sure if this helps but I had the same issue using Android sdk 19 and it was driving me insane. I dont use Firebase (at least not purposefully) I am not sure why, but the error ceased when I set "minifyEnabled true" in the gradle config.

I see you have yours commented out in your releases section.

gregrobinz
  • 23
  • 5
0

If you are using google play services , please make sure that you add the specific service . For example when using maps :

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

instead of

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

This will reduce the size of the code and compilation will not require the use of "multidex" feature. If by chance you have already included

{
multiDexEnabled true
}

in your code try removing it and unnecessary library references

Farina Ali
  • 11
  • 5