본문 바로가기
*오류해결

Execution failed for task ':react-native-gradle-plugin:compileKotlin' 오류

by yun5o 2023. 2. 14.

npm run android 프로젝트명 을 실행하니 오류가 발생했습니다.

error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.

> Task :react-native-gradle-plugin:compileKotlin FAILED
'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.
1 actionable task: 1 executed

FAILURE: Build failed with an exception.                                                                                              
                                                                                                                                      
* What went wrong:                                                                                                                    
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.                                                                
> Failed to query the value of task ':react-native-gradle-plugin:compileKotlin' property 'compilerRunner$kotlin_gradle_plugin'.       
   > Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilation is running on a JDK, not JRE.

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

* Get more help at https://help.gradle.org                                                                                            

BUILD FAILED in 1m 41s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.


* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 41s

    at makeError (D:\app\weightLog\node_modules\execa\index.js:174:9)
    at D:\app\weightLog\node_modules\execa\index.js:278:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async runOnAllDevices (D:\app\weightLog\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
    at async Command.handleAction (D:\app\weightLog\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.

compileJava 버전은 1.8이고 compileKotlin 버전은 11이라서 둘의 버전차이가 나서 오류가 발생했다고 합니다.

 

아래 명령어를 사용하여 환경 상태를 확인할 수 있습니다.

npx react-native doctor

JDK랑 Android SDK 버전을 찾을 수 없다고 나옵니다.

 

* Android SDK 버전 설정

File > Settings > Appearance & Behavior > System Settings > Android SDK로 들어가서 Android SDK Command-line Tools을 install 해줍니다.

 

그러고 다시 조회해 보면 Android SDK에 버전이 뜨는 것을 확인할 수 있습니다. 하지만 설정된 버전과 일치하지 않습니다.

 

build.gradle 폴더로 이동하여 buildToolsVersion을 Versions found와 맞춰줍니다. 저는 33.0.1로 변경해 줬습니다.

 

다시 조회해 보니 정상적으로 반영된 것을 확인할 수 있습니다.

 

* JDK 버전 설정

File > Project Structure... 를 선택해 줍니다.

 

Platform Settings > SDKs로 들어와서 JDK home path를 확인합니다.

현재 JAVA_HOME 경로가 아닌 jre 경로가 설정되어 있습니다.

 

내 PC > 우클릭 속성 > 고급 시스템 설정 > 환경변수 > JAVA_HOME에 설정된 값으로 JDK home path를 설정합니다.

 

다시 조회해 보면 정상적으로 반영된 것을 확인할 수 있습니다.

댓글