如何解决混合支持库版本

问题描述 投票:0回答:1

我写了一个基本的Android应用程序,并希望在版本23.4.0中使用Android支持库,因为我的编译,最小和目标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

整个app 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!

为什么会出现这些火灾基础错误(我甚至不知道它们的含义:D)? (Firebase消息传递工作正常btw)。

android firebase android-gradle android-support-library
1个回答
0
投票

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

    android {
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.