Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1 error in compose

Viewed 92

I am using Google map for my app with jetpack compose I implemented these dependencies

 //Compose Maps

implementation 'com.google.maps.android:maps-compose:2.5.3'
implementation 'com.google.android.gms:play-services-maps:18.0.2'

in my app.gradle file

and I am getting this error

Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.

I used everything please answer this question.

my app.gradle file:-

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'

}

android { compileSdk 32

defaultConfig {
    applicationId "com.example.mapsincompose"
    minSdk 23
    targetSdk 32
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    vectorDrawables {
        useSupportLibrary true
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
}
buildFeatures {
    compose true
}
composeOptions {
    kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
    resources {
        excludes += '/META-INF/{AL2.0,LGPL2.1}'
    }
}

}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"


//Compose Maps

implementation 'com.google.maps.android:maps-compose:2.5.3'
implementation 'com.google.android.gms:play-services-maps:18.0.2'

}

my project.gradel file:-

buildscript {
ext {
    compose_version = '1.1.0-beta01'
}

}

plugins {
    id 'com.android.application' version '7.2.2' apply false
    id 'com.android.library' version '7.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
2 Answers

The following might help you out:

Obs! Have you followed the implementation of google maps correctly ? This includes created a google cloud account for the API key and implementations of it ?

  1. Update compose to the latest version:
compose_version = "1.3.0-beta02"
  1. Change:
kotlinCompilerExtensionVersion = "1.2.0"
  1. Change the plugin to:
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
  1. You need to make sure you have all dependencies:

a) Add this to you app.gradle file:

id 'com.google.gms.google-services'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'

b) In build.gradle Project:

id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false

Let me know if this resolved your problem!

in ext block of project level gradle file change compose version like this :-

compose_version = '1.1.0-rc03'

and add this to the dependency in the same file like this

dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
}

it worked for me and I hope it will work for every one

explanation:- basically here I just change compose version to the latest version and I change kotlin version according to the compose version support here is the full documentation.

Related