ERROR: npx react-native run-android

김래영·2020년 7월 31일
1

React-Native

목록 보기
1/10

react-native cli로 세팅을 하고 ios 시뮬레이터에서는 정상작동하던 프로젝트가 android에서는 아래와 같은 오류를 내면서 에뮬레이터가 정상작동하지 않는 상황이 발생했다.

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 1s

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

안드로이드 스튜디오 환경설정이 잘못됐나 싶어 확인해보았지만 발생한 에러와 관계가 없었고 npx react-native start를 실행했을 때에 error listen EADDRINUSE: address already in use :::8081라는 에러가 나와 포트를 죽이고 재실행 하면 되지 않을까 싶어 포트를 죽이고 재실행해 보았지만 결과는 같았다.

port kill하기

계속되는 구글링으로 에뮬레이터가 정상적으로 실행되지만 에뮬레이터 안에 앱이 설치가 되지 않으면서 에러가 발생하는 것을 알게됐다.

<변경전>
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
<변경후>
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

다시 npx react-native run-android 로 실행해 보니 뭔가 달라졌지만 이번엔 아래와 같은 다른 에러가 발생했다.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:installDebug'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/gimlaeyeong/Desktop/react-native/test/android/local.properties'.

* 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 48s

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

  • React Native 프로젝트 안에 /android 안에 local.properties 파일을 생성한 후 아래와 같이 작성한 다음 npx react-native run-android 를 다시 실행해보니 오류없이 정상작동 하는것을 확인할 수 있었다.

    sdk.dir = /Users/<USERNAME>/Library/Android/sdk

해결 방법

  • React Native 프로젝트 안에 /android/gradle/wrapper/gradle-wrapper.properties 파일로 이동하여 distributionUrl로 시작하는 라인에서 아래와같이 gradle 버전을 변경해준다

    distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
  • React Native 프로젝트 안에 /android 안에 local.properties 파일을 생성한 후 아래와 같이 작성해 준다.

    • mac

      sdk.dir = /Users/<USERNAME>/Library/Android/sdk
    • windows

      sdk.dir = C:\\Users\\<USERNAME>\\AppData\\Local\\Android\\sdk
    • linux

      sdk.dir = /home/<USERNAME>/Android/Sdk
profile
개발 노트

1개의 댓글

comment-user-thumbnail
2020년 8월 5일

저 같은 경우는

  • What went wrong:
    Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
    요 에러가 계속 나와서 진행했었는데
    포트 번호만 바꾸니 바로 되었어요 하던 다른 프젝를 종료를 완벽하게 했다고 생각했는데
    그 프젝이랑 포트가 겹쳐서 그랬나봐요 ㅎㅎ
    감사합니다 :)
답글 달기