添加firebase

时间:2018-06-01 14:17:02

标签: firebase gradle dart firebase-cloud-messaging flutter

我想在我的Flutter应用程序中实施Firebase Cloud Messaging,然后我开始实现Android部分。我在Firebase文档中添加了依赖项,但现在我在构建应用程序时遇到了gradle错误:

The library com.google.firebase:firebase-iid is being requested by various other libraries at [[16.0.0,16.0.0]], but resolves to 15.1.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

我对gradle没有任何经验,所以我很感激一些帮助^^

这是app / build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.leodr.pguapp"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'
}

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

这是项目build.gradle(如果需要):

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:4.0.0'
    }
}

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

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

4 个答案:

答案 0 :(得分:2)

将build.gradle上的gms版本降级为
classpath'com.google.gms:google-services:3.2.1'

答案 1 :(得分:0)

将此内容写在app.gradle ScoreID的底部

答案 2 :(得分:0)

您好,我遇到了同样的问题,但是我通过添加buil.gradle来解决了这个问题,希望并能解决

dependencies {

    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.0.1'
    classpath 'com.android.tools.build:gradle:3.2.1'
}

答案 3 :(得分:0)

我认为,当您没有最新版本的GRADLE / SDK / ANDROID STUDIO且使用最新的Firebase支持版本时,可能会产生这种类型的错误。