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

Flutter Firebase Plugin Issues: Incompatibility issues

我将 firebase 插件添加到我的 flutter 项目后出现以下错误: ProcessException:进程 "C:\projects\ecommerce\android\gradlew.bat" 异常退出: 启动 Gradle 守护进程(后续构建会更快)

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

Failed to apply plugin [id 'com.android.application'] Minimum supported Gradle version is 5.4.1. Current version is 4.10.2. If using the gradle wrapper, try editing the distributionUrl in C:\projects\ecommerce\android\gradle\wrapper\gradle-wrapper.properties to 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中gradle的版本Studio\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



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

Firebase 身份验证:

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

云 Firestore:

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

于是在网上整整梳理了两天,终于解决了,改成 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'

会有帮助

同样的问题可以参考这个post: https://github.com/flutter/flutter/issues/38163#issuecomment-520429066