如何解决混合支持库版本

时间:2019-03-08 10:41:35

标签: android firebase android-gradle android-support-library

我写了一个基本的android应用程序,并希望使用23.4.0版中的Android支持库,因为我的sdk,min-和目标sdk版本是23。

我也使用Firebase消息传递。该应用程序编译没有错误,但是在运行时,我在日志文件中遇到了很多错误。该应用程序不会崩溃,但日志中存在垃圾邮件错误和警告。例如,此错误以红色显示:

2019-03-08 10:59:42.527 20093-20093/de.my.prettyapp E/FirebaseApp: Firebase API initialization failure.
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at com.google.firebase.FirebaseApp.zza(com.google.firebase:firebase-common@@16.0.2:797)
    at com.google.firebase.FirebaseApp.zze(com.google.firebase:firebase-common@@16.0.2:763)
    at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:359)
    at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:324)
    at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:310)
    at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common@@16.0.2:53)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1940)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1915)
    at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common@@16.0.2:47)
    at android.app.ActivityThread.installProvider(ActivityThread.java:6737)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6284)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6199)
    at android.app.ActivityThread.access$1200(ActivityThread.java:237)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1785)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7045)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
 Caused by: java.lang.NoSuchMethodError: No virtual method zzbsv()Ljava/lang/String; in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/de.my.prettyapp-kbqktdTn67S7-9ayMAcb8g==/split_lib_dependencies_apk.apk)
    at com.google.firebase.auth.FirebaseAuth.zzb(Unknown Source:3)
    at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source:0)
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.google.firebase.FirebaseApp.zza(com.google.firebase:firebase-common@@16.0.2:797) 
    at com.google.firebase.FirebaseApp.zze(com.google.firebase:firebase-common@@16.0.2:763) 
    at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:359) 
    at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:324) 
    at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:310) 
    at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common@@16.0.2:53) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1940) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:1915) 
    at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common@@16.0.2:47) 
    at android.app.ActivityThread.installProvider(ActivityThread.java:6737) 
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6284) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6199) 
    at android.app.ActivityThread.access$1200(ActivityThread.java:237) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1785) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:214) 
    at android.app.ActivityThread.main(ActivityThread.java:7045) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 

在日志文件中,还有多条(如20条)错误消息以白色显示。它们看起来都差不多,就像:

    Rejecting re-init on previously-failed class java.lang.Class<com.google.firebase.auth.FirebaseUser>: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzbgl;
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at java.lang.Class java.lang.Class.classForName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:-2)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at java.lang.Class java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:453)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at java.lang.Class java.lang.Class.forName(java.lang.String) (Class.java:378)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void com.google.firebase.FirebaseApp.zza(java.lang.Class, java.lang.Object, java.lang.Iterable, boolean) (com.google.firebase:firebase-common@@16.0.2:792)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void com.google.firebase.FirebaseApp.zze() (com.google.firebase:firebase-common@@16.0.2:763)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at com.google.firebase.FirebaseApp com.google.firebase.FirebaseApp.initializeApp(android.content.Context, com.google.firebase.FirebaseOptions, java.lang.String) (com.google.firebase:firebase-common@@16.0.2:359)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at com.google.firebase.FirebaseApp com.google.firebase.FirebaseApp.initializeApp(android.content.Context, com.google.firebase.FirebaseOptions) (com.google.firebase:firebase-common@@16.0.2:324)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at com.google.firebase.FirebaseApp com.google.firebase.FirebaseApp.initializeApp(android.content.Context) (com.google.firebase:firebase-common@@16.0.2:310)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at boolean com.google.firebase.provider.FirebaseInitProvider.onCreate() (com.google.firebase:firebase-common@@16.0.2:53)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.content.ContentProvider.attachInfo(android.content.Context, android.content.pm.ProviderInfo, boolean) (ContentProvider.java:1940)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.content.ContentProvider.attachInfo(android.content.Context, android.content.pm.ProviderInfo) (ContentProvider.java:1915)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void com.google.firebase.provider.FirebaseInitProvider.attachInfo(android.content.Context, android.content.pm.ProviderInfo) (com.google.firebase:firebase-common@@16.0.2:47)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at android.app.ContentProviderHolder android.app.ActivityThread.installProvider(android.content.Context, android.app.ContentProviderHolder, android.content.pm.ProviderInfo, boolean, boolean, boolean) (ActivityThread.java:6737)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.app.ActivityThread.installContentProviders(android.content.Context, java.util.List) (ActivityThread.java:6284)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.app.ActivityThread.handleBindApplication(android.app.ActivityThread$AppBindData) (ActivityThread.java:6199)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.app.ActivityThread.access$1200(android.app.ActivityThread, android.app.ActivityThread$AppBindData) (ActivityThread.java:237)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1785)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.os.Looper.loop() (Looper.java:214)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:7045)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:493)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:964)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.internal.zzbgl" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/de.my.prettyapp-kbqktdTn67S7-9ayMAcb8g==/base.apk", zip file "/data/app/de.my.prettyapp-kbqktdTn67S7-9ayMAcb8g==/split_lib_dependencies_apk.apk", zip file "/data/app/de.my.prettyapp-kbqktdTn67S7-9ayMAcb8g==/split_lib_resources_apk.apk", zip file "/data/app/de.my.prettyapp-kbqktdTn67S7-9ayMAcb8g==/split_lib_slice_0_apk.apk", zip file "/data/app/de.my.prettyapp-kbqktdTn67S7-9ayMAcb8g==/split_lib_slice_1_apk.apk", zip file "/data/app/de.my.prettyapp-kbqktdTn67S7-9ayMAcb8g==/split_lib_slice_2_apk.apk", zip file "/data/app/de.my.prettyapp-kbqktdTn67S7-9ayMAcb8g==/split_lib_slice_3_apk.apk", zip file "/data/app/de.my.prettyapp-kbqktdTn67S7-9ayMAcb8g==/split_lib_slice_4_apk.apk", zip file "/data/app/de.my.prettyapp-kbqktdTn67S7-9ayMAcb8g==/split_lib_slice_5_apk.apk", zip file 
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:134)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at java.lang.Class java.lang.Class.classForName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:-2)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at java.lang.Class java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:453)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at java.lang.Class java.lang.Class.forName(java.lang.String) (Class.java:378)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void com.google.firebase.FirebaseApp.zza(java.lang.Class, java.lang.Object, java.lang.Iterable, boolean) (com.google.firebase:firebase-common@@16.0.2:792)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void com.google.firebase.FirebaseApp.zze() (com.google.firebase:firebase-common@@16.0.2:763)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at com.google.firebase.FirebaseApp com.google.firebase.FirebaseApp.initializeApp(android.content.Context, com.google.firebase.FirebaseOptions, java.lang.String) (com.google.firebase:firebase-common@@16.0.2:359)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at com.google.firebase.FirebaseApp com.google.firebase.FirebaseApp.initializeApp(android.content.Context, com.google.firebase.FirebaseOptions) (com.google.firebase:firebase-common@@16.0.2:324)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at com.google.firebase.FirebaseApp com.google.firebase.FirebaseApp.initializeApp(android.content.Context) (com.google.firebase:firebase-common@@16.0.2:310)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at boolean com.google.firebase.provider.FirebaseInitProvider.onCreate() (com.google.firebase:firebase-common@@16.0.2:53)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.content.ContentProvider.attachInfo(android.content.Context, android.content.pm.ProviderInfo, boolean) (ContentProvider.java:1940)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.content.ContentProvider.attachInfo(android.content.Context, android.content.pm.ProviderInfo) (ContentProvider.java:1915)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void com.google.firebase.provider.FirebaseInitProvider.attachInfo(android.content.Context, android.content.pm.ProviderInfo) (com.google.firebase:firebase-common@@16.0.2:47)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at android.app.ContentProviderHolder android.app.ActivityThread.installProvider(android.content.Context, android.app.ContentProviderHolder, android.content.pm.ProviderInfo, boolean, boolean, boolean) (ActivityThread.java:6737)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.app.ActivityThread.installContentProviders(android.content.Context, java.util.List) (ActivityThread.java:6284)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.app.ActivityThread.handleBindApplication(android.app.ActivityThread$AppBindData) (ActivityThread.java:6199)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.app.ActivityThread.access$1200(android.app.ActivityThread, android.app.ActivityThread$AppBindData) (ActivityThread.java:237)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1785)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.os.Looper.loop() (Looper.java:214)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:7045)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:493)
2019-03-08 10:59:42.297 20093-20093/de.my.prettyapp I/my.prettyapp:     at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:964)

在这篇文章(StackOverflow Answer)中,解决方案是不混合使用android支持库。因此,我查看了 app.gradle 文件,发现了以下警告:

行:实现'com.android.support:appcompat-v7:23.4.0'

警告:

  

所有com.android.support库必须使用完全相同的版本   规范(混合版本可能导致运行时崩溃)。找到了   版本26.1.0、23.4.0。例子包括   com.android.support:support-compat:26.1.0和   com.android.support:animated-vector-drawable:23.4.0

整个应用程序gradle文件为:

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

android {
    //compileSdkVersion 28
    compileSdkVersion 23
    defaultConfig {
        applicationId "de.my.prettyapp"
        minSdkVersion 23
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    lintOptions {
        abortOnError false
    }
}

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

    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.google.firebase:firebase-messaging:17.4.0'
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
    implementation 'com.google.firebase:firebase-crash:16.2.1'

    implementation 'net.zetetic:android-database-sqlcipher:4.0.1@aar'

    testImplementation 'junit:junit:4.12'
    implementation group: 'com.squareup.okhttp', name: 'okhttp', version: '2.5.0'
    implementation('com.squareup.retrofit:converter-simplexml:2.0.0-beta2')
            {
                exclude module: 'stax'
                exclude module: 'stax-api'
                exclude module: 'xpp3'
            }
    // https://mvnrepository.com/artifact/com.nanohttpd/nanohttpd
    implementation group: 'com.nanohttpd', name: 'nanohttpd', version: '2.1.0'
    implementation "commons-io:commons-io:+"

    implementation 'com.google.android.gms:play-services-location:16.0.0'

    implementation 'com.android.support:appcompat-v7:23.4.0'
    implementation 'com.android.support:support-v13:23.4.0'
    implementation 'com.android.support:support-v4:23.4.0'
    implementation 'com.android.support:design:23.4.0'

    implementation 'com.squareup:otto:1.3.8'
    implementation 'com.jakewharton.timber:timber:4.3.0'
    //compile 'com.google.android.gms:play-services:10.2.1'

    // implementation 'com.google.android.gms:play-services:12.0.1'

    implementation 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    implementation 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
}

为什么android studio告诉我混合支持库版本?我在gradle文件中看到的所有版本均为23.4.0!

为什么会有这些firebase错误(我什至不知道它们是什么意思:D)? (Firebase消息传递顺便说一句)。

1 个答案:

答案 0 :(得分:0)

您可以强制gradle使用相同版本的支持库。将以下代码行放在应用的build.gradle 文件中,并放在 android 块内。

    android {
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
}