混合使用Firebase不同版本可能导致运行时崩溃?

3

以下是我的 gradle 文件:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'


android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "???"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 4
        versionName "1.02"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {

            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    realm {

        syncEnabled = true
    }
}

dependencies {

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':EBS')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:gridlayout-v7:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.daimajia.swipelayout:library:1.2.0@aar'

    implementation 'com.google.firebase:firebase-messaging:17.1.0'
    implementation 'com.google.firebase:firebase-core:16.0.1'

    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.4'
    implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
}

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

// 顶级构建文件,您可以在其中添加所有子项目/模块共有的配置选项。
buildscript {

    repositories {
        google()
        jcenter()
        maven {

            url 'https://maven.fabric.io/public'

        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
        classpath "io.realm:realm-gradle-plugin:5.4.1"
        classpath 'com.google.gms:google-services:4.0.2'
        classpath 'io.fabric.tools:gradle:1.25.4'
        classpath 'com.google.android.gms:strict-version-matcher-plugin:1.0.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {

            url 'https://jitpack.io'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我在项目中添加了Firebase Core和Firebase Messaging,但是我遇到了以下问题:

“所有的gms/firebase库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。发现版本为17.1.0、16.2.0、16.1.1、16.0.1、16.0.0、15.0.1。示例包括com.google.firebase:firebase-messaging:17.1.0和com.google.firebase:firebase-iid:16.2.0等... (⌘F1)有些库或工具与库的组合是不兼容的,或者会导致错误。其中一种不兼容性是使用不是最新版本的Android支持库进行编译(特别是低于您的targetSdkVersion的版本)。”

请帮我解决这个问题。

你尝试过清理你的项目吗? - Alex Mamo
我尝试了但没有用。 - sAm
2个回答

0

我也遇到了同样的问题,以下是我解决这个问题的方法:

由于gradle会发出警告混合版本可能导致运行时崩溃,因此gradle会给出示例包括:

所有gms/firebase库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。发现版本17.1.0、16.2.0、16.1.1、16.0.1、16.0.0、15.0.1。示例包括com.google.firebase:firebase-messaging:17.1.0和com.google.firebase:firebase-iid:16.2.0等... (⌘F1) 有一些库或工具与库的组合是不兼容的,或者可能导致错误。其中一个不兼容性是使用Android支持库的版本编译,而不是最新版本(或特别是低于您的targetSdkVersion的版本)。

正如您在上述声明中所看到的那样

示例包括com.google.firebase:firebase-messaging:17.1.0和com.google.firebase:firebase-iid:16.2.0等...

所以只需添加由Gradle提到的创建版本冲突的任何依赖项即可。

implementation com.google.firebase:firebase-messaging:17.1.0
implementation  com.google.firebase:firebase-iid:16.2.0

在添加依赖项后,Gradle可能会包含更多的依赖项,因此请添加这些依赖项。

注意:Gradle显示此警告是因为您正在使用某些第三方库,该库正在使用其他库。


我尝试了你的解决方案,但仍然出现相同的错误。 - sAm
@sAm,你遇到了什么错误,是相同的还是不同的? - Rohit Maurya

0
在您的 build.gradle 文件 中,在您的存储库旁边:
maven { url 'https://jitpack.io' }

添加:

maven { url "https://maven.google.com" }

根据官方文档,没有:

implementation 'com.google.firebase:firebase-iid:16.2.0'

我尝试了你的解决方案,但仍然出现相同的错误。 - sAm

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接