0

I have an app that has as minSdkVersion API 14, I've tested the app on a device running Android M and everything works fine, then I've tried to run the app on a device running API 15 (Android 4.0.3) and I get the following crash when the app starts:

FATAL EXCEPTION: main 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:986)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source) 
at android.app.ActivityThread.installProvider(ActivityThread.java:4249) 
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4004) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3958)
at android.app.ActivityThread.access$1300(ActivityThread.java:127) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)

I'm not using Firebase in my app and this is my gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "it.*.*"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile project(':libraries:Sliding Menu')
    compile 'com.android.volley:volley:1.0.0'
    compile files('libs/YouTubeAndroidPlayerApi.jar')
    compile 'com.android.support:cardview-v7:23.+'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:design:23.4.0'
    compile 'com.google.android.gms:play-services-analytics:9.0.0'
    compile 'com.google.android.gms:play-services:9.0.0'
    compile 'com.android.support:multidex:1.0.1'
}
apply plugin: 'com.google.gms.google-services'

Does anyone know what could be the problem? Why is it crashing only on the device with API 15?

LS_
  • 6,763
  • 9
  • 52
  • 88
  • 2
    Firebase is the new version of Google Cloud Messaging. Since you are using all the play-services firebase is also added. Try replacing `compile 'com.google.android.gms:play-services:9.0.0'` with the only those libraries that you need. Refer this [link](https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project) if you have any doubts. – Unnikrishnan M R Jun 06 '16 at 10:41
  • @Signo : Where in `gradle` you have added firebase lib? – AndiGeeky Jun 06 '16 at 10:42
  • 1
    @Signo : Please check this link and add dependencies accordingly : https://firebase.google.com/docs/android/setup#available_libraries – AndiGeeky Jun 06 '16 at 10:43
  • possibly duplicate http://stackoverflow.com/questions/37535141/android-noclassdeffounderror-com-google-firebase-firebaseoptions – Sunil Sunny Jun 06 '16 at 10:44
  • @UnnikrishnanMR yeah that was the problem, I was using compile 'com.google.android.gms:play-services:9.0.0' which added all of the google libraries to my project (gradle was taking like 50sec to build), I've removed that line and added the following that adds to the project only the GCM: compile 'com.google.android.gms:play-services-gcm:9.0.0' and now it works! – LS_ Jun 06 '16 at 10:55
  • @Signo glad to be of help – Unnikrishnan M R Jun 06 '16 at 12:13
  • @UnnikrishnanMR if you want post it as an answer so I can accept it :) – LS_ Jun 06 '16 at 12:16

3 Answers3

1

According to latest Google docs, Firebase is the new version of Google Cloud Messaging. From your gradle file it seems you are adding all the play services hence firebase is also added. Replace

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

with the only the libraries that you need. For more information on selective services refer this link

Unnikrishnan M R
  • 224
  • 2
  • 11
0

If you haven't already, update your 'Google Play Services' to Revision 30 from Android SDK

If you haven't already add this attribute to the application tag in manifest: android:name="android.support.multidex.MultiDexApplication"

As you have stated "I'm not using Firebase in my app" remove all the improts of Firebase related class and then run gradlew clean from terminal in android studio.

Abdullah
  • 935
  • 9
  • 18
0

I don't think you require google-play-services for using firebase

What I have in my gradles:

build.gradle(Project):

...
dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0-alpha1'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
...

build.gradle:(Module)

...
dependencies {
       ...
       compile 'com.google.firebase:firebase-messaging:9.0.2'
    }
...
apply plugin: 'com.google.gms.google-services'

Check this way and tell me whether it works or not.

Note: If you want to use Firebase Analytics, then you will require

compile 'com.google.firebase:firebase-analytics:9.0.0'

in your build.gradle(Module).

Chintan Soni
  • 24,761
  • 25
  • 106
  • 174