react-native build error
react-native 세팅을 마치고 ios로 돌려보고 android로 돌려보려는 찰나! build Failed!
그래서 원인을 찾기위해 구글링을 시작.
문제가 발생했을때 나의 RN-android 관련 버전 정보는 아래와 같다.
java version "14.0.1" 2020-04-14
Java(TM) SE Runtime Environment (build 14.0.1+7)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
Android 10.0(Q)
"react": "16.11.0",
"react-native": "0.62.2"react-native android build error
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
에러 메세지는 아래와 같다.
FAILURE: Build failed with an exception.
* What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
* 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 687ms
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
* 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 687ms
at makeError (/Users/app/node_modules/execa/index.js:174:9)
at /Users/app/node_modules/execa/index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async runOnAllDevices (/Users/app/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:5)
at async Command.handleAction (/Users/app/node_modules/@react-native-community/cli/build/index.js:186:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! SampleApp@0.0.1 android: `react-native run-android`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the SampleApp@0.0.1 android script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.해결 방법
- 아래 경로에 있는 gradle-wrapper.properties 안에 distributionUrl을 변경한다
# 사용자프로젝트dir/android/gradle/wrapper/gradle-wrapper.properties
#수정 전
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
#수정 후
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip- build.gradle 파일을 통해 gradle build를 실행한다.
빌드하는 방법을 모르겠다면 이걸 보세요
- 안드로이드 스튜디오로 프로젝트 경로를 open
- android 경로 안에 있는 build.gradle 파일을 마우스 오른쪽 클릭 후 Run
출처 : https://github.com/gradle/gradle/issues/10248#issuecomment-633656326