1、遇到的问题:
This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.7.0 which is not known to be compatible. Please fix your configuration (or
suppressKotlinVersionCompatibilityCheckbut don't say I didn't warn you!).
2、找到 compose 与 kotlin 的兼容性版本对照表
| Compose Compiler 版本 | 兼容的 Kotlin 版本 |
|---|---|
| 使用 Compose Compiler Gradle 插件启用 Compose。 | 2.0.0 及更高版本 |
| 1.5.14 | 1.9.24 |
| 1.5.13 | 1.9.23 |
| 1.5.12 | 1.9.23 |
| 1.5.11 | 1.9.23 |
| 1.5.10 | 1.9.22 |
| 1.5.9 | 1.9.22 |
| 1.5.8 | 1.9.22 |
| 1.5.7 | 1.9.21 |
| 1.5.6 | 1.9.21 |
| 1.5.5 | 1.9.20 |
| 1.5.4 | 1.9.20 |
| 1.5.3 | 1.9.10 |
| 1.5.2 | 1.9.0 版 |
| 1.5.1 | 1.9.0 版 |
| 1.5.0 | 1.9.0 版 |
| 1.4.8 | 1.8.22 |
| 1.4.7 | 1.8.21 |
| 1.4.6 | 1.8.20 |
| 1.4.5 | 1.8.20 |
| 1.4.4 | 1.8.10 |
| 1.4.3 | 1.8.10 |
| 1.4.2 | 1.8.10 |
| 1.4.1 | 1.8.0 |
| 1.4.0 | 1.8.0 |
| 1.4.0-alpha02 | 1.7.21 |
| 1.4.0-alpha01 | 1.7.20 |
| 1.3.2 | 1.7.20 |
| 1.3.1 | 1.7.10 |
| 1.3.0 | 1.7.10 |
| 1.3.0-rc02 | 1.7.10 |
| 1.3.0-rc01 | 1.7.10 |
| 1.3.0-beta01 | 1.7.10 |
| 1.2.0 | 1.7.0 |
| 1.2.0-rc02 | 1.6.21 |
| 1.2.0-rc01 | 1.6.21 |
| 1.2.0-beta03 | 1.6.21 |
| 1.2.0-beta02 | 1.6.21 |
| 1.2.0-beta01 | 1.6.21 |
| 1.2.0-alpha08 | 1.6.20 |
| 1.2.0-alpha07 | 1.6.10 |
| 1.2.0-alpha06 | 1.6.10 |
| 1.2.0-alpha05 | 1.6.10 |
| 1.2.0-alpha04 | 1.6.10 |
| 1.2.0-alpha03 | 1.6.10 |
| 1.2.0-alpha02 | 1.6.10 |
| 1.2.0-alpha01 | 1.6.10 |
| 1.1.1 | 1.6.10 |
| 1.1.0 | 1.6.10 |
| 1.1.0-rc03 | 1.6.10 |
| 1.1.0-rc02 | 1.6.10 |
| 1.1.0-rc01 | 1.6.0 |
| 1.1.0-beta04 | 1.6.0 |
| 1.1.0-beta03 | 1.5.31 |
| 1.1.0-beta02 | 1.5.31 |
| 1.1.0-beta01 | 1.5.31 |
| 1.1.0-alpha06 | 1.5.31 |
| 1.1.0-alpha05 | 1.5.31 |
| 1.0.5 | 1.5.31 |
| 1.0.4 | 1.5.31 |
| 1.1.0-alpha04 | 1.5.30 |
| 1.1.0-alpha03 | 1.5.30 |
| 1.0.3 | 1.5.30 |
| 1.1.0-alpha02 | 1.5.21 |
| 1.1.0-alpha01 | 1.5.21 |
| 1.0.2 | 1.5.21 |
| 1.0.1 | 1.5.21 |
| 1.0.0 | 1.5.10 |
| 1.0.0-rc02 | 1.5.10 |
| 1.0.0-rc01 | 1.5.10 |
3、解决问题:
解决思路:根据错误提示,分析如下:
- 1、Compose(V1.1.1版本)和 Kotlin (V1.6.10版本) 是对应的;
- 2、我们在项目中使用了Kotlin(V1.7.0版本);
- 3、查看对照表Compose(V1.2.0版本)和 Kotlin (V1.7.0版本) 是对应的
所以,我们把项目配置为Compose(V1.2.0版本)和 Kotlin (V1.7.0版本) 就OK了。
4、更改代码:
发现在 project 下的 build.gradle 中有:
buildscript {
ext {
//1、Compose的版本更改为1.2.0
compose_ui_version = '1.2.0'
}
}
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
//2、Kotlin的版本更改为1.7.0
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}
在module / build.gradle 中,增加
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.mycomposedemo'
compileSdk 33
defaultConfig {
applicationId "com.example.mycomposedemo"
minSdk 21
targetSdk 33
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 {
//3、Compose的版本更改为1.2.0
kotlinCompilerExtensionVersion '1.2.0'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
//4、Kotlin的版本更改为1.7.0
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.1.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_ui_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
//约束布局
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-rc02"
//显示图片
implementation "io.coil-kt:coil-compose:2.2.2"
implementation "io.coil-kt:coil-svg:2.2.2"
implementation "com.github.skydoves:landscapist-coil:2.0.3"
implementation "com.github.skydoves:landscapist-glide:2.1.0"
implementation "com.github.skydoves:cloudy:0.1.1"
implementation "io.coil-kt:coil-gif:2.3.0"
}