8

我想在我的应用程序上添加带有 firebase 的通知。我在 YouTube 上观看了一段视频(https://www.youtube.com/watch?v=xx7hemn3FY4)但是当我在我的颤振项目中做同样的事情时出现错误:图书馆 com.google.android.gms:play -services-basement 正在 [[15.0.1,15.0.1]] 的各种其他库中请求,但解析为 11.8.0。禁用插件并使用 ./gradlew :app:dependencies 检查您的依赖关系树。

正如您在评论中看到的那样,我尝试了几件事。

项目等级:

 buildscript {
    repositories {
        google()
        jcenter()
    }

dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'

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

}
}

allprojects {
    repositories {
        google()
        jcenter()
        /*
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
        */
    }
}

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

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

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.0"
            }

        }
    }
}

应用程序摇篮:

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.example.weatherapp"
        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.android.gms:play-services-basement:15.0.1'
    //Implementation 'com.google.firebase:firebase-core:15.0.0'
}

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

但这些变化都不起作用。你有别的想法吗?

4

3 回答 3

5

我遇到了类似的问题,在错误消息中它指出

[[15.0.1,15.0.1]] 的各种其他库正在请求库 com.google.android.gms:play-services-basement,但解析为 11.8.0。禁用插件并使用 ./gradlew :app:dependencies 检查您的依赖关系树。

解决 11.8.0

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.android.gms:play-services-basement:15.0.1'
    //Implementation 'com.google.firebase:firebase-core:15.0.0'

   implementation 'com.google.firebase:firebase-core:11.8.0'.  // <<--- Add this
}

我通过添加行解决了我的问题

implementation 'com.google.firebase:firebase-core:11.8.0'.  // <<--- Add this

此外,如果这不能解决问题,请添加此行;

com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

在同一个文件的末尾,如下所示;

...

dependencies {
  ....
}

....

com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

让我知道它是否解决了我们的问题。

谢谢!

于 2018-07-30T03:09:09.057 回答
3

发生这种冲突是因为使用较旧的库解决方案是使用最新的。就我而言,我使用的是 firebase 版本 16.0.0 ,当前最新版本是 16.0.4 (07-02-2019)

 implementation 'com.google.firebase:firebase-core:16.0.0'

而不是这个

 implementation 'com.google.firebase:firebase-core:16.0.4'
于 2019-02-07T15:47:06.670 回答
-1

检查 firebase 和其他 Google 服务是否相同。

形式
implementation 'com.google.android.gms:play-services-maps:16.0.0'

`implementation 'com.google.android.gms:play-services-maps:16.0.1'`
于 2018-11-17T17:48:03.063 回答