简体   繁体   中英

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

在此处输入图像描述

  1. SDK Tools Installed

在此处输入图像描述

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

在此处输入图像描述

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

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

npx @react-native-community/cli doctor

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.

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.

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.

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在此处输入图像描述

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: 在此处输入图像描述

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 eg: distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM