Firebase具有不同的编译和运行时版本

时间:2017-09-05 14:51:00

标签: android firebase

今天开始使用Firebase - 看起来很简单,但目前我做错了。

我的构建错误:

Error:Execution failed for task ':app:preDebugBuild'. Android dependency 
'com.google.firebase:firebase-core' has different version for the compile 
(9.0.0) and runtime (11.2.0) classpath. You should manually set the same version via DependencyResolution```

基本要素中的apply plugin: 'com.google.gms.google-services' build.gradle

如果没有此行,则没有构建错误,但Firebase停止工作(这是非常可预测的:D)

基本功能build.gradle

apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'

android {
    baseFeature = true
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 35
        versionName "1.1.1"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
    mavenCentral()
}

dependencies {
    androidTestCompile('com.android.support.test.espresso:espresso-                core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-    annotations'
    })
    testCompile 'junit:junit:4.12'

    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile "com.android.support:appcompat-v7:$support_version"
    compile "com.android.support:support-v13:$support_version"
    compile "com.android.support:recyclerview-v7:$support_version"

    compile "com.android.support:design:$support_version"
    compile "com.android.support:customtabs:$support_version"
    compile "com.android.support:support-vector-drawable:$support_version"

    implementation "com.google.firebase:firebase-messaging:$firebase_version"
    implementation "com.google.firebase:firebase-database:$firebase_version"
    implementation "com.google.firebase:firebase-appindexing:$firebase_version"
    implementation "com.google.firebase:firebase-core:$firebase_version"

    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

和项目的一个:

buildscript {
    ext.kotlin_version = '1.1.4-3'
    ext.firebase_version = '11.2.0'
    ext.support_version = '26.0.2'
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.0'
    }    
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        google()
    }
}

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

有任何帮助吗?非常感谢!

2 个答案:

答案 0 :(得分:3)

你应该把apply plugin: 'com.google.gms.google-services'放在你的gradle文件的BOTTOM而不是顶部。

https://developers.google.com/android/guides/google-services-plugin

答案 1 :(得分:0)

对于即时应用应该是:

**implementation 'com.google.firebase:firebase-messaging:11.8.0'**

而不是

implementation 'com.google.firebase:firebase-messaging:11.8.0'