I am getting this error when build the apps Execution failed for task ':app:kaptGenerateStubsDebugKotlin'

huangapple go评论90阅读模式
英文:

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'
}

huangapple
  • 本文由 发表于 2023年7月27日 14:29:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76777020.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定