我正在尝试将 Firebase 添加到 Flutter Android 项目。
https://firebase.google.com/docs/flutter/setup?platform=android
我成功完成了所有步骤,除了(步骤3-5)
flutter run
当我将此代码写入命令行时,我得到了
e: /Users/me/.gradle/caches/transforms-3/b164394ffae5503ee96abe8c4d019cbc/transformed/jetified-play-services-measurement-api-22.0.0-api.jar!/META-INF/java.com.google.android.gmscore.integ.client.measurement_api_measurement_api.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
> Compilation error. See log for more details
* 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
BUİLD FAILED in 1s
这个错误。
其元数据的二进制版本是1.9.0,预期版本是 1.7.1.
如何解决这个问题?
谢谢。
应用程序等级:
plugins {
id "com.android.application"
id 'com.google.gms.google-services'
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
namespace "com.example.myflutterproject"
compileSdk flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.myflutterproject"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 21//flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
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 {
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:33.0.0')
// TODO: Add the dependencies for Firebase products you want to use
// When using the BoM, don't specify versions in Firebase dependencies
implementation 'com.google.firebase:firebase-analytics'
}
项目gradle:
plugins {
// ...
// Add the dependency for the Google services Gradle plugin
id 'com.google.gms.google-services' version '4.3.15' apply false//4.4.1
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Android Studio版本:
Android Studio Jellyfish | 2023.3.1 构建 建于 2024 年 4 月 12 日
这个答案帮助太大了。
https://stackoverflow.com/a/78080295/7880054
kotlin插件版本在新版本中转移到settings.gradle 的颤动。你可以在settings.gradle中找到kotlin插件版本 里面的插件标签
SO 上的所有解决方案都与 build.gradle 文件相关。我试图通过查看 build.gradle 文件来解决我的问题,但解决方案是
android/settings.gradle
文件...
我查看了 android/settings.gradle 文件并进行了更改
plugins {
...
...
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}
到
plugins {
...
...
id "org.jetbrains.kotlin.android" version "1.9.0" apply false
}
并且
flutter run
工作成功。