Article directory
Problem Description
Android Studio Version: 2021.2.1 Patch 2
After creating a compose project and running it, an error similar to the following is reported:
“This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.5.31 …”
Solve the problem
1. Find the compatibility version comparison table between compose and kotlin
My goal is as follows , I want to apply the latest version
2. Add compose compiler dependency
In module/build.gradle, add
implementation "androidx.compose.compiler:compiler:1.3.0"
The latest AS version is automatically prompted. Enter 1.3 and find that 1.3.0 is available, but the stable version 1.3.0 in the document has not been updated yet.
Then run it and find that the error is still there...
3. Modify the kotlin version configuration
Found in build.gradle under project:
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
}
Find the configuration of kotlin 1.5.31 and modify it to 1.7.10.
4. Modify other compose dependencies to the latest stable version
You can view the latest release log on the Compose repository - stable version page. like:
It is found that the latest version of other compose libraries is 1.2.1, and 1.3.0 cannot be used when using automatic prompts in AS, so they are all changed to 1.2.1.
[app module] / build.gradle:
android {
compileSdk 33
defaultConfig {
...
targetSdk 33
}
...
composeOptions {
kotlinCompilerExtensionVersion '1.3.0'
}
}
dependencies {
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10"
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.compiler:compiler:1.3.0"
implementation "androidx.compose.ui:ui:1.2.1"
implementation "androidx.compose.animation:animation:1.2.1"
implementation "androidx.compose.animation:animation-graphics:1.2.1"
implementation "androidx.compose.foundation:foundation:1.2.1"
implementation "androidx.compose.foundation:foundation-layout:1.2.1"
implementation "androidx.compose.runtime:runtime:1.2.1"
implementation 'androidx.compose.material3:material3:1.0.0-alpha16'
implementation "androidx.compose.ui:ui-tooling-preview:1.2.1"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.5.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:1.2.1"
debugImplementation "androidx.compose.ui:ui-tooling:1.2.1"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.2.1"
}
After the final gradle sync, the compilation and operation were successful ^~^
.