error Failed to install the app. Make sure you have the Android development

created at 07-10-2021 views: 2

description

The complete error is as follows:

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

troubleshooting

The main troubleshooting points:

  1. Whether the emulator is turned on or whether it is connected to a mobile phone with USB debugging turned on
  2. JDK environment variable setting (jdk version must be 1.8)
  3. Whether to install JDK and configure globally
  4. Whether to install Android SDK, and whether to install the corresponding version in buildToolsVersion

First of all, we directly open the project in Android Studio, so that it is easy to find specific errors. Through the project compilation, it is found that the corresponding version of jDK and SDK is not configured correctly. After downloading the corresponding version, configure the global

 Android Studio

Android SDK

Take Mac OS as an example to set environment variables
Terminal input first

open -e .bash_profile 

If there is no change, you must create a new one yourself:

cd ~
touch .bash_profile

Below is my .bash_profile file (don’t forget to change the username: frank)

# Java SDK
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

# Android SDK
export ANDROID_HOME=/Users/frank/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools 
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/build-tools/29.0.2  

export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

Then enter in the terminal: (This can take effect without restarting)

source ~/.bash_profile

It should be noted that there may be settings that do not take effect after closing the terminal and reopening it. This is because
Mac will not load the ~/.bash_profile file by default after startup. Here you can add a command to the .zshrc file to load it after booting.
Execute the command in the terminal and open the .zshrc file:

open -e ~/.zshrc

Add a command to the file: source ~/.bash_profile
Then enter in the terminal: (This can take effect without restarting)

source ~/.zshrc

2. But later use the react-native run-android command to run the prompt: react-native :app:installDebug FAILED
The full text is reported as follows:

> Task :app:installDebug FAILED
29 actionable tasks: 4 executed, 25 up-to-date
Unable to install /Users/frank/Desktop/WorkProject/Recat Native/rn2/android/app/build/outputs/apk/debug/app-debug.apk
com.android.ddmlib.InstallException: Unknown failure: Security exception: You need the android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS permission to use the PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS flag
java.lang.SecurityException: You need the android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS permission to use the PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS flag

This can be solved by the following steps:

  1. Uninstall the software that needs to be run on the phone (if installed)
  2. If it is a MIUI system, enter the developer options-scroll down to find "Turn on MIUI optimization" and close it, restart the phone

Then re-run react-native run-android

Please log in to leave a comment.