【问题标题】:Dependency collision between play-services-map and firebaseplay-services-map 和 firebase 之间的依赖冲突
【发布时间】:2018-06-01 04:37:49
【问题描述】:

我正在尝试将 firebase 添加到我已经启动的项目中,但是在 build.gradle(应用程序)中,我在 play-services-maps 和 firebase 之间发生了依赖冲突,我到处查看并尝试更改版本号,但是还是行不通。 这是 build.gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.android.tencho.test"
        minSdkVersion 22
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        //testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.google.android.gms:play-services:15.0.1'
//    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    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.android.support:design:26.1.0'
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
    compile 'com.google.code.gson:gson:2.2.+'
    compile 'com.google.firebase:firebase-core:16.0.0'

//    //Firebase Auth
    implementation 'com.google.firebase:firebase-auth:16.0.1'
//    //FirebaseUI Auth
    compile 'com.firebaseui:firebase-ui-auth:3.3.0'


}

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

Build.gradle(项目级别)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

//        The google-services plugin has 2 main functions:
//        1) Process the google-services.json file and produce Android resources that can be used in your
//        application's code
//        2) Add dependencies for basic libraries required for the services you have enabled. This step requires
//        that the apply plugin: 'com.google.gms.google-services' line be at the bottom of your app/build.gradle file
//        so that no dependency collisions are introduced.
        classpath 'com.google.gms:google-services:4.0.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

【问题讨论】:

  • 错误是什么?
  • 您应该为 firebase 和 google play 服务使用相同的版本。
  • 所有 gms/firebase 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 16.0.1、16.0.0、15.0.4、15.0.1、12.0.1。示例包括 com.google.firebase:firebase-auth:16.0.1 和 com.google.firebase:firebase-analytics:16.0.0

标签: android firebase gradle google-play-services


【解决方案1】:

您使用的版本不一致。

让我告诉你一个简单的例子。

如果您使用的是 google play services 11.8.0,那么 firebase 也应该是同一版本..

compile 'com.google.android.gms:play-services:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.google.android.gms:play-services-maps:11.8.0'
compile 'com.google.firebase:firebase-crash:11.8.0'
compile 'com.google.firebase:firebase-core:11.8.0'

所以主要需要注意的是,您使用的版本不一致。

【讨论】:

  • 你能帮我澄清两件事吗,我对android有点陌生。 1)如果没有匹配firebase的play-services-maps:16.0.1怎么办?我必须使用旧版本? 2)如果我确实使用了你发布的内容,那么我会在 support.appcompat 中得到一个错误
  • 它抛出错误,因为您可能没有更新 sdk 管理器中的构建。让我知道它在 appcompat 中显示什么错误?
  • 所有 com.android.support 库必须使用完全相同的版本规范(混合版本会导致运行时崩溃)。找到版本 26.1.0、25.2.0。示例包括 com.android.support:animated-vector-drawable:26.1.0 和 com.android.support:mediarouter-v7:25.2.0
  • 您需要更新 sdk 中构建的播放服务。单击 SDK 管理器并更新它。然后它会工作。
  • 这不是真的。现在您可以使用不同版本的 firebase 和 google play 服务库。此外,播放服务库不在 sdk 中,而是在 google maven repo 中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-26
  • 1970-01-01
  • 2020-10-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多