skip to Main Content

I am getting these errors whenever I run `flutter buid apk` for first time. After first time if I make the build again it does not happen. If I clear caches and make build again then it happens again for first time.

Commands which cause these errors again after first time build:

flutter clean

flutter pub cache clean

flutter pub get

flutter build apk

e: E:/user/.gradle/caches/transforms-3/760f7ca3c06fd16010ad3c3f87a73608/transformed/jetified-play-services-location-21.2.0/jars/classes.jar!/META-INF/java.com.google.android.gms.libs.identity_identity.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.

e: E:/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib.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.

e: E:/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib-jdk8.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.

e: E:/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib-jdk7.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.

e: E:/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.9.0/cd65c21cfd1eec4d44ef09f9f52b6d9f8a720636/kotlin-stdlib-common-1.9.0.jar!/META-INF/kotlin-stdlib-common.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.

This is what I have done so far to fix it but no luck.

  1. I have upgraded flutter and dart,

  2. Installed fresh Android studio again.

  3. Upgraded all package

  4. Added dependency_overrides to latest dependencies versions.

Following is my file structure:
pubspec.yaml

name: example_app
description: app description

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 0.0.1+1

environment:
  sdk: '>=3.4.0 <4.0.0'

dependencies:
  cached_network_image: ^3.3.1
  carousel_slider: ^4.2.1
  cmp_sdk: ^0.1.0
  compute: ^1.0.2
  connectivity_plus: ^6.0.3
  equatable: ^2.0.5
  firebase_analytics: ^10.10.6
  firebase_core: ^2.31.1
  firebase_messaging: ^14.9.3
  flutter:
    sdk: flutter
  flutter_bloc: ^8.1.5
  flutter_breadcrumb: ^1.0.1
  flutter_dotenv: ^5.1.0
  flutter_local_notifications: ^17.1.2
  flutter_localizations:
    sdk: flutter
  flutter_widget_from_html: ^0.15.0
  http: ^1.2.1
  image_picker: ^1.1.1
  intl: any
  location: ^6.0.2
  path: any
  provider: ^6.1.2
  share_plus: ^9.0.0
  shared_preferences: ^2.2.3
  transparent_image: ^2.0.1
  url_launcher: ^6.2.6
  youtube_player_iframe: ^5.1.2

dependency_overrides:
  js: ^0.7.1
  leak_tracker: ^10.0.5
  leak_tracker_flutter_testing: ^3.0.5
  material_color_utilities: ^0.11.1
  meta: ^1.15.0
  package_info_plus: ^8.0.0
  test_api: ^0.7.1
  vm_service: ^14.2.2

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^4.0.0

flutter:
  generate: true
  uses-material-design: true
  assets:
    - lib/.env

android/build.gradle:

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/app/build.gradle:

plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    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.exmaple.application_1"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    // kotlin {
    //     jvmToolchain(11)
    // }

    // buildFeatures {
    //     compose true
    // }
    
    // composeOptions {
    //     kotlinCompilerExtensionVersion '1.5.2'
    // }
    
    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.application_1
        // 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
        multiDexEnabled = true
    }

    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:1.9.0"
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'androidx.core:core-ktx:1.6.0'
    //implementation 'com.google.firebase:firebase-messaging:23.0.99'
    implementation 'com.google.firebase:firebase-bom:30.3.1'
    implementation 'net.consentmanager.sdk:android:2.4.0'
}

androidsettings.gradle:

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.0.0" apply false
    id "org.jetbrains.kotlin.android" version "1.8.22" apply false
    id "com.google.gms.google-services" version "4.3.13" apply false
}

include ":app"

androidgradlewrappergradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-8.0-all.zip

I have already many solutions other related question and articles but none of them has helped so far.
Does anyone have any idea what I could be missing or doing wrong here?

2

Answers


  1. Try replacing this line in android/app/build.gradle:

        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.0"
    
    

    With:

        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.1"
    
    Login or Signup to reply.
  2. I’ve found that this issue happens when you have location based packages in your app, not sure why, but this is how I fixed it.

    In android>build.gradle add this line to your buildscript

    change 2.0.0 to latest version if it isn’t anymore

        ext.kotlin_version = '2.0.0'
    

    so the top of the file should look something like this

    buildscript {
        ext.kotlin_version = '2.0.0'
        
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:7.4.2'  // Use the latest version available
            classpath 'com.google.gms:google-services:4.3.15'  // Use the latest version available
        }
    }
    

    In settings.gradle you have a plugins section. You need to change the kotlin version there too

    So this line

     id "org.jetbrains.kotlin.android" version "1.8.22" apply false
    

    Should be changed to

     id "org.jetbrains.kotlin.android" version "2.0.0" apply false
    

    The 2.0.0 should match the kotlin_version above

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search