Flutter Firebase插件问题:不兼容问题

时间:2019-12-07 09:40:54

标签: android firebase gradle flutter android-gradle-plugin

我在flutter项目中添加了Firebase插件后,出现以下错误: ProcessException:进程“ C:\ projects \ ecommerce \ android \ gradlew.bat”异常退出: 启动Gradle守护进程(后续构建会更快)

失败:生成失败,发生异常。 *其中: 构建文件“ C:\ projects \ ecommerce \ android \ app \ build.gradle”行:24 * 什么地方出了错: 评估项目':app'时发生问题。

  

无法应用插件[id'com.android.application']   支持的最低Gradle版本是5.4.1。当前版本是4.10.2。如果使用gradle包装器,请尝试编辑      C:\ projects \ ecommerce \ android \ gradle \ wrapper \ gradle-wrapper.properties中的distributionUrl到gradle-5.4.1-all.zip。

这是我的android \ app \ build.gradle。

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.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    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.example.ecommerce"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        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 {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    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'
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
}

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

这是我的android \ build.gradle:

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

    dependencies {

        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.2'
    }


}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}


//      ====SUBPROJECT DEPENDENCIES START HERE
    subprojects {
        project.evaluationDependsOn(':app')
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'androidx.core'
                    && !details.requested.name.contains('androidx') ) {
                details.useVersion "1.0.1"
            }
        }
    }
  }
//ENDS HERE

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

C:\ Program Files \ Android \ Android Studio \ gradle中的gradle版本: 是5.1.1。 我的android \ build.gradle中的gradle版本, 依赖项:

dependencies {

        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.2'
    }```

I dont know if there's any conflict between 
```classpath 'com.google.gms:google-services:4.3.2' ```
with:
```classpath 'com.android.tools.build:gradle:3.5.2'```

Please help



2 个答案:

答案 0 :(得分:2)

这些是我在最近的演讲中使用的链接。它们包含了3周前所有内容的必要版本。试试看。

Firebase身份验证:

https://github.com/flutter/flutter/issues/41492#issuecomment-536112970 https://github.com/flutter/flutter/issues/27254#issuecomment-477474444

Cloud Firestore:

https://developer.android.com/studio/build/multidex#mdex-gradle

答案 1 :(得分:0)

因此,在梳理了整个互联网两天之后,我终于通过更改 classpath 'com.google.gms:google-services:4.3.2' 到,
classpath 'com.google.gms:google-services:4.2.0'

此外,在android / build.gradle文件中升级gradle依赖项: 来自:

classpath 'com.android.tools.build:gradle:3.2.1'

收件人:

classpath 'com.android.tools.build:gradle:3.3.1'

会帮助

如果出现相同问题,您可以参考这篇文章: https://github.com/flutter/flutter/issues/38163#issuecomment-520429066