Getting error: Execution failed for task ':app:kaptGenerateStubsDebugKotlin'. after upgrading to Android Studio Flamingo | 2022.2.1

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

Getting error: Execution failed for task ':app:kaptGenerateStubsDebugKotlin'. after upgrading to Android Studio Flamingo | 2022.2.1

问题

After updating Android Studio version to 2022.2.1,I started to get this error when trying to compile the project:

> Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.<br>
> '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.<br>
> Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

My gradle:
compileSdk 33

defaultConfig {
minSdk 23
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.incremental": "true"]
}
}

consumerProguardFiles 'proguard-rules.pro'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}

How to fix this error?

Android Studio Flamingo | 2022.2.1<br>
Build #AI-222.4459.24.2221.9862592, built on March 31, 2023<br>
Runtime version: 17.0.6+0-17.0.6b802.4-9586694 aarch64<br>
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.<br>
macOS 13.3.1

英文:

After updating Android Studio version to 2022.2.1 I started to get this error when trying to compile the project:

> Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.<br>
> '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.<br>
> Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

My gradle:
compileSdk 33

defaultConfig {
    minSdk 23
    targetSdk 33

    testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;

    javaCompileOptions {
        annotationProcessorOptions {
            arguments = [&quot;room.incremental&quot;: &quot;true&quot;]
        }
    }

    consumerProguardFiles &#39;proguard-rules.pro&#39;
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = &quot;1.8&quot;
}

How to fix this error?

Android Studio Flamingo | 2022.2.1<br>
Build #AI-222.4459.24.2221.9862592, built on March 31, 2023<br>
Runtime version: 17.0.6+0-17.0.6b802.4-9586694 aarch64<br>
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.<br>
macOS 13.3.1

答案1

得分: 2

If you updated Gradle to version 8.0.0 along with the Flamingo 2022.2.1 update, then you need to update the JDK to version 17.

You can see the compatibility table here.

The following code in app level build.gradle should solve your problem:

android {
    ...
    compileOptions {
        sourceCompatibilityJavaVersion.VERSION_17
        targetCompatibilityJavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }
    ...
}
英文:

If you updated Gradle to version 8.0.0 along with the Flamingo 2022.2.1 update, then you need to update the JDK to version 17

You can see the compatibility table here.

The following code in app level build.gradle should solve your problem:

android {
    ...
    compileOptions {
        sourceCompatibilityJavaVersion.VERSION_17
        targetCompatibilityJavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = &#39;17&#39;
    }
    ...
}

答案2

得分: 0

这在Android Studio Giraffe上运行良好。

根据此工具链文档

将此内容添加到应用程序gradle文件中可解决我的问题。

compileOptions {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = "1.8"
}

//important
kotlin {
    jvmToolchain(18)
}
英文:

This worked well for Android Studio Giraffe

As per This Toolchain Documentation

Adding this in the app gradle file fixed the issue for me.

compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = &quot;1.8&quot;

    }

    //important
    kotlin {
        jvmToolchain(18)
    }

huangapple
  • 本文由 发表于 2023年4月17日 18:06:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033964.html
匿名

发表评论

匿名网友

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

确定