使用 google_sign_in 插件进行颤振时,Gradle 构建失败

时间:2020-12-22 21:41:46

标签: android firebase flutter gradle google-signin

当不使用插件 (google_sign_in) 时,应用程序编译正常。但是一旦我将它作为依赖项添加到 pubspec.yaml 中,应用程序就不会构建。

这是我得到的gradle错误:

* What went wrong:
A problem occurred configuring project ':google_sign_in'.
    > Could not resolve all artifacts for configuration ':google_sign_in:classpath'.
         > Could not find kotlin-reflect.jar (org.jetbrains.kotlin:kotlin-reflect:1.3.11).
           Searched in the following locations:
               https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.3.11/kotlin-reflect-1.3.11.jar
    
    > Could not get unknown property 'android' for project ':google_sign_in' of type org.gradle.api.Project.

我曾尝试点击 kotlin-reflect-1.3.11.jar 的链接,它会下载文件,因此该链接显然有效。

我尝试过几乎所有东西的不同版本,但我没有找到任何有效的东西......

这是我的 pubspec.yaml 文件:

name: wishtogether
description: A new Flutter application.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  firebase_core: 0.5.3
  firebase_auth: ^0.18.4+1
  google_sign_in: ^4.5.6
  provider: ^4.3.2+3
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:

  uses-material-design: true

项目级 build.gradle:

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0' //4.3.4
    }
}

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

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.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.google.gms.google-services' //Firebase
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.jonathan.wishtogether"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:26.2.0')
    implementation 'com.google.firebase:firebase-analytics'
}

对于可能出现的问题有任何建议或想法吗?谢谢!

1 个答案:

答案 0 :(得分:1)

更改 google_sign_in build.gradle 文件中的 Gradle 版本,使其与 Flutter 应用中 android 文件夹中的版本匹配。

运行后抖动干净。

然后运行您的项目。