'Facing issue " Failed to install the app. Make sure you have the Android development environment " in react native

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



Solution 1:[1]

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

Solution 2:[2]

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.

Solution 3:[3]

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

Solution 4:[4]

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

Solution 5:[5]

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

Solution 6:[6]

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

Solution 7:[7]

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

Solution 8:[8]

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

Solution 9:[9]

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!

Solution 10:[10]

You can do this :

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

Finally :

npx react-native run-android 

This works for me.

Solution 11:[11]

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.

Solution 12:[12]

This command worked for me -

cd android
chmod +x gradlew

Solution 13:[13]

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.

Solution 14:[14]

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.

Solution 15:[15]

  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

Solution 16:[16]

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

Solution 17:[17]

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

Solution 18:[18]

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.

Solution 19:[19]

If you have expo installed on your project then run expo start --android instead of npm run android. This is how i got my app to run.

Solution 20:[20]

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

This works for me.

Solution 21:[21]

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)

Solution 22:[22]

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'
            }
        }
    }
}

Solution 23:[23]

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

Solution 24:[24]

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 )

Solution 25:[25]

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

Solution 26:[26]

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

Solution 27:[27]

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.

Solution 28:[28]

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

Solution 29:[29]

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

Solution 30:[30]

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.