Flutter run не работает для проекта Firebase Android. Ошибка: двоичная версия метаданных — 1.9.0, ожидаемая версия — 1.7.1

Я пытаюсь добавить 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'

}

Град проекта:

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-студия Медуза | 2023.3.1 Сборка построен 12 апреля 2024 г.

0
0
93
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Я решил свою проблему.

Этот ответ слишком помог.

https://stackoverflow.com/a/78080295/7880054

Версия плагина Kotlin перенесена на settings.gradle в более новой версии трепетания. вы можете найти версию плагина Kotlin в settings.gradle внутри тега плагинов

Все решения по SO были связаны с файлами build.gradle. Я пытался решить свою проблему, просматривая файлы build.gradle, но решение

Android/settings.gradle

файл... потому что я использую последнюю версию Flutter.

Я посмотрел файл 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 сработало успешно.

Другие вопросы по теме