英文:
I am getting this error when build the apps Execution failed for task ':app:kaptGenerateStubsDebugKotlin'
问题
执行任务“:app:kaptGenerateStubsDebugKotlin”失败。
>“compileDebugJavaWithJavac”任务(当前目标为1.8)和“kaptGenerateStubsDebugKotlin”任务(当前目标为17)的JVM目标兼容性应设置为相同的Java版本。
请考虑使用JVM工具链:https://kotl.in/gradle/jvm/toolchain
以下是我的app gradle文件:
插件{
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}
android{
命名空间'com.waltonbd.daggerwithcheezy'
compileSdk 32
defaultConfig{
applicationId "com.waltonbd.daggerwithcheezy"
minSdk 24
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
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'
}
}
dependencies{
def dagger_version = "2.40.5"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
英文:
Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain
And here is my app gradle file
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}
android {
namespace 'com.waltonbd.daggerwithcheezy'
compileSdk 32
defaultConfig {
applicationId "com.waltonbd.daggerwithcheezy"
minSdk 24
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
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'
}
}
dependencies {
def dagger_version = "2.40.5"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
答案1
得分: 1
错误意味着在compileDebugJavaWithJava
任务和kaptGenerateStubsDebugKotlin
任务之间,编译使用的Java版本不匹配。
请确保这两个任务都使用相同的Java版本。更新你的Kotlin options
,使用支持Java 17的更高版本的JVM。
例如:
...
kotlinOptions {
jvmTarget = '17'
}
英文:
The error means there is a mismatch in the Java version being used for compilation between the compileDebugJavaWithJava
task and the kaptGenerateStubsDebugKotlin
task.
Make sure both tasks are using the same Java version. Update your Kotlin options
to use a higher version of the JVM that supports Java 17.
e.g.
...
kotlinOptions {
jvmTarget = '17'
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论