在 Android 上构建 Flutter 应用程序时如何修复“依赖失败”

Posted

技术标签:

【中文标题】在 Android 上构建 Flutter 应用程序时如何修复“依赖失败”【英文标题】:How to fix 'Dependency failing' when building Flutter application on Android 【发布时间】:2019-08-29 00:44:42 【问题描述】:

我正在尝试在我的 Flutter 应用程序中使用 Google 登录。但是,由于依赖项的一些问题,我无法构建应用程序。我已将所有依赖项更新到最新版本,但无济于事。如何解决这些依赖关系以便构建应用程序?

这是一个使用谷歌登录的简单颤振应用程序,在连接的 OnePlus 6 安卓手机上运行。

我已尝试将我的依赖项更新到最新版本,并更改​​代码以匹配此处找到的 google_sign_in 依赖项的最新版本:https://pub.dartlang.org/packages/google_sign_in

我还尝试将 firebase_core 添加到依赖项列表中,因为错误消息表明该应用程序依赖于 firebase_core。这并没有改变错误消息。

项目“pubspec.yaml”依赖项

dependencies:
  flutter:
    sdk: flutter

  duration: ^2.0.0
  firebase_core: ^0.3.2
  cloud_firestore: ^0.9.11
  firebase_auth: ^0.8.4
  google_sign_in: ^4.0.1+3
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter  

项目级 build.gradle (android/build.gradle):

buildscript 
    repositories 
        google()
        jcenter()
    

    dependencies 
        classpath 'com.android.tools.build:gradle:3.2.1'
        // Google Services class path
        classpath 'com.google.gms:google-services:4.2.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

应用级 build.gradle (android/app/build.gradle):

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

android 
    compileSdkVersion 28

    lintOptions 
        disable 'InvalidPackage'
    

    defaultConfig 
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.recipe_app"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    

    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 
    implementation 'com.google.firebase:firebase-core:16.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


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

'flutter run' 的输出:

Launching lib/main.dart on ONEPLUS A6003 in debug mode...
Initializing gradle...                                              1.0s
Resolving dependencies...                                           4.0s
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

FAILURE: Build failed with an exception.

* What went wrong:
Failed to capture fingerprint of input files for task ':app:checkDebugClasspath' property 'compileClasspath' during up-to-date check.
> In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[15.0.
  1]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.

  Dependency failing: com.google.android.gms:play-services-stats:15.0.1 -> com.google.android.gms:play-services-basement@[
  15.0.1], but play-services-basement version was 16.1.0.

  The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art
  ifact with the issue.
  -- Project 'app' depends on project 'cloud_firestore' which depends onto com.google.firebase:firebase-firestore@18.2.0
  -- Project 'app' depends onto com.google.firebase:firebase-core@16.0.1
  -- Project 'app' depends on project 'firebase_auth' which depends onto com.google.firebase:firebase-auth@16.0.5
  -- Project 'app' depends on project 'google_sign_in' which depends onto com.google.android.gms:play-services-auth@16.0.1

  For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dep
  endency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at https://
  github.com/google/play-services-plugins and disable by adding "googleServices  disableVersionCheck = false " to your b
  uild.gradle file.

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

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

BUILD FAILED in 2s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                         2.9s
Gradle task assembleDebug failed with exit code 1

我希望应用程序能够成功构建,以便测试 Google 登录是否有效。但是,应用程序没有成功构建,我不知道该怎么办。

【问题讨论】:

【参考方案1】:

我尝试使用详细模式重新编译,并被告知 AndroidX 是原因。

我遵循了link 并将所有依赖项降级到文章中列出的 AndroidX 迁移之前的版本。这解决了问题。

【讨论】:

以上是关于在 Android 上构建 Flutter 应用程序时如何修复“依赖失败”的主要内容,如果未能解决你的问题,请参考以下文章

在 Flutter/Android 构建中找不到 protoc-3.9.2-osx

由于 icon_tree_shaker,Flutter 无法在 Android 上构建

Flutter:在 web 、android 和 ios 中使用相同的应用程序

Flutter 无法在 VS Code 上构建示例 iOS 应用程序

Gradle 在构建 Flutter 应用程序时突然开始报错

使用风味使用 MS AppCenter 构建 Flutter android APK 的问题