개발새발 - IT 기술블로그
article thumbnail

Error  'compileDebugJavaWithJavac' task (current target is 11) and 'compileDebugKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.

 

작성코드👀

 

<build.gradle>

Android {
...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    kotlinOptions {
        jvmTarget='11'
    }
...
}

자바 버전을 JavaVersion.VERSION_1_8(8)에서 JavaVersion.VERSION_11(11)로 올리면서 컴파일 도중 에러가 발생했다.

 

원인은 다음과 같다.

 

compileDebugJavaWithJavac 에 사용되는 JVM의 버전과  compileDebugKotlin 에 사용되는 JVM의 버전이 서로 달라 디버깅 과정에서 충돌이 일어났던 것.

 

따라서 위 작성코드 처럼 코틀린 디버깅 옵션에 JVM버전을 수동으로 입력해 주면 된다.

 

아무래도 Java11은 안드로이드 프레임워크가 공식 지원하는 버전인 Java8이 아니다보니 코틀린에서 자동으로 Java8로 컴파일을 시도해서 생기는 오류인 듯 하다.

 

 

 

참고

 

https://cliearl.github.io/posts/android/android-gradle-java-11/

 

Android Studio Arctic Fox와 JDK 11의 도입

이번 포스팅에서는 Android Studio Arctic Fox와 JDK 11의 도입에 관한 내용을 다루어보도록 하겠습니다. Android Gradle 7.0.0 도입 2021년 7월 말에 Android Studio의 버전이 Arctic Fox|2020.3.1 로 올라갔습니다. 그 과

cliearl.github.io

 

 

 

https://stackoverflow.com/questions/69079963/how-to-set-compilejava-task-11-and-compilekotlin-task-1-8-jvm-target-com

 

How to set compileJava' task ( 11) and 'compileKotlin' task (1.8) jvm target compatibility to the same Java version in build.gra

Build.gradle.kts buildscript { repositories { google() mavenCentral() gradlePluginPortal() } dependencies { classpath ("com.android.tools.build:grad...

stackoverflow.com