Android Studio : jvm target compatibility should be set to the same Java version.Android Studio 에러 해결

A

최근 Android Studio 에서 새로운 프로젝트를 만들면 다음과 같은 에러가 나면서 빌드가 되지 않는 경우가 잦습니다.

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

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

Command + ; 버튼을 누르거나 File Menu -> Project Structure 를 클릭하여 Project Structure 설정으로 들어갑니다

좌측의 SDK Location 메뉴에서 JDK location was moved to Gradle Settings. 를 클릭합니다.

Gradle JDK 를 사용하려는 JDK 버전으로 변경합니다. Download JDK 옵션에서 특정 JDK 를 설치할 수 있습니다. Amazon Corretto JDK를 이용했습니다.

app 모듈의 build.gradle.kts 파일의 다음 부분을 다음과 같이 변경합니다. 사용하시는 JDK 의 버전에 따라 버전을 맞춰주시면 됩니다.

compileOptions {
    sourceCompatibility = JavaVersion.VERSION_18
    targetCompatibility = JavaVersion.VERSION_18
}

kotlinOptions {
    jvmTarget = "18"
}

compileOptions 의 JDK 버전kotlinOptions의 JDK 버전, 그리고 빌드하는 프로젝트의 Gradle JDK의 버전이 같아야 정상적으로 빌드가 됩니다.

About the author

Gyeongrok Kim

Add comment

Your sidebar area is currently empty. Hurry up and add some widgets.