84

Would you please help me, I am stuck to create a new project in react-native Like below screenshot. I have able to run old projects. but I am not able to run a new project

I have followed these steps:

  1. react-native init projectName
  2. cd projectName
  3. react-native run-projectName

But I get the error below:

error Failed to install the app. Make sure you have the Android development environment set up:

Screenshot

1

34 Answers 34

131

I was receiving this error message when running react-native run-android.

When I ran cd android && ./gradlew clean I was getting permission errors also.

I ran chmod +x gradlew and it started working

3
  • 11
    When I try to run ./gradlew clean after going in the android folder I get the following error: FAILURE: Build failed with an exception. * What went wrong: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper Sep 10, 2020 at 11:32
  • 1
    This worked for me. As a matter of knowledge, I'm using Ubuntu 20.04.2 and the React Native version is 0.62.2 (it's an old app I ressurrected). Thanks Dylan w Apr 11, 2021 at 13:35
  • i am getting this error env: sh\r: No such file or directory while running ./gradlew clean Nov 9, 2021 at 7:28
61

To make sure your environment is setup properly for android, go to the root of your react-native project. Open the android project(folder) in the Android Studio IDE.

All errors with your environment will show up, and that will automatically start the Gradle Daemon to sync and configure the build for you. Once it finished, close the Android Studio and come back to command-line and run: react-native run-android

This works fine.

1
  • came here to say exactly this. Ultimately if you've got issues with your android development environment setup, Android Studio should make it a whole lot easier to identify what those issues are. Literally just finished doing a successful deploy from Android Studio and now subsequent deployments are (finally) working correctly again.
    – Marc
    Jan 5, 2023 at 11:47
21

Run the following command

cd .\android\ 
./gradlew clean

Then in the root of your project:

npx react-native start --reset-cache

NOTE

Make sure that the app does not exist on your phone, if so, first try to remove it then run your project again

0
19

This command chmod +x gradlew work for me in mac.

0
10

Just do $:cd android and then $: gradlew clean worked for me on Windows

1
  • 5
    This didn't fix the issue but in order to run the clean command I typed ./gradlew clean in the android sub-folder.
    – klaevv
    Jan 2, 2020 at 13:16
9

Hi I fixed this issue by wipe data of the emulator. Go to android studio -> then open AVD Manager -> Click the triangle icon of the emulator. -> then click Wipe data.

after that run react-native run-android . This fixed my issue. enter image description here

1
  • 1
    This was the only solution that worked for me. ./gradlew clean on its own did not work Jan 2, 2022 at 1:40
7

Fix for macOS | React Native | Android

This issue is because of permission missing, I solved this issue in macOS by using following steps.

Change directory to android using following command is vs code

cd android

add the x permission which is the symbol for the execute permission for the gradlew using following command is vs code

 chmod +x gradlew

Clean ./gradlew using

./gradlew clean

Go back to project root folder by

cd ..

Run android build using [after npm start]

npm run android
6

Open ~/.bash_profile and add:

 export ANDROID_HOME=~/Library/Android/sdk/

 export PATH=$PATH:~/android-sdks/platform-tools/

 export PATH=$PATH:~/android-sdks/tools/

source ~/.bash_profile

5

Make sure the Android SDK is connected correctly to the terminal shell as described in the docs. This solved the problem on my machine after generating a bare workflow expo project.

https://reactnative.dev/docs/environment-setup

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
4

This command worked for me -

cd android
chmod +x gradlew
3

Edit:

According to the updated questions, with screenshots comment below, seems like your problem is related to this other post from years ago.

The solution I could provide for you is to find your gradle*.zip file, delete it, and re-run the command. That way, the command would try downloading the gradle again. And this time, please make sure your connection is stable during the command run process, as the command will re-download the gradle zip again.

For reasons of the solution I provided, according to the link, it is caused by your connection is unstable and the gradle zip downloaded during the process is corrupted.

Previous Answer:

Do you have Android Studio installed on your computer?

Have you tried running the command again after you started an Android emulator device from Android Studio?

The command you mentioned AFAIK, does not try to run any emulator for you, and you need to run an emulator yourself to test your app.

Also you need to have Android SDK installed to run a react-native android-app. It does not comes with react-native, but it does comes with Android Studio.

So, maybe you should start there!

3
  • Thanks for your comment and sorry for the late response, I have tried above all step still not working. but old projects is working perfectly in emulators. Would you please share your new solution for the same Jul 16, 2019 at 14:51
  • @prafulargiddi I updated my answer above. Please try following the link in my updated answers. Jul 19, 2019 at 4:49
  • 1
    there is no 'gradle.zip' file in android folder for ma Nov 11, 2019 at 6:35
3

You can do this :

Open Android Studio > Configure > AVD Manager > Stop virtual device

Finally :

npx react-native run-android 

This works for me.

3

This error usually happens when you're running an app that you've never run before on your computer. A simple way of solving this issue is that:

  1. Open and run your app on Android Studio
  2. Let it build everything in the Gradle.
  3. Once it's done, close Android Studio
  4. Open your App back on Visual Studio Code and it will work just fine.
2

In my case, I was getting this error only when I try to run it on my physical device. Activating Install via USB from Developer Options fixed the problem.

2

THIS WORKED IN UBUNTU

use the below code to open the editor

sudo gedit ~/.bashrc

And then paste the following lines in the last (Make sure to specify path names according to you system paths)

export BASE_DIR="/home/sid"
export ANDROID_SDK=$BASE_DIR/Sdk
export ANDROID_PATH=$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools
export ANDROID_HOME=$BASE_DIR/Sdk
export FLUTTER=$BASE_DIR/developement/flutter/bin
export PATH=$PATH:$BASE_DIR:$ANDROID_PATH:$ANDROID_HOME:$FLUTTER
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/emulator


JAVA_HOME="/home/sid/android-studio/jre"
PATH="$PATH:$HOME/bin:$JAVA_HOME/bin"
export JAVA_HOME
export JRE_HOME
export PATH

And finally run the following code in terminal to make changes

source ~/.bashrc
1
  • Did you mean BASE_DIR="/home/'username'/Android"
    – ambassallo
    Oct 11, 2020 at 10:57
1

I too stumbled into this problem today. It happens when you take project form other users. Hence the ndk and sdk path are of the other user. So make sure the ndk and sdk path are correctly mentioned inside your local.properties file.

1
  1. ..\..\android\.gradle open your project's gradle directory
  2. There is gradle version directory. Delete it and download the new version from https://services.gradle.org/distributions/
  3. Then paste the new version to your directory.

Open vscode and go android → gradle/wrapper → gradle-wrapper.properties and after the new gradle version has been downloaded, we have to change

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

to

distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip
1

For me what worked was setting up adb reverse, then clearing the development server cache.

Step 1:

Follow this link and set up adb reverse.

Step 2: Run this to clear development server cache:

npx react-native start --reset-cache

Finally: Run this to bundle android file and install debug apk on your device:

npx react-native run-android
1

In my case I had ANDROID_HOME environment variable set correctly ... but the error has more details saying:

Unable to make field private final java.lang.String java.io.File.path accessible

Which means I installed the wrong version of Java JDK which is JDK 17 which is not supported by the time of this answer...

Downgrading Java JDK to Java JDK 11 resolved the issue

0
npx --quiet react-native config or npx.cmd --quiet react-native config

This works for me.

0

For me the problem was that the res folder under android/app/src/res was deleted so i can make an apk. Then the project was pushed on git with the deleted file. I solved the problem by adding the res file again to the project.

0

In windows solve it with the attrib command. The gradle directory may require write permissions.

proyect> cd android (enter)
proyect/android> attrib -r gradle (enter)
0

I also had below error

Task :react-native-charts-wrapper:mergeDebugJniLibFolders FAILED

and fixed it by adding below change in android/build.gradle:

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.google.android.gms'
                && details.requested.name.contains('play-services-gcm')) {
                details.useVersion '16.0.0'
            }
        }
    }
}
0

This worked for me on Windows 10

cd android && chmod +x gradlew

If you are getting an error saying **'chmod' is not recognized as an internal or external command** then you need to install Git

Download and install git.

Then

  • Got to the C drive In Program Files folder, you will find the folder named Git, find usr then bin.

  • In my case, the location for bin folder was:

    • C:\Program Files\Git\usr\bin
  • Add this location C:\Program Files\Git\usr\bin to path variables, in system environment variables.

  • Restart cmd.

Finally Try again

cd android && chmod +x gradlew

Good Luck

0

A workaround for this is basically just run the app on your physical device using wi-fi connection.

1 - Open your cmd;

2 - > adb tcpip 5555;

3 - With your device IP, run the following command: adb connect deviceIp;

(In case you don't know how to find your device's ip´: https://help.simpletelly.com/article/329-how-to-find-your-android-device-ip-address )

0

Make sure your dependencies are updated to support your react-native version (for me it was react-native-navigation when I updated to RN65).

0

In January 2022, I had this same issue. I am using a Windows 11 machine running AMD Ryzen 3. All the steps given above failed me. The only solution that worked for me was turning off my Avast anti-virus and running npx react-native run-android again.

The antivirus has a ransomware shield that was preventing certain actions, so when I checked the error logs and found areas where Access Denied was the issue, I figured it could be my antivirus.

Another way I could have solved this would be to move the project folder to a different directory other than my Desktop (which is a protected directory) or change the protection settings from my Avast ransomware settings so that Desktop would no longer be a protected directory.

0

Make sure you have Java JDK installed - for Ubuntu 20.04 - sudo apt install openjdk-11-jdk fixed it for me

0

In my case, I have already installed an app with the same identifier, i.e. com.appname. So first, I remove it from the device.

Don't forget to do a ./gradlew clean

0

In my case, it occurred after I added to android/app/src/main/res/raw a sound with the name in camelCase. When I changed it to cebab_case, it all worked fine again.

Not the answer you're looking for? Browse other questions tagged or ask your own question.