英文:
Compose Complier & Kotlin Version Compatibility
问题
所以我在升级项目后无法使我的应用程序正常工作。
我遇到了以下错误:
> Task :app:compileDebugKotlin FAILED
e: This version (1.0.3) of the Compose Compiler requires Kotlin version 1.5.30 but you appear to be using Kotlin version 1.8.20 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
我已经安装了最新版本的插件(223-1.8.0-release-345-AS8836.35.2231.10406996)在Android Studio Giraffe 2022.3.1上,但我无法解决这个问题。
这是我的完整build.gradle(:app):
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.0.3'
kotlinCompilerVersion '1.5.30'
}
kotlinOptions {
jvmTarget = "1.8"
}
namespace '__________'
compileSdk 33
defaultConfig {
applicationId "___________"
minSdk 30
targetSdkVersion 33
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
vectorDrawables{
useSupportLibrary = true
}
}
buildTypes {
release {
minifyEnabled true // https://www.youtube.com/watch?v=EOQB8PTLkpY&list=PLWz5rJ2EKKc9Ty3Zl1hvMVUsXfkn93NRk
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
// Added for MVVM: https://www.simplifiedcoding.net/firebase-mvvm-example/
dataBinding {
enabled = true
}
}
dependencies {
implementation 'androidx.activity:activity-compose:1.7.2'
implementation 'androidx.activity:activity-ktx:1.7.2'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat-resources:1.6.1'
implementation 'androidx.core:core-ktx:1.10.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
// Lifecycle
implementation "androidx.lifecycle:lifecycle-runtime-compose:2.6.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1" //https://www.simplifiedcoding.net/firebase-mvvm-example/
// Compose
implementation platform('androidx.compose:compose-bom:2023.06.01')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview:1.4.3'
implementation 'androidx.compose.material3:material3:1.1.1'
implementation "androidx.compose.material:material-icons-extended"
implementation 'androidx.compose.material:material:1.4.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
debugImplementation 'androidx.compose.ui:ui-tooling:1.4.3'
debugImplementation 'androidx.compose.ui:ui-test-manifest:1.4.3'
// Navigation
implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.6.0'
// Testing
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
testImplementation 'junit:junit:4.13.2'
// Add the SDKs for any other Firebase products you want to use in your app
// For example, to use Firebase Authentication and Cloud Firestore
implementation 'com.google.firebase:firebase-firestore:24.7.0'
implementation 'com.google.firebase:firebase-auth:22.1.1'
implementation 'com.google.firebase:firebase-messaging:23.2.1'
implementation 'com.google.firebase:firebase-core:21.1.1'
implementation 'com.google.firebase:firebase-storage:20.2.1'
implementation 'com.google.android.gms:play-services-auth:20.6.0'
// Add the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-analytics:21.3.0'
// // Picasso
// implementation 'com.squareup.picasso:picasso:2.71828'
//anko https://www.youtube.com/watch?v=uB7WeED1d1w
// implementation "org.jetbrains.anko:anko:0.10.4"
// implementation "org.jetbrains.anko:anko-design:0.10.4"
// implementation "org.jetbrains.anko:anko-coroutines:0.10.4"
// Material Dialogs (https://github.com/afollestad/material-dialogs, recommended by CodingWithMitch https://www.youtube.com/watch?v=_sOHZAk6KnA)
implementation 'com.afollestad.material-dialogs:core:3.3.0'
implementation 'com.afollestad.material-dialogs:input:3.3.0'
implementation 'com.afollestad.material-dialogs:datetime:3.3.0'
implementation 'com.afollestad.material-dialogs:lifecycle:3.3.0'
// debugImplementation because LeakCanary should only run in debug builds.
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
// Couroutines Dependency
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
}
这是我的完整build.gradle(Project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
classpath 'com.android.tools.build:gradle:8.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://developer.android.com/studio/build/repository' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
英文:
So I am struggling to get my app to work after upgrading my project.
I am getting the following error:
> Task :app:compileDebugKotlin FAILED
e: This version (1.0.3) of the Compose Compiler requires Kotlin version 1.5.30 but you appear to be using Kotlin version 1.8.20 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
I have the latest version of the plugin installed (223-1.8.0-release-345-AS8836.35.2231.10406996) on Android Studio Giraffe 2022.3.1, but I cannot get this to go away.
Here is my full build.gradle(:app):
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.0.3'
kotlinCompilerVersion '1.5.30'
}
kotlinOptions {
jvmTarget = "1.8"
}
namespace '__________'
compileSdk 33
defaultConfig {
applicationId "___________"
minSdk 30
targetSdkVersion 33
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
vectorDrawables{
useSupportLibrary = true
}
}
buildTypes {
release {
minifyEnabled true // https://www.youtube.com/watch?v=EOQB8PTLkpY&list=PLWz5rJ2EKKc9Ty3Zl1hvMVUsXfkn93NRk
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
// Added for MVVM: https://www.simplifiedcoding.net/firebase-mvvm-example/
dataBinding {
enabled = true
}
}
dependencies {
implementation 'androidx.activity:activity-compose:1.7.2'
implementation 'androidx.activity:activity-ktx:1.7.2'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat-resources:1.6.1'
implementation 'androidx.core:core-ktx:1.10.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
// Lifecycle
implementation "androidx.lifecycle:lifecycle-runtime-compose:2.6.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1" //https://www.simplifiedcoding.net/firebase-mvvm-example/
// Compose
implementation platform('androidx.compose:compose-bom:2023.06.01')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview:1.4.3'
implementation 'androidx.compose.material3:material3:1.1.1'
implementation "androidx.compose.material:material-icons-extended"
implementation 'androidx.compose.material:material:1.4.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
debugImplementation 'androidx.compose.ui:ui-tooling:1.4.3'
debugImplementation 'androidx.compose.ui:ui-test-manifest:1.4.3'
// Navigation
implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.6.0'
// Testing
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
testImplementation 'junit:junit:4.13.2'
// Add the SDKs for any other Firebase products you want to use in your app
// For example, to use Firebase Authentication and Cloud Firestore
implementation 'com.google.firebase:firebase-firestore:24.7.0'
implementation 'com.google.firebase:firebase-auth:22.1.1'
implementation 'com.google.firebase:firebase-messaging:23.2.1'
implementation 'com.google.firebase:firebase-core:21.1.1'
implementation 'com.google.firebase:firebase-storage:20.2.1'
implementation 'com.google.android.gms:play-services-auth:20.6.0'
// Add the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-analytics:21.3.0'
// // Picasso
// implementation 'com.squareup.picasso:picasso:2.71828'
//anko https://www.youtube.com/watch?v=uB7WeED1d1w
// implementation "org.jetbrains.anko:anko:0.10.4"
// implementation "org.jetbrains.anko:anko-design:0.10.4"
// implementation "org.jetbrains.anko:anko-coroutines:0.10.4"
// Material Dialogs (https://github.com/afollestad/material-dialogs, recommended by CodingWithMitch https://www.youtube.com/watch?v=_sOHZAk6KnA)
implementation 'com.afollestad.material-dialogs:core:3.3.0'
implementation 'com.afollestad.material-dialogs:input:3.3.0'
implementation 'com.afollestad.material-dialogs:datetime:3.3.0'
implementation 'com.afollestad.material-dialogs:lifecycle:3.3.0'
// debugImplementation because LeakCanary should only run in debug builds.
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
// Couroutines Dependency
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
}
<!-- end snippet -->
This is my full build.gradle(Project):
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
classpath 'com.android.tools.build:gradle:8.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://developer.android.com/studio/build/repository' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
<!-- end snippet -->
答案1
得分: 2
根据这个链接,你会知道你的编译器版本应该与 Kotlin 版本匹配。你正在使用 Kotlin 版本 1.8.20,在构建文件中将 Compose 编译器更改为 1.4.5。
composeOptions {
kotlinCompilerExtensionVersion = "1.4.5"
}
英文:
Following this link you will know that your compiler version should match with the kotlin version. You are using kotlin version 1.8.20 ,in the build file change the compose compiler to 1.4.5
composeOptions {
kotlinCompilerExtensionVersion = "1.4.5"
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论