Search code examples
androidflutterfirebasegradleandroid-gradle-plugin

Flutter run is not working for Firebase Android project. Error: The binary version of its metadata is 1.9.0, expected version is 1.7.1


I am trying to add Firebase to Flutter Android project.

https://firebase.google.com/docs/flutter/setup?platform=android

I did all steps successfully except(Step 3-5)

flutter run

When I write this code to command line I am getting

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

this error.

The binary version of its metadata is 1.9.0, expected version is 1.7.1.

How can I solve this problem?

Thanks.

app gradle:

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'

}

project 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 version:

Android Studio Jellyfish | 2023.3.1 Build built on April 12, 2024


Solution

  • I solved my problem.

    This answer helped too much.

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

    kotlin plugin version is shifted to settings.gradle in newer version of flutter. you can find kotlin plugin version in settings.gradle inside plugins tag

    All solutions on SO was related with build.gradle files. I was trying to solve my problem by looking build.gradle files but the solution is

    android/settings.gradle

    file... because I'm using latest Flutter version.

    I looked android/settings.gradle file and changed

    plugins {
        ...
        ...
        id "org.jetbrains.kotlin.android" version "1.7.10" apply false
    }
    

    to

    plugins {
        ...
        ...
        id "org.jetbrains.kotlin.android" version "1.9.0" apply false
    }
    

    And flutter run worked succesfully.