尽管 Kotlin 版本正确,但构建时仍出现错误
2022-07-20
883
太荒谬了,我收到此错误,而我确实有:
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
更新: 一整天都运行正常。当我决定合并它时, https://dagger.dev/hilt/ ,问题就开始出现了。不知道为什么,我按照网站上的所有说明操作。 😔😔😔
Android 已安装:
错误:
> Task :app:compileDebugKotlin FAILED
e: This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.6.21 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
> Compilation error. See log for more details
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 648ms
28 actionable tasks: 1 executed, 27 up-to-date
build.gradle(项目):
buildscript {
ext {
compose_version = '1.1.1'
coroutines = '1.6.4'
accompanist = '0.24.13-rc' // https://github.com/google/accompanist
datastore = '1.0.0' // https://developer.android.com/jetpack/androidx/releases/datastore
room = '2.4.2'
navigation = '2.5.0'
lifecycle = '2.5.0' // https://developer.android.com/jetpack/androidx/releases/lifecycle
material3 = '1.0.0-alpha14' // https://developer.android.com/jetpack/androidx/releases/compose-material3
work = '2.7.1' // https://developer.android.com/jetpack/androidx/releases/work
rcview = '1.2.1' // https://developer.android.com/jetpack/androidx/releases/recyclerview
rcview_select = '1.1.0'
}
repositories {
google()
mavenCentral()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.42'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(模块):
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.dagger.hilt.android'
id 'kotlin-android'
id "kotlin-kapt"
}
android {
compileSdk 32
defaultConfig {
applicationId ""
minSdk 24
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
javaCompileOptions {
annotationProcessorOptions {
arguments += [
"room.schemaLocation":"$projectDir/schemas".toString(),
"room.incremental":"true",
"room.expandProjection":"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 {
kotlinCompilerVersion "1.6.10"
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation "androidx.datastore:datastore-preferences:$datastore"
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines"
// Work
implementation "androidx.work:work-runtime-ktx:$work"
// optional - Paging 3 Integration
implementation "androidx.room:room-paging:2.5.0-alpha02"
// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$navigation"
implementation "androidx.navigation:navigation-ui-ktx:$navigation"
implementation "androidx.navigation:navigation-dynamic-features-fragment:$navigation"
// Testing Navigation
androidTestImplementation "androidx.navigation:navigation-testing:$navigation"
// Jetpack Compose Integration
implementation "androidx.navigation:navigation-compose:$navigation"
// status bar customization
implementation "com.google.accompanist:accompanist-systemuicontroller:0.23.1"
// Accompanist
implementation "com.google.accompanist:accompanist-pager:0.23.0" // Pager
implementation "com.google.accompanist:accompanist-pager-indicators:0.23.0" // Pager Indicators
implementation "androidx.recyclerview:recyclerview:$rcview"
// For control over item selection of both touch and mouse driven selection
implementation "androidx.recyclerview:recyclerview-selection:$rcview_select"
// Card view
implementation "androidx.cardview:cardview:1.0.0"
implementation 'com.google.dagger:hilt-android:2.42'
kapt 'com.google.dagger:hilt-compiler:2.42'
//implementation("com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.6")
// For instrumentation tests
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.42'
kaptAndroidTest 'com.google.dagger:hilt-compiler:2.42'
// For local unit tests
testImplementation 'com.google.dagger:hilt-android-testing:2.42'
kaptTest 'com.google.dagger:hilt-compiler:2.42'
implementation("androidx.room:room-runtime:$room")
annotationProcessor("androidx.room:room-compiler:$room")
// To use Kotlin annotation processing tool (kapt)
kapt("androidx.room:room-compiler:$room")
// optional - Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:$room")
implementation 'androidx.core:core-ktx:1.8.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.animation:animation-graphics:$compose_version"
implementation "androidx.compose.material3:material3:$material3"
implementation "androidx.compose.material3:material3-window-size-class:$material3"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle"
implementation 'androidx.activity:activity-compose:1.5.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"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}
settings.gradle
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
kotlin.code.style=official
android.nonTransitiveRClass=true
android.enableJetifier=true
org.gradle.daemon=true
kapt.correctErrorTypes=true
org.gradle.parallel=true
android.lifecycleProcessor.incremental=true
1个回答
在您的
build.gradle
(模块)文件中的
composeOptions
下有一行
kotlinCompilerVersion "1.6.10"
,请将其更改为与您的 Kotlin 版本
1.6.21
相匹配。
2022-07-20