Npx react native run android error

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account


Closed

iOSDevGarg opened this issue

Apr 21, 2020

· 30 comments

Comments

@iOSDevGarg

  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

@github-actions

⚠️ Missing Environment Information
ℹ️ Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.

@iOSDevGarg

⚠️ Missing Environment Information
ℹ️ Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.

Hi I have updated Question with Environment Information. It says Android SDK missing. But I have already installed it

@sunguoxing0628

@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

Tobim99, carlosalvarez91, SavageWilliam, RoohAlmahaba, Omar-He, milanumeshchalishajarwala12, ilya-raevskiy, Renan04lima, KrialY, icreatevisions, and 15 more reacted with thumbs up emoji
Tobim99, SavageWilliam, mani3710, Omar-He, ilya-raevskiy, Renan04lima, adamako, natasha08n, celalyuksel, m4tr1k, and 6 more reacted with hooray emoji
Tobim99, yoojinkimm, ubaidmoin, ilya-raevskiy, Renan04lima, Doipah, natasha08n, m4tr1k, nicholasrussellweb, lee-vathanaka, and 5 more reacted with heart emoji
dhananjay2011 reacted with rocket emoji

@jwd2a

Can confirm this bug. Started a new project last night and ran up against this. Tried again, and tried @sunguoxing0628’s suggestions, but still getting this:

image

Environment details:

  • MacOS 10.15.3
  • ZShell
  • react-native-cli: 2.0.1
  • react-native: 0.61.5
  • Android Debug Bridge version 1.0.41
  • java 14.0.1 2020-04-14
  • Gradle 6.3

And just in case the react-native info output is helpful:

System:
    OS: macOS 10.15.3
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 177.10 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v10.16.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
  IDEs:
    Android Studio: 3.6 AI-192.7142.36.36.6392135
    Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild
  npmPackages:
    react: ~16.9.0 => 16.9.0 
    react-native: ~0.61.5 => 0.61.5 
  npmGlobalPackages:
    create-react-native-app: 2.0.2
    react-native-cli: 2.0.1

edit: updated env details

@sunguoxing0628

@jwd2a
Before that, I used Android Studio to install the gradle and run the app. I don’t know if it has any impact.

@iOSDevGarg

@iOSDevGarg

For now I used Android Studio to Build App once. But it is still issue that it doesn’t work with command Line

@sunguoxing0628

my environment information.

$ source ~/.bash_profile&&react-native info

info Fetching system and libraries information...
System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 1.89 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.16.2 - /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:
      Android NDK: 21.0.6113669
  IDEs:
    Android Studio: 3.6 AI-192.7142.36.36.6392135
    Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.6 - /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

$ source ~/.bash_profile&&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

$ source ~/.bash_profile&&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...
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
Starting a Gradle Daemon (subsequent builds will be faster)

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

BUILD SUCCESSFUL in 16s
26 actionable tasks: 2 executed, 24 up-to-date
info Connecting to the development server...
info Starting the app on "emulator-5554"...
Starting: Intent { cmp=com.egos_app/.MainActivity }
✨  Done in 24.42s.

@gokhandoslu

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

@iOSDevGarg

Hi All
Attaching info again It says Android SDK: Not Found which looks like the main reason that it not letting me launch Emulator from react-native command
But I had already installed Android SDK and Android Studio Too

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: 11.32 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

@chrisglein

If I’m understanding correctly this works when running directly but not from the CLI? Did the last set of tips about your bash config help? Have you been able to get react-native doctor to run clean? Is that still giving the same failures?

@iOSDevGarg

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

@developius

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.

@developius

Update: running this appears to fix the issue. No idea why.

cd android && ./gradlew clean

@iOSDevGarg

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)

@Liqiankun

@chrisglein

@RockinGarg There were plenty of errors/warnings in that log to follow up on. Did you end up getting unblocked?

@iOSDevGarg

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)

@mylesshie

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。

@Mhde96

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)

what are you doing here for be like this
i have the same initial issues

@developius

@Mhde96 @mylesshie @RockinGarg

Your logs include a message about missing adb (/bin/sh: adb: command not found). I would suggest making sure adb is installed before trying to debug anything else. Also, react-native doctor is your friend.

@esfxra

Hello, I am experiencing a similar issue in my macOS + Android Studio setup when running react-native run-android from the command line.

The only way I can get it to work is by building the project from Android Studio. Also:

  • I tried ./gradlew clean in the ./android folder but that alone fails as well.

  • I have checked my .zshrc setup a few times. I even hardcoded $ANDROID_HOME to the path found in Android Studio’s settings.

This is occurring with the 0.63.3 release. Could someone please advise?

This is the error:

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

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

And the info from react-native info:

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
    Memory: 1.64 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.13.0 - ~/.nvm/versions/node/v14.13.0/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.13.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
    Android SDK:
      API Levels: 29
      Build Tools: 28.0.3, 29.0.2, 30.0.2
      System Images: android-29 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.6858069
    Xcode: 12.0.1/12A7300 - /usr/bin/xcodebuild
  Languages:
    Java: javac 15 - /usr/bin/javac
    Python: 3.8.3 - /Users/diegoserrano/.pyenv/shims/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.63.3 => 0.63.3 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

The result of running react-native doctor:

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

Android
 ✓ JDK
 ✓ 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:   0
Warnings: 1

@gideondev

I am facing the same issue.
Wow, this is open for a long time.

@esfxra

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.

@iOSDevGarg

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 can you share your full bash_profile or where have you set java_home variable

@esfxra

@RockinGarg I use zsh. This is my .zshrc configuration for react-native:

export JAVA_HOME_8=$(/usr/libexec/java_home -v1.8)
export JAVA_HOME_11=$(/usr/libexec/java_home -v11)
export JAVA_HOME=$JAVA_HOME_11

export ANDROID_HOME=/Users/diegoserrano/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

@campsjos

In my case I had to install Android SDK Command-line Tools (in SDK Manager > SDK Tools) in order to react-native doctor recognise Android SDK

@sakkaras

@iOSDevGarg

I would like to close this issue
It’s been long i am working on react native and found this command fails sometimes and sometimes that’s work it’s intermittent.
If app is already installed then this command works fine else it fails

If anyone think this issue is occurring feel free to open

My observation
Call
source ~./bash_profile before you run
react-native run-android command

This makes it works sometimes

@junedkhan

Update: running this appears to fix the issue. No idea why.

cd android && ./gradlew clean

Thanks @developius this has sloved my issues.

@facebook
facebook

locked as resolved and limited conversation to collaborators

Nov 17, 2021

When I first started to build Android apps with react native, I was soo frustrated with the framework and almost gave up on it. This is because anytime I tried to compile the app with npx react-native run-android I run into a lot of errors. Fixing one error after days of google searching and reading through stack overflow threads, produces a different set of errors which will then take another few days to resolve and the process repeats until you eventually give up or the app miraculously compiles. It was a nightmare.

In this article I will be showing you how to avoid all the errors I have encountered and how to avoid them or fix them in case you run across them while developing your app in react native.

1. Always read the documentation of a package or its npm repository page for how to correctly install a package

This is a common source of error when building apps with react-native. Sometimes you don’t have the time to read the step by step processes involved in installing and setting up the package to work with your application, so you rush through the installation guide and end up missing an important step required to integrate the package with the platform you are working with.

React native compiles code to a specific native platform. This means that sometime to make a package to work with a platform for example android, you have to make some changes to native code and build tools.

Lets take a popular framework for example react-native-vector-icons, which is a library that allows you to use vector icons from different vector icons toolkits all in one place including FontAwesome, Ionicons, MaterialIcons, AntDesign and so on. You install this package using:

npm install react-native-vector-icons

Enter fullscreen mode

Exit fullscreen mode

And then you can start using the library? well… not quite. If this is all you do, then be ready for some nasty errors and frustration. As you can see from https://www.npmjs.com/package/react-native-vector-icons you need to make some changes in Xcode if you are building for iOS and you also need to make some changes to files inside the android folder if you want this package to work with the android platform. Specifically for android, you have to make changes to these files:

android/app/build.gradle 
android/app/src/main/assets/fonts 
android/settings.gradle 
android/app/src/main/java/<your_android_app_package_name>/MainApplication.java

Enter fullscreen mode

Exit fullscreen mode

as specified by the link above.

The setup might be quite tedious, but strictly following the steps judiciously will save you a lot more headache down the line.

There are some packages that require you to install other packages for it to work correctly. take for example, @react-navigation/native library https://reactnavigation.org/docs/getting-started/, which requires you to install react-native-screens and react-native-safe-area-context. But on android devices, react-native-screens requires you to configure android/app/src/main/java/<your_android_app_package_name>/MainActivity.java, adding the following to the MainActivity class:

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(null);
}

Enter fullscreen mode

Exit fullscreen mode

and requires you to add an import statement at the top of this file:

import android.os.Bundle;

Enter fullscreen mode

Exit fullscreen mode

before you can start using the library in your project.

Basically, any library you install with

npm install <package-name>

Enter fullscreen mode

Exit fullscreen mode

make sure you find and follow the installation instruction for that package.

Also, if eventually you need to update a package, or maybe you are creating a new react-native app in which you decide to use a newer version of a package, make sure you check for breaking changes, and check if additional steps are required to make the new version work.

2. Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.3 (or other similar error with other Gradle versions)

Basically, what this error is trying to tell you is that this particular package does not support the Gradle version you are using for your android build. Everyone has dealt with this error at one point if you’ve use npx react-native init <Project-name> to generate a new react native application.

Why does this error happen?

This happens because react-native init is always shipping the latest version of Gradle to your android project, and third party libraries might not have support for that Gradle version, making your Gradle version incompatible with the library.

What you need to do is install a earlier version of Gradle for your project and then rebuild your app.

Step 1: install a earlier version of Gradle

To see your version of Gradle, go to the android folder of your project and type gradlew -v:

cd android
gradlew -v

Enter fullscreen mode

Exit fullscreen mode

Go to https://developer.android.com/studio/releases/gradle-plugin. Scroll down to the Update Gradle section. Here, you will see a table of Gradle version and Plugin version.

Image description

As you can see, during the time of this writing, the latest Gradle version is 7.3+ and the associating Plugin version is 7.2.

As a rule, what I normally do is pick the previous Gradle version 3 steps away from the latest version. In this case, it is Gradle version is 6.7.1+ and the associating Plugin version is 4.2.0+. You can pick the Gradle version that is most suitable for you.

Image description

Now, open android/build.gradle in a text editor. you will see something like this:

buildscript {
...
dependencies {
classpath("com.android.tools.build:gradle:7.2.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

Enter fullscreen mode

Exit fullscreen mode

classpath(«com.android.tools.build:gradle:7.2.0») is in the form classpath(«com.android.tools.build:gradle:»).

Therefore change the plugin version to the version you chose from the table above. this line will now be:

classpath("com.android.tools.build:gradle:4.2.0")

Enter fullscreen mode

Exit fullscreen mode

Open android/gradle/warpper/gradle-wrapper.properties in a text editor. You will see something similar to this:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-7.3.0-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Enter fullscreen mode

Exit fullscreen mode

We are interested in the line distributionUrl=https://services.gradle.org/distributions/gradle-7.3.0-all.zip

this line is in the form

distributionUrl=https://services.gradle.org/distributions/gradle-<gradle-version>-all.zip

Enter fullscreen mode

Exit fullscreen mode

Change the Gradle version to match the plugin version you selected. this line should then look like this when you are done:

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

Enter fullscreen mode

Exit fullscreen mode

Step 2: Rebuild the app

From your project folder, run the following command:

rm -r android/build ; rm -r android/app/src/release/res ; rm -r android/app/build/intermediates

Enter fullscreen mode

Exit fullscreen mode

All this command does is delete the previous build of the app by deleting the folders that contain them. you can delete the folders manually if you like: android/build, android/app/src/release/res, android/app/build/intermediates.

when you are done, go into the android folder and clean gradle:

cd android
gradlew clean

Enter fullscreen mode

Exit fullscreen mode

make sure you now have the Gradle version you specified:

gradlew -v

Enter fullscreen mode

Exit fullscreen mode

Go back to your root project folder and build the app:

cd..
npx react-native run-android

Enter fullscreen mode

Exit fullscreen mode

Your app should now build smoothly with all «Deprecated Gradle features were used in this build» errors now gone. If the error continues, try a more earlier Gradle version. Don’t go too far back though.

3. java.io.IOException: Could not delete path

Sometimes you see errors that looks like this this:

* What went wrong:
Execution failed for task ':@myApp/react-native-spinkit:mergeReleaseResources'.
> java.io.IOException: Could not delete path 'C:UsersMyDesktopAppnode_modules@myApp
react-native-spinkitandroidbuildintermediatesresmergedreleasedrawable-xhdpi-v4'.

Enter fullscreen mode

Exit fullscreen mode

I notice I get these types of errors when I make changes to Gradle like changing the Gradle version or changing the range of android versions I support in my android/build.gradle file. When changes that affect the current android build are made, Gradle will try to delete files from the old build and create new files. This error shows that some other program is currently accessing these files and preventing them from being deleted. Most of the time it is the Metro Bundler that is preventing these files from being deleted. So you need to rebuild without running Metro. There are two ways to do this:

  • Method 1:Clean Gradle

Run this code, making sure that Metro is not running:

cd android
gradlew clean

Enter fullscreen mode

Exit fullscreen mode

  • Method 2:Stop Metro manually

Build your app using:

npx react-native run-android

Enter fullscreen mode

Exit fullscreen mode

when the metro terminal comes up, close it.

After the app has been bundled, run npx react-native run-android again. This time, allowing Metro to run.

Your app should now be installed and run as expected.

4. Expiring Daemon because JVM(Java Virtual Machine) heap space is exhausted.

When you are building your react native android app, you might encounter the error: heap limit allocation failed. this happens when you have a lot of libraries and your app becomes larger.

This error mostly shows up when you are generating the release AAB of your android app after signing it with a release key to upload on Google Play Store.

To fix this, you will have to increase the heap memory allocation.

To do this, open the file android/gradle.properties in a text editor and add the following lines to the end:

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Enter fullscreen mode

Exit fullscreen mode

Then open the file android/app/build.gradle in a text editor. Add the following under the android task:

android {
...
  dexOptions {
    javaMaxHeapSize "4g"
  }
...
}

Enter fullscreen mode

Exit fullscreen mode

Your app should now build smoothly with no error.

These errors are the root of most errors in react-native android build fails. Fixing it will save you from a lot of errors that crop up from fragmental solutions.

If you are still having trouble with these errors as I did, or are hoping to start android app development with react native, I hope this will save you a lot of time, stress and energy better spent in doing productive work.

React Native is one of the most used JavaScript mobile frameworks today. React Native enables developers who are familiar with JavaScript and the React web framework to develop mobile applications using similar methods and principles.

As a React Native developer, you’re bound to run into some errors when developing your application. When an error is detected by the compiler when running the code, it terminates the process and displays an error message.

Error messages in React Native are very descriptive. They tell the developer what error occurred and where the error was detected. In addition, they often provide clear instructions or at least a clue on how to resolve the issue.

Some errors are inherently easier to debug than others. For example, errors that happen as a result of using the wrong syntax or accessing undefined variables or components are easier to debug than errors caused by misconfigurations or incompatible dependencies.

Regardless of the nature of the error, you’ll often need help to resolve them.

In this post, I’ll cover some common React Native errors and their solutions. Some of these errors will have different solutions depending on what causes the error in the first place. For such errors, go through the solutions one after another.

Feel free to skip to any of the following sections using the links below:

  • Failed to install the app
  • Unable to load script
  • React Native run-android command is unrecognized
  • react-native command not found
  • Unrecognized command: “link”
  • Duplicate resources

Failed to install the app

After creating a new React Native project, when attempting to run the app for the first time with the command react-native run-android, you might encounter the following error:

BUILD FAILED in 13s

error Failed to install the app. Make sure you have an Android emulator running or a device connected. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.
...

This error message says that the build process wasn’t successful and also specifies the particular command that failed. Sometimes you can get rid of the error by simply using new command prompts and restarting the virtual devices.

Oftentimes, however, the error is caused by using an incompatible Gradle version to build the app.

The Android studio build system requires the right version of Gradle to successfully build Android apps. In this case, you’ll need to upgrade the Gradle version used in your app to one that is compatible with your Android studio build system.

Follow these steps:

  1. Open your React Native application in a text editor like VS Code
  2. In the application’s root folder, navigate to android > gradle > wrapper
  3. Edit the gradle-wrapper.properties file
  4. Update the distributionUrl variable with the URL for a compatible version of Gradle
  5. Run react-native run-android again to build the app using the new version.

Here’s the full path for steps two and three:

{your-project-folder}androidgradlewrappergradle-wrapper.properties

To get the accurate version of Gradle for step four, go to Gradle’s distributions list and check for the latest -all.zip Gradle version. Then, update the distributionUrl variable as follows:

distributionUrl=https://services.gradle.org/distributions/gradle-{latest version}.zip

To learn more about Gradle and Android studio, read the Android Gradle plugin and Android Studio compatibility article.

Unable to load script

Another error that developers commonly encounter when attempting to run their React Native application is shown below:

Unable to load script. Make sure you're either running a metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.

This error is always displayed on the connected Android device. There are several causes for this error. As such, there are different solutions too.

Solution 1: Package the bundle correctly

All of your app’s JavaScript is bundled into the index.android.bundle file. If the bundle file is unavailable or not correctly packaged, you’ll get the Unable to load script error. Follow the instructions below to fix it.

Go into {your-project-folder}/android/app/src/main/ folder and check if an assets folder exists within it. If the assets folder isn’t already there, create it.

Next, directly from your root folder, run this:

cd android
./gradlew clean

Next, open a command terminal and make sure it’s pointed to your project’s root folder. If your project has just one file (i.e index.js), run the following command:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

If there are two files (i.e. index.android.js and index.ios.js) then run the following instead:

react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

Note that both are single commands.

After the bundle has been generated, run react-native run android.

To execute all the above steps at once, you can place them in the scripts section of package.json like so:

"android-script": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && react-native run-android"

The command for the above is npm run android-script.

Solution 2: Use adb reverse

If you keep getting the same error after implementing the first solution, then you need to consider other causes. Another common cause is that the port wasn’t exposed. This happens if you’re running your app on a physical device.

The adb reverse command lets you to expose a TCP port on your Android device with a TCP port on your computer. To try fixing the error, run the following command:

adb reverse tcp:8081 tcp:8081

Here you are exposing TCP port 8081 on the phone via port 8081 on your computer.

If you do not have the Android platform tools component in your Windows PATH variable, then the adb executable is found at the following path:

C:Users{your-username}AppDataLocalAndroidsdkplatform-tools

Solution 3: Add cleartext support

If the first two options don’t solve React Native’s inability to load the script, then it’s likely that the error is coming from a network communication problem.

Specifically, it’s likely that the app is inaccessible from the development server due to cleartext support being disabled, as is the case from Android 9.0 (API level 28) onwards.

To fix this, modify the AndroidManifest.xml file and add cleartext support as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>

You can find your AndroidManifest.xml file in:

{your-project-folder}/android/app/src/main/AndroidManifest.xml

Restart your application for the change to be applied.

React Native run-android command is unrecognized

Sometimes when you attempt to run your React Native app on Android, you might get the following error message on the command prompt:

Command run-android unrecognized. Did you mean to run this inside a react-native project?

The error message already hints at the most common cause of the error: you’re not running the command in a React Native folder. In this case, the solution is to simply ensure that you navigate to your application’s root folder before running the app. This is what I mean:

// After initializing a project:
react-native init AwesomeProject

// Make sure to navigate to the project folder:
cd AwesomeProject

// Before you run the app:
react-native run-android

Otherwise, if the error wasn’t a result of using the wrong folder, then it’s possible that you didn’t install the contents of the project. To do that, run:

npm install or yarn install

It’s also possible that your global installation of react-native or react-native-cli is old or broken. In this case, simply reinstall your libraries globally using one of the following commands:

npm:

npm install -g react-native && npm install -g @react-native-community/cli

Yarn:

yarn global add react-native && yarn global add @react-native-community/cli

As a note, I recommend using npx (included in npm v5.0+) to install libraries on demand.

This means that whenever you run npx react-native init <your-project-name> or any other React Native CLI command, it’ll first ask for your permission to install react-native before creating the project. This ensures that you always use the latest version at all times!

Lastly, if all of the above fails to work, you might need to upgrade your npm with the following command:

npm install [email protected] -g

Ensure that you run each of these commands using a new terminal. This is to prevent using outdated path sources in your .bashrc file.

react-native command not found

command not found: react-native is another common error in React Native. You encounter this error when attempting to run any react-native command, such as when you try to initialize a React Native project, like so:

react-native init MyProject

The command not found error has two potential causes: either you do not have the CLI installed on your local machine, or you do, but it’s not properly configured.

Both of these scenarios can be avoided by using npx for all npm executables. For example, to create a new React Native app, run it with npx as follows:

npx react-native init MyProject

This will install the latest available version of the react-native package before initializing the project.

Unrecognized command: “link”

When attempting to link assets like custom fonts or icons in a React Native project, you might get the following error on your command terminal:

error Unrecognized command "link". info Run "react-native --help" to see a list of all available commands.

This error occurs when you attempt to use the manual linking feature (i.e. react-native link and react-native link unlink commands), which have been removed in React Native 0.69 and replaced with autolinking.

To avoid this error, you’ll need to use a third-party asset linking library such as react-native-asset to link assets automatically.

First, install the library with one of the following commands:

npm install -g react-native-asset
# or if you're using yarn: 
yarn global add react-native-asset

Then create a react-native.config file at the root level of the project folder and add the below code snippet:

module.exports = {
    project: {
        ios: {},
        android: {}
    },
    "assets": [
      "./src/assets/font",
      "./src/assets/mp3",
      "./src/assets/icons"
  ]
};

Run one of the below commands to enable automatic linking and unlinking in your codebase.

npm:

npx react-native-asset

yarn:

yarn react-native-asset

Now you can use any of the specified assets in your code. For example, you can use a custom font in your stylesheet:

fontFamily: 'my-custom-font'

Duplicate resources

Another common error that you might face when attempting to generate a release APK using Generate Signed APK from Android Studio is the Duplicate Resource error:

[drawable-mdpi-v4/jumper] /Users/admin/Projects/testApp/android/app/src/main/res/drawable-mdpi/jumper.png [drawable-mdpi-v4/jumper] /Users/admin/Projects/testApp/android/app/build/generated/res/react/release/drawable-mdpi-v4/jumper.png: Error: Duplicate resources
:app:mergeReleaseResources FAILED

FAILURE: Build failed with an exception.

...

The build failure occurred because duplicated resources were found in the Android project inside the Android folder. There are various solutions for this depending on the cause.

Solution 1: Cleaning the drawable folder from the terminal

Oftentimes you can get rid of the error simply by cleaning the drawable folder from the terminal using Gradle. To do this, cd into the android folder, then run ./gradlew clean before attempting to run the app again:

react-native run android

If it fails, try the next solution.

Solution 2: Add some helper code

Most times, simply cleaning the drawable folder won’t resolve the issue. If that’s the case, then you’ll need to make a slight modification in the react.gradle file to prevent duplicate resource collisions.

Add the following helper code in the react.gradle file found in node_modules/react-native/react.gradle. The code should be placed right after the doFirst block:

doLast {
    def moveFunc = { resSuffix ->
        File originalDir = file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
        if (originalDir.exists()) {
            File destDir = file("$buildDir/../src/main/res/drawable-${resSuffix}");
            ant.move(file: originalDir, tofile: destDir);
        }
    }
    moveFunc.curry("ldpi").call()
    moveFunc.curry("mdpi").call()
    moveFunc.curry("hdpi").call()
    moveFunc.curry("xhdpi").call()
    moveFunc.curry("xxhdpi").call()
    moveFunc.curry("xxxhdpi").call()
}

This error was solved in 2018 by GitHub user echaso, who provided the code above.

Conclusion

In this article, we looked at six common errors in React Native and how each of these errors can be debugged. If the error you encountered isn’t included here, do not hesitate to check this article for possible solutions.

Anyways, thanks for reading and see you next time!

LogRocket: Instantly recreate issues in your React Native apps.

LogRocket is a React Native monitoring solution that helps you reproduce issues instantly, prioritize bugs, and understand performance in your React Native apps.

LogRocket also helps you increase conversion rates and product usage by showing you exactly how users are interacting with your app. LogRocket’s product analytics features surface the reasons why users don’t complete a particular flow or don’t adopt a new feature.

Start proactively monitoring your React Native apps — try LogRocket for free.

In this article we are going to fix this error i.e. if you are a react native developer then it’s a big possibility that you might come across this error. Let’s understand a solution that works wonders for this error. 

When does this error occur?

This error occurs when we try to run our react-native project on an emulator. For example: with the help of the following command-

npx react-native run-android 

This command starts making the processes work but then it fails when tries to launch the emulator from the android studio. Hence it fails in installing the application.  

Follow the below steps to Fix this error:

Step 1: Launch Android studio and open your project.

Step 2: Go to files and check if Invalidate Caches/Restart… option is active. If it’s not active then click on  Invalidate Caches/Restart… option.

 Step 3: Click on Invalidate and Restart.

  • After this, Your project is going to restart again on android studio. 
  • Wait until all the Gradle processes are finished. 

Step 4: Clear the cache of your emulator. To clear the cache click on AVD Manager.

Step 5: Click on the down arrow button and click WIPE Data. 

That’s all on the android studio side. For most of the users, the problem may not occur after these steps but if the problem is still not resolved then follow the below steps. 

  • Sometimes the metro bundler causes this problem while we try to run the application on the emulator. 
  • To resolve that we can start the metro bundler separately. 
  • As you would already know that npx react-native run-android does the entire task of running your application. But in this case, we are going to run the metro-bundler separately. 

Step 6: Write this command in your project directory:

npx react-native start --port 8084 --reset-cache

What does this command do? Well, it is going to reset the cache of the metro bundler and launches the metro bundler at the same time.

Now, We will be running the emulator separately. Open a new cmd(command Prompt) window and write the following command in your project directory.

npx react-native run-android 

Note: Close your all previous emulators if they are currently opened. 

Now you can see the build is successful this time. 

Всем привет.

При запуске команды npm run android
получаю ошибку :

Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

Купил ноут, пока работал только с expo, сейчас появилась необходимость запилить проект на cli. Это я к тому что возможно что то корневое не установил(то есть нет такого что раньше работало а сейчас не работает.На этом компе пытаюсь запустить cli в первый раз.)

Далее опишу что я делал и какое ответы в консоль получал.
Добавил все необходимые переменные и path (JAVA_HOME, ANDROID_HOME).

Пишу npx react-native run-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.bat app:installDebug -PreactNativeDevServerPort=8081

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ration@0.0.1 android: `react-native run-android`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ration@0.0.1 android script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:UsersnikbaAppDataRoamingnpm-cache_logs2020-08-16T14_19_16_672Z-debug.log

Пишу : $ ./gradlew.bat app:installDebug или ./gradlew clean
Получаю :

←[1A←[1m<←[0;1m-------------> 0% INITIALIZING [45ms]←[m←[38D←[1B←[1A←[0K
←[31mFAILURE: ←[39m←[31mBuild failed with an exception.←[39m

* What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

* Try:
Run with ←[1m--stacktrace←[m option to get the stack trace. Run with ←[1m--info←[m or ←[1m--debug←[m option to get more log output. Run with ←[1m--scan←[m to get full insights.       

* Get more help at ←[1mhttps://help.gradle.org←[m

←[31;1mBUILD FAILED←[0;39m in 1s
←[0K
←[1A←[1m<←[0;1m-------------> 0% WAITING←[m←[26D←[1B←[1A←[2K

Так же мне показалось странным что при выполнении команды npm i -g openjdk8
Получаю ошибку:

npm ERR! 404 Not Found - GET https://registry.npmjs.org/openjdk8 - Not found

Хотя установил jdk вручную.

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Npm python error
  • Npm publish error 403
  • Npm proxy error
  • Npm install sqlite3 error
  • Npm install package json error

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии