Why My android app crashes as soon as I open it in device 4.4.3 but not in device 5.0 or above

不想你离开。 提交于 2019-12-13 08:59:42

问题


I have used facebook sdk for log in with facebook and also google map for user current position. It run well in android 5.o or above but crashes in android 4.4.3. I have used following configuration.

 android {
             compileSdkVersion 24
             buildToolsVersion "24.0.0"

             defaultConfig {
                 applicationId "com.example.nuevo.getsocial"
                 minSdkVersion 15
                 targetSdkVersion 24
                 versionCode 1
                 versionName "1.0"
                 multiDexEnabled true
             }
             buildTypes {
                 release {
                     minifyEnabled false
                     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                 }
             }
             dexOptions{
                 javaMaxHeapSize "4g"
             }
         }
         repositories {
             mavenCentral()
         }

         dependencies {
             compile fileTree(dir: 'libs', include: ['*.jar'])
             testCompile 'junit:junit:4.12'
             compile project(path: ':volley')
             compile 'com.android.support:appcompat-v7:24.2.0'
             compile 'com.facebook.android:facebook-android-sdk:4.7.0'
             compile 'com.squareup.picasso:picasso:`enter code here`2.4.0'
             compile 'com.google.android.gms:play-services:9.4.0'
             compile 'com.android.support:design:24.2.0'
             compile 'com.google.android.gms:play-services-ads:9.4.0'
             compile 'com.google.android.gms:play-services-auth:9.4.0'
             compile 'com.google.android.gms:play-services-gcm:9.4.0'
         }

Logcat is as follow

446/com.example.nuevo.getsocial E/dalvikvm: Could not find class 'com.google.firebase.FirebaseOptions', referenced from method com.google.firebase.FirebaseApp. 08-29 02:41:35.041 1446-1446/com.example.nuevo.getsocial E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApp$zzb', referenced from method com.google.firebase.FirebaseApp.zzcm 08-29 02:41:35.045 1446-1446/com.example.nuevo.getsocial E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApiNotAvailableException', referenced from method com.google.firebase.FirebaseApp.getToken 08-29 02:41:35.049 1446-1446/com.example.nuevo.getsocial E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApp$zza', referenced from method com.google.firebase.FirebaseApp.zza 08-29 02:41:35.081 1446-1446/com.example.nuevo.getsocial E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.nuevo.getsocial, PID: 1446 java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions at com.google.firebase.FirebaseApp.zzek(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:4774) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4369) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4309) at android.app.ActivityThread.access$1500(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) 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)


回答1:


replace your appcompat and design libraries into gradle dependencies with following

compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
    compile 'com.android.support:design:24.0.0-alpha1'



回答2:


According to Android Studio User Guide:Multidex support prior to Android 5.0

Versions of the platform prior to Android 5.0 (API level 21) use the Dalvik runtime for executing app code. By default, Dalvik limits apps to a single classes.dex bytecode file per APK. In order to get around this limitation, you can use the multidex support library, which becomes part of the primary DEX file of your app and then manages access to the additional DEX files and the code they contain.

In your case, if you're supporting old version of Android, you need to include com.android.support:multidex:1.0.0 in your gradle dependency.



来源:https://stackoverflow.com/questions/39198823/why-my-android-app-crashes-as-soon-as-i-open-it-in-device-4-4-3-but-not-in-devic

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