react-native: npx react-native run-android Failing in macOS
- I Had Setup Android Studio installed in Mac
- I had installed ADB Nexus 6p (R and Android Pie)
- Tried Manually Running Android Emulator - Works Perfect
AVD Manager:
Nexus 6p with Android R and Android Pie
Installed SDK:
SDK Platforms
bash_profile or bashrc
Command Used: nano .bash_profile
export ANDROID_HOME=/Users/user/Library/Android/sdk
export PATH=${PATH}:/Users/user/Library/Android/sdk/tools
export PATH=${PATH}:/Users/user/Library/Android/sdk/platform-tools
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
Command used: npx @react-native-community/cli doctor
user@Devs-Mac MyReactApp % npx @react-native-community/cli doctor
Common
✓ Node.js
✓ yarn
✓ Watchman - Used for watching changes in the filesystem when in development mode
Android
✓ JDK
✖ ANDROID_HOME
✖ Android SDK - Required for building and installing your app on Android
- Versions found: N/A
- Version supported: 28.0.3
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
Command used: npx react-native run-android
user@Devs-Mac MyReactApp % npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
/bin/sh: adb: command not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
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 748ms
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/getting-started.html#android-development-environment. 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 748ms
at makeError (/Users/user/Desktop/sa/MyReactApp/node_modules/execa/index.js:174:9)
at /Users/user/Desktop/sa/MyReactApp/node_modules/execa/index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async runOnAllDevices (/Users/user/Desktop/sa/MyReactApp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:5)
at async Command.handleAction (/Users/user/Desktop/sa/MyReactApp/node_modules/@react-native-community/cli/build/index.js:186:9)
File local.properties inside android folder of React-native project
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Apr 21 17:57:13 IST 2020
sdk.dir=/Users/user/Library/Android/sdk
Command: react-native info Environment Information
user@Devs-Mac MyReactApp % react-native info
info Fetching system and libraries information...
System:
OS: macOS 10.15.4
CPU: (8) x64 Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
Memory: 8.14 GB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 13.13.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK: Not Found
IDEs:
Android Studio: 3.6 AI-192.7142.36.36.6308749
Xcode: 11.4/11E146 - /usr/bin/xcodebuild
Languages:
Java: 14.0.1 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.2 => 0.62.2
npmGlobalPackages:
*react-native*: Not Found
Even ran brew cask install android-sdk Just to make it work Logs Below
user@Devs-Mac ~ % brew cask install android-sdk
Updating Homebrew...
==> Caveats
You can control android sdk packages via the sdkmanager command.
You may want to add to your profile:
'export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"'
android-sdk requires Java 8. You can install it with:
brew cask install homebrew/cask-versions/adoptopenjdk8
==> Downloading https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'android-sdk'.
==> Installing Cask android-sdk
==> Linking Binary 'android' to '/usr/local/bin/android'.
==> Linking Binary 'archquery' to '/usr/local/bin/archquery'.
==> Linking Binary 'avdmanager' to '/usr/local/bin/avdmanager'.
==> Linking Binary 'jobb' to '/usr/local/bin/jobb'.
==> Linking Binary 'lint' to '/usr/local/bin/lint'.
==> Linking Binary 'monkeyrunner' to '/usr/local/bin/monkeyrunner'.
==> Linking Binary 'screenshot2' to '/usr/local/bin/screenshot2'.
==> Linking Binary 'sdkmanager' to '/usr/local/bin/sdkmanager'.
==> Linking Binary 'uiautomatorviewer' to '/usr/local/bin/uiautomatorviewer'.
==> Linking Binary 'emulator' to '/usr/local/bin/emulator'.
==> Linking Binary 'emulator-check' to '/usr/local/bin/emulator-check'.
==> Linking Binary 'mksdcard' to '/usr/local/bin/mksdcard'.
==> Linking Binary 'monitor' to '/usr/local/bin/monitor'.
🍺 android-sdk was successfully installed!
Issue Still same
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 30
@RockinGarg i hope it helps you
1、open a terminal 2、
touch ~/.bash_profile
3、open ~/.bash_profile
4、write5、source ~/.bash_profile(if it doesn’t work,next) 6、change
"android": "react-native run-android"
to"android": "source ~/.bash_profile&&react-native run-android"
, and runyarn android
This is happening for me too. It was all working fine yesterday, I could run my RN app on both iOS and Android. Today however, I’m getting this error from Android when using
npx react-native run-android
:Doing
npx react-native doctor
gives:I followed the installation instructions to the T, and it was all working correctly yesterday. That suggests to me there’s something up with the environment variables but I can’t work out what it is. Here’s my
.bash_profile
:Running
source ~/.bash_profile && npx react-native doctor
gives the same output as above.Hi I used Android Studio to manually install Build on Android Emulator then manually launch the App by running server.
I am still unable to use react-native run-android (Doesn’t Work) whereas react-native run-is (Works Perfect)
Update: running this appears to fix the issue. No idea why.
Hi,
Shell: 5.7.1 - /bin/zsh Your shell is zsh, not bash. Therefore you need to source your .bash_profile in zshrc file. Just add the line below into ~/.zshrc
source ~/.bash_profile
Then restart your terminal or source your ~/.zshrc by using the code belowsource ~/.zshrc
To check adb:adb --version
error Failed to launch emulator. Reason: No emulators found as an output of
emulator -list-avds
. Open Android Studio AVD Manager, then create an emulator if you have no emulators. If you have emulators, then wipe their data and rerunnpx react-native run-android
Hi yes you are right I am to run in android through android studio But not through CLI
Bash changes i made as suggested none worked
React-native doctor says AndroidSDK: not found But its installed
For now I used Android Studio to Build App once. But it is still issue that it doesn’t work with command Line
Setting up a
$JAVA_HOME
variable to point to the adoptopenjdk11 I installed through homebrew helped with this issue. In my case, it seemed like a past JRE/JDK installation was interfering. I can also run gradlew commands now.Would be helpful to mention adding
$JAVA_HOME
in the docs.I have the same error with you, so I launch the app in Android Studio, It work well。