haru
haru

Reputation: 551

react-native run-android command failed, but gradlew installDebug work

I'm using react-native 0.43.3 on OSX. I tried to running app on Android and get message

react-native run-android

Scanning 568 folders for symlinks in /Users/ruci.k/project/mayacrew/supermembers/supermembers/node_modules (5ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

./gradlew installDebug gave me some errors and fixed it all. Finally build get successed and app is working on Android device.

But react-native run-android command still not work. Only ./gradlew installDebug command work.

Is there anything can I check to use react-native run-android command?

I can't understand how could it happened.

Upvotes: 45

Views: 243499

Answers (22)

mohamed mansour
mohamed mansour

Reputation: 61

as for me working on apple m1 I had to change the path to the following:

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"

just a change in the path in case it didn't work with

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"

Upvotes: 0

Okpo
Okpo

Reputation: 417

Check the error messages carefully. It will give a clue to what went wrong. In my case, after installing expo in my react-native project, the MainApplication.java got corrupted. I made a comparison with the a backup (you can check an earlier working commit), then removed the erroring lines.

After this, it worked.

Upvotes: 0

Guru
Guru

Reputation: 928

After you create your react native app ,try

sudo chmod -R 777 node-modules
sudo chmod -R 777 android 
export ANDROID_HOME=~/Library/Android/sdk

now run

react-native run-android 

Upvotes: 21

Christopher
Christopher

Reputation: 21

What worked for me is,

Uninstalling the previous installed app version on the emulator device, and running react-native run-android after.

Upvotes: 0

AddaPadda82
AddaPadda82

Reputation: 1

For me, this had to do with running low on RAM om my Mac.

in gradle.properties put -XX:MaxPermSize=4096

for example like this:

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m

After that, it runs again.

Upvotes: 0

Mina Fawzy
Mina Fawzy

Reputation: 21462

this issue come from two reasons

1- Permission issue

How to Fix it

sudo react-native run-android

Or

chmod 755 android/gradlew

2- Mismatch java version with Gradle

make sure you are using Java 8 as $JAVA_HOME environment variable

depending on which terminal you are using to run your code at

For zsh shell, export $JAVA_HOME at ~/.zshenv or ~/.zshrc.
For bash shell, export $JAVA_HOME at ~/.bash_profile or ~/.bashrc.

get installed JDK by this command

/usr/libexec/java_home -V

example for using zsh

vi  ~/.zshrc
// paste the java export inside it 
export JAVA_HOME="JDK_8_Path_from_previous command"

to save your change

:x

make sure your changes applied

source ~/.zshrc

now for testing

echo $JAVA_HOME

Upvotes: 3

Ali Yar Khan
Ali Yar Khan

Reputation: 1354

I have to perform these steps to get it running.

  • First install dos2unix
  • Run dos2unix ./gradlew inside android folder
  • then run ./gradlew clean
  • at last run react-native run-android.

Upvotes: 0

ABHISHEK PATEL
ABHISHEK PATEL

Reputation: 1

1 . you should have space in your phone
2 . developer option on
3 . USB debugging option also on
4 . check "adb devices" devices is connected or not

Upvotes: 0

Paschalidis Christos
Paschalidis Christos

Reputation: 452

cd android && sudo ./gradlew clean

This worked for me. Try it out and let me know if it helps folks

Upvotes: 12

Saksham Kumar
Saksham Kumar

Reputation: 1

So here are the three solution for this bug , from which one will most probably solve your issue :

1: Adding local.properties file in your android folder

https://stackoverflow.com/questions/32634352/react-native-android-build-failed-sdk-location-not-found

2: Try deleting .gradle file and then build (react-native run-android)

3: Might be possible that under SDK tools NDK(side by side) and CMake are not installed . Steps for the same is Android Studio which include direction for opening sdk manager

Open android folder in Android Studio Click on the SDK Manager (which is at the third position from the top left )

After opening SDK manager you have to go to SDK Tools Installation image for NDK and CMake

Under SDK Tools select NDK(side by side) and CMake and press the okay button and let the installation complete . After the close the Android Studio and react-native run-android.

Upvotes: 0

Luis Felipe Zamora
Luis Felipe Zamora

Reputation: 505

Running

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"

worked for me

Upvotes: 38

hexhad
hexhad

Reputation: 1303

  1. Go to C:\Users\ [username]
  2. Rename or delete ".gradle"
  3. Then run "react-native run-android"

Upvotes: 0

Eduardo Ceolin
Eduardo Ceolin

Reputation: 41

I had the same issue, and just opened the project in android studio, and that's all. Solved!

Upvotes: 3

fatemeh ghanbari
fatemeh ghanbari

Reputation: 11

  1. go to folder android in terminal
  2. gradlew clean
  3. run react-native run-android

Upvotes: 1

Jose Kj
Jose Kj

Reputation: 2962

Try removing android,ios folders and then do react-native upgrade then try again react-native run-android After that if you get an error like

SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

then create a file named local.properties inside the folder

android

and insert the following line sdk.dir =/path/to/Android/Sdk After this everything should be fine

Note: If you have made some changes in android/ios folder please keep its backup before removing the folders

Upvotes: 16

Zumry Mohamed
Zumry Mohamed

Reputation: 9558

Run the following command

chmod 755 android/gradlew

inside your app root folder then run

react-native run-android

Upvotes: 34

adefemi micheal
adefemi micheal

Reputation: 1

So what i did was to download this jar file from: 1: https://drive.google.com/file/d/1MHSJx-_0RHRzlrXBLAePKeWKQteke0Um/view?usp=sharing and placed it inside android/gradle/wrapper then i went back to the project directory and did npm install i then changed directory to android by doing: cd android then i ran the following commands

chmod +x ./gradlew

xattr -l ./gradlew

Now i went back to the project directory and ran react-native run-android

Upvotes: 0

Avinash Buddana
Avinash Buddana

Reputation: 49

In Ubuntu, I have used this command and it worked for me:

    sudo react-native run-android

Upvotes: 4

Sridhar Nalam
Sridhar Nalam

Reputation: 547

I have faced the same issue when I have imported the project from the GitHub.

Follow the below steps to run your react-native project in the Android device from the MAC OS

  1. Remove the 'node_modules' folder from the root project.
  2. Run the below command in the project root folder.

npm install

  1. Move to the android folder in the project root folder.

    cd android

  2. Run the following commands one after another to give permissions to gradlew file.

chmod +x ./gradlew

xattr -l ./gradlew

xattr -d com.apple.quarantine ./gradlew

  1. Now, come back to project root folder and run the project in android device.

react-native run-android

Now you can see the launched application on your connected Android device/emulator.

Upvotes: 4

pavan paraskar
pavan paraskar

Reputation: 41

Check whether your emulator is connected or not:

  1. set ANDROID_HOME path: E:\android-sdk-windows

  2. set path D:C:\Program Files\nodejs;C:\Program Files\Java\jdk1.8.0_111\bin;E:\android-sdk-windows\platform-tools

Upvotes: 2

sia
sia

Reputation: 613

You must change your build.gradle:

compileSdkVersion 28  
buildToolsVersion "28.0.2"  
minSdkVersion 16  
targetSdkVersion 27  

and add this line:

implementation "com.android.support:appcompat-v7:28.0.0"

Upvotes: 2

LemonPie
LemonPie

Reputation: 846

maybe install watchman?

https://github.com/facebook/react-native/issues/10056

Otherwise, for me I actually use 'npm start' inside of the folder. npm will know to run the right command to start react native because it's in a react native directory.

Upvotes: 0

Related Questions