react-native run-android error

Jean Deluge·2021년 2월 24일
1

리액트앱만들기

목록 보기
2/3

1. react-native run-android 에러

 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/jean/JEAN/JeansProject/PThelper/front/tsHealthApp/android/local.properties'.

이 에러 문구를 해결 하기 위해서 react-native 앱에서 android 디렉토리에서
local.properties 파일을 만들고,
그 안에 sdk.dir = /Users/"username"/Library/Android/sdk 를 넣어줌

warn Failed to connect to development server using "adb reverse": spawnSync adb ENOENT
info Starting the app...
error Failed to start the app. Run CLI with --verbose flag for more details.
Error: spawnSync adb ENOENT
    at Object.spawnSync (internal/child_process.js:1041:20)

이번엔 이 에러가 나서

 npx @react-native-community/cli doctor
 

를 실행해서 문제를 확인

Common
 ✓ Node.js
 ✓ yarn
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✖ JDK
   - Version found: 1.8.0_282
   - Version supported: >= 8
 ✓ Android Studio - Required for building and installing your app on Android
 ✓ Android SDK - Required for building and installing your app on Android
 ✖ ANDROID_HOME

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ CocoaPods - Required for installing iOS dependencies
 ✓ ios-deploy - Required for installing your app on a physical device with the CLI

Errors:   2
Warnings: 0

Usage
 › Press f to try to fix issues.
 › Press e to try to fix errors.
 › Press w to try to fix warnings.
 › Press Enter to exit.

JDK 버전이 맞지않고, 환경변수에서 ANDROID_HOME 이 제대로 설정이 안되어 있다보다.

그래서 JDK를
brew reinstall adoptopenjdk8
로 재인스톨하고

JAVA 환경변수가 맞지 않아 터미널에서 open ~/.bash_profile 에서

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home
export PATH=${PATH}:$JAVA_HOME/bin

로 수정 후 source ~/.bash_profile 로 적용

이번엔

ndroid
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✖ Android SDK - Required for building and installing your app on Android
   - Versions found: N/A
   - Version supported: 29.0.2
 ✖ ANDROID_HOME

android SDK 쪽에서 문제가 있어서,

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

ANDROID_HOME 경로 다시 확인해서 넣어주어서 해결

  1. FAILURE: Build failed with an exception.
info JS server already running.
info Installing the app...

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 488ms

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

찾아보니 gradle 문제 인 것 같다고해서
app > android> gradle>wrapper > gradle-wrapper.properties 에서

distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip

로 바꾸어줌

 Could not find method compileSdkVersion() for arguments [29] on object of type org.gradle.internal.extensibility.DefaultExtraPropertiesExtension.

에러가 남 ㅠ

알고보니 android > build.gradle에서

compileSdkVersion  29 

'='이 빠져있었음.

=>! 성공적으로 실행 완료!

  • 가끔 ANDROID_HOME 이 지정안되어있다고 해서 package.json 의 script에
    "android": "source ~/.bash_profile&&react-native run-android"
    로 바꾸어주어 실행시마다 환경변수 적용해주도록 했다.
profile
node.js , rudyonrails개발자

0개의 댓글