Jatin Garg
Jatin Garg

Reputation: 346

react-native run-android Fails MacOS

Complete Console Output is below

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

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

    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)

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
export ANDROID_SDK_ROOT=$ANDROID_HOME
export ANDROID_AVD_HOME=$HOME/.android/avd
alias emulator='$ANDROID_SDK_ROOT/tools/emulator'

Requested Attachments

  1. Android SDK Link From Android Studio

enter image description here

  1. SDK Tools Installed

enter image description here

  1. npx @react-native-community/cli doctor Result

enter image description here

Installed Android Emulator Nexus 6P (Android R and Pie)

New To React Native it works perfectly on iOS but it fails to launch in Android Simulator

Tried Ways

  1. npm start
  2. npx react-native run-ios
  3. npx react-native run-android

Upvotes: 6

Views: 13190

Answers (6)

Zohaib Naseer
Zohaib Naseer

Reputation: 26

Please make changes as per below to resolve this error.

Install Java SDK version: 14 or above.

JDK Download link: https://www.oracle.com/java/technologies/javase-jdk14-downloads.html

In gradle-wrapper.properties please use grade version 6.3 or above.

For e.g:distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

Upvotes: 0

rnwed_user
rnwed_user

Reputation: 1660

The error is due to the version of JDK or JDK not installed.

i think you need to solve in the section:

open the androind folder with android studio

then file-> project structure -> SDK location and in here you can change, in my case i change the version enter image description here

before that, for to know what was the error:

i realized what is the problem with this command

npx @react-native-community/cli doctor

i got these errors: enter image description here

Upvotes: 2

Malik_usman
Malik_usman

Reputation: 51

This link is the complete solution but here is a little problem if you have win32 but if you have win64 you are good to go.

 **https://www.npmjs.com/package/jetifier#do_you_need_this**

hope this answer will be useful for you feel free for any problem.

Upvotes: 0

Malik_usman
Malik_usman

Reputation: 51

your problem can be resolved just follow these steps: To jetify / convert node_modules dependencies to AndroidX Imagine you have a react-native project. One of your library dependencies converts to AndroidX., and you need to use the new version.

So now you need to convert your app to AndroidX, but many of your react-native libraries ship native Java code and have not updated. How is this done?

First, use Android Studio's refactoring tool to convert your app re: the Android developer docs npm install --save-dev jetifier npx jetify npx react-native run-android (your app should correctly compile and work) Call npx jetify run in the postinstall target of your package.json (Any time your dependencies update you have to jetify again

you can follow this link as well: https://www.npmjs.com/package/jetifier

feel free for any confusion.

Upvotes: 2

RishabhRathod
RishabhRathod

Reputation: 333

It is Probably because of JDK version as mention above. You can verify by running react native doctor

npx @react-native-community/cli doctor

Upvotes: 7

Allan Joseph
Allan Joseph

Reputation: 145

Install JDK 1.8 and setup $JAVA_HOME env variable and try to run the app again.

The error is due to lower version of JDK or JDK not installed.

Upvotes: 2

Related Questions