在Android上构建Flutter应用程序时如何解决“依赖项失败”

时间:2019-04-07 21:14:36

标签: firebase gradle flutter google-cloud-firestore google-signin

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

这是一个简单的flutter应用程序,它使用google登录在已连接的OnePlus 6 android手机上运行。

我尝试将依赖项更新为最新版本,并更改​​代码以匹配在此处找到的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  

Project Level 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 个答案:

答案 0 :(得分:0)

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

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