react-native: npx react-native run-android Failing in macOS

  1. I Had Setup Android Studio installed in Mac
  2. I had installed ADB Nexus 6p (R and Android Pie)
  3. Tried Manually Running Android Emulator - Works Perfect

AVD Manager:

Nexus 6p with Android R and Android Pie

Screen Shot 2020-04-21 at 8 59 59 PM Installed SDK:

Screen Shot 2020-04-21 at 8 59 39 PM

SDK Platforms

Screen Shot 2020-04-21 at 8 59 44 PM

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

Most upvoted comments

@RockinGarg i hope it helps you

1、open a terminal 2、touch ~/.bash_profile 3、open ~/.bash_profile 4、write

export ANDROID_HOME=/Users/yourname/Library/Android/sdk
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH

5、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 run yarn android

image

image

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:

java.lang.RuntimeException: Unable to instantiate application <my identifier>.MainApplication: java.lang.ClassNotFoundException: Didn't find class "<my identifier>.MainApplication"

Doing npx react-native doctor gives:

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

Android
 ✓ 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

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:

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

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.

cd android && ./gradlew clean

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 below source ~/.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 rerun npx 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.

Hi @developius

that seems helped me with previous error now I get below log

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 990 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...

> Task :react-native-webview:compileDebugJavaWithJavac

> Task :app:compileDebugJavaWithJavac

> Task :app:stripDebugDebugSymbols
WARNING: Compatible side by side NDK version was not found. Default is 20.0.5594570.
Compatible side by side NDK version was not found. Default is 20.0.5594570.
Unable to strip the following libraries, packaging them as they are: libc++_shared.so, libc++_shared.so, libc++_shared.so, libc++_shared.so, libevent-2.1.so, libevent-2.1.so, libevent-2.1.so, libevent-2.1.so, libevent_core-2.1.so, libevent_core-2.1.so, libevent_core-2.1.so, libevent_core-2.1.so, libevent_extra-2.1.so, libevent_extra-2.1.so, libevent_extra-2.1.so, libevent_extra-2.1.so, libfb.so, libfb.so, libfb.so, libfb.so, libfbjni.so, libfbjni.so, libfbjni.so, libfbjni.so, libflipper.so, libflipper.so, libflipper.so, libflipper.so, libfolly_futures.so, libfolly_futures.so, libfolly_futures.so, libfolly_futures.so, libfolly_json.so, libfolly_json.so, libfolly_json.so, libfolly_json.so, libglog.so, libglog.so, libglog.so, libglog.so, libglog_init.so, libglog_init.so, libglog_init.so, libglog_init.so, libhermes-executor-debug.so, libhermes-executor-debug.so, libhermes-executor-debug.so, libhermes-executor-debug.so, libhermes-executor-release.so, libhermes-executor-release.so, libhermes-executor-release.so, libhermes-executor-release.so, libhermes-inspector.so, libhermes-inspector.so, libhermes-inspector.so, libhermes-inspector.so, libimagepipeline.so, libimagepipeline.so, libimagepipeline.so, libimagepipeline.so, libjsc.so, libjsc.so, libjsc.so, libjsc.so, libjscexecutor.so, libjscexecutor.so, libjscexecutor.so, libjscexecutor.so, libjsijniprofiler.so, libjsijniprofiler.so, libjsijniprofiler.so, libjsijniprofiler.so, libjsinspector.so, libjsinspector.so, libjsinspector.so, libjsinspector.so, libnative-filters.so, libnative-filters.so, libnative-filters.so, libnative-filters.so, libnative-imagetranscoder.so, libnative-imagetranscoder.so, libnative-imagetranscoder.so, libnative-imagetranscoder.so, libreactnativeblob.so, libreactnativeblob.so, libreactnativeblob.so, libreactnativeblob.so, libreactnativejni.so, libreactnativejni.so, libreactnativejni.so, libreactnativejni.so, libyoga.so, libyoga.so, libyoga.so, libyoga.so.

> Task :app:installDebug
Installing APK 'app-debug.apk' on 'Nexus_6P_Edited_API_R(AVD) - 10' for app:debug
Installed on 1 device.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 24s
47 actionable tasks: 47 executed
info Connecting to the development server...
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:1045:20)
    at Object.spawnSync (child_process.js:597:24)
    at Function.module.exports.sync (/Users/user/Desktop/sa/MyReactApp/node_modules/execa/index.js:334:30)
    at tryLaunchAppOnDevice (/Users/user/Desktop/sa/MyReactApp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/tryLaunchAppOnDevice.js:57:22)
    at /Users/user/Desktop/sa/MyReactApp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:104:39
    at Array.forEach (<anonymous>)
    at runOnAllDevices (/Users/user/Desktop/sa/MyReactApp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:102:48)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Command.handleAction (/Users/user/Desktop/sa/MyReactApp/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:186:9)

I have the same error with you, so I launch the app in Android Studio, It work well。