所有的gms/firebase库必须使用完全相同的版本(混合使用不同版本可能导致运行时崩溃)。发现的版本有16.1.1、16.0.1、16.0.0和15.0.1。

3
尝试在我的项目中实现Firebase,但是“implementation 'com.google.firebase:firebase-core:16.0.1'”这一行被下划线标出。请帮忙看看。
谢谢Mbuodile Obiosio,但是没有起作用,我不知道怎么办。
apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.harun.basicmathquiz"
        minSdkVersion 15
        targetSdkVersion 27
        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:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'

}

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

// 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.1.2'
        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 {
        maven { url "https://maven.google.com" }
        jcenter()
    }
}

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

我的错误:所有的 gms/firebase 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。发现的版本有 16.1.1、16.0.1、16.0.0、15.0.1。示例包括 com.google.firebase:firebase-analytics-impl:16.1.1 和 com.google.firebase:firebase-analytics:16.0.1。


你的问题解决了吗?如果是,那么是怎么解决的?因为下面的答案都对我没用。 - alphaguy
3个回答

2
我是一个有用的助手,可以为您翻译文本。以下是您需要翻译的内容:

我也面临同样的问题。我的问题通过在Gradle中添加以下内容得到解决:

classpath 'com.google.gms:google-services:4.0.1'

在依赖项中

 dependencies {
 .
 .
 .
    implementation ('com.google.firebase:firebase-database:16.0.1') {
        exclude group: "com.google.android.gms"
    }
}
apply plugin: 'com.google.gms.google-services'

2

1
你混合了不同的版本,所以才会出现错误。
    apply plugin: 'com.android.application'

    android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.harun.basicmathquiz"
        minSdkVersion 15
        targetSdkVersion 27
        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:27.1.1'
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'    
 }

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

别忘了更新顶层的build.gradle文件

classpath 'com.google.gms:google-services:4.0.1'

感谢Mbuodile Obiosio。我已经解决了。我的Android Studio版本是3.0.1(旧版本),我更新了Studio版本(版本3.1.3),然后就可以工作了:)我得到了更新版本,但电脑不接受。我卸载了旧版本并安装了新版本。 - Septik Argonot

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