Reputation: 277
I am trying to work through a tutorial on android compose. It works well while I use:kotlin-gradle-plugin:1.5.31, but the android studio has updated to :kotlin-gradle-plugin:1.6.10, and when I try running the program again it doesn't compile. I don't understand what the problem is. but even in the original run with the old version, I get the following message:
w: ATTENTION! This build uses unsafe internal compiler arguments: -XXLanguage:+NonParenthesizedAnnotationsOnFunctionalTypes This mode is not recommended for production use, as no stability/compatibility guarantees are given on compiler or generated code. Use it at your own risk!
when I try the new version it tells me that I must migrate the code, but when I do this I get the following message:
e: This version (1.0.5) of the Compose Compiler requires Kotlin version 1.5.31 but you appear to be using Kotlin version 1.6.10 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck
but don't say I didn't warn you!).
Task :app:mergeExtDexDebug FAILURE: Build failed with an exception.
Compilation error. See log for more details
and you can't migrate back even if you want to.
I don't know what to do with this or how to proceed forward.
Upvotes: 1
Views: 2326
Reputation: 37
I think your problem is with the version of Compose and Kotlin. A few days ago, I encountered a similar error, and after updating the Kotlin and Compose versions, my problem was fixed.
First of all change composeOptions:
composeOptions {
kotlinCompilerExtensionVersion compose_version
//kotlinCompilerVersion '1.5.31' the old version
kotlinCompilerVersion '1.6.21'
}
then update all your dependencies versions
dependencies {
implementation "androidx.compose.ui:ui-tooling:$compose_version"
.
.
.
}
then add this classpaths to gradle dependencies
dependencies {
//the older version of kotlin
//classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
.
.
.
}
At the end, i think this is an version compatibility issue between Kotlin and compose libraries.
You just need to update your dependencies.
Note : the $compose_version that i used in the dependencies is an variable in buildscript
buildscript {
ext {
kotlin_version = "1.6.21"
//compose_version = '1.0.5'
compose_version = '1.2.0-rc01'
}
.
.
.
}
I hope it helps you to solve your problem.
Upvotes: 0
Reputation: 760
In my case i specified kotlinCompilerExtensionVersion
for composeOptions
in build.gradle
of the app
module and error fixed:
build.gradle(app)
android {
composeOptions { kotlinCompilerExtensionVersion = "your compose version"}
}
Upvotes: 0
Reputation: 742
Finally, Figure out and fix the issue to run compose version
Currently Stable version 1.1.0
So here is my code for build.gradle(Project:app)
buildscript {
ext {
compose_version = '1.1.0'
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(Module)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.dreammeanings"
minSdk 21
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.4.1'
implementation 'androidx.activity:activity-compose:1.4.0'
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"
}
Upvotes: 1
Reputation: 277
I managed to find out that the right compos version for kotlin 1.6.10 is 1.2.0-alpha01, but I still get the message that this is not a stable version and should not be production use. But at least my program runs again.
Upvotes: 3