添加Firebase依赖项时,Gradle构建失败

时间:2018-06-19 13:50:28

标签: firebase gradle dart flutter

我想为我的应用程序使用Firebase,但是每当我添加特定于Firebase的依赖项(例如:“ cloud_firestore:”或“ firebase_analytics:^ 0.3.3”)时,我都无法构建该应用程序。当我进行颤动运行时,会收到以下输出:

Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...                                       4.4s
Resolving dependencies...                                   19.1s
Running 'gradlew assembleDebug'...
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)

FAILURE: Build failed with an exception.

* What went wrong:
Failed to notify dependency resolution listener.
> The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.4,15.0.4]], but
resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
> The library com.google.firebase:firebase-analytics is being requested by various other libraries at [[16.0.0,16.0.0]], but resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 16s
Gradle build failed: 1

1 个答案:

答案 0 :(得分:1)

作为explained here,如果要在Android上运行 Firebase ,则需要添加 Android依赖项

在您的build.gradle 项目级别文件中,您需要添加:

dependencies {
  // other dependencies might already be here

  classpath 'com.google.gms:google-services:3.1.2'
}

在您的应用级别 build.gradle 中,在最底部添加

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

并非每个 Dart 的Firebase插件页面都有此信息。 Another great source is this codelab,因为它显示了如何与 Android iOS 集成。

此外,在使用 Android 时,请确保您的设备已安装 Google Play服务