江玲华
江玲华

Reputation: 1061

react-native :app:installDebug FAILED

Install APK debug to my device failed.

jianglinghuadeMacBook-Pro:hello jianglinghua$ react-native run-android
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug...
WARNING [Project: :app] Current NDK support is deprecated.  Alternative will be provided in the future.
:app:preBuild UP-TO-DATE
......
:app:assembleDebug UP-TO-DATE
:app:installDebug
Installing APK 'app-debug.apk' on 'MI NOTE LTE - 6.0.1'
Unable to install /Users/jianglinghua/Desktop/hello/android/app/build/outputs/apk/app-debug.apk
com.android.ddmlib.InstallException: Failed to establish session
    at com.android.ddmlib.Device.installPackages(Device.java:894)
    ........
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
:app:installDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Failed to establish session

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 13.945 secs

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

I look at my devices

jianglinghuadeMacBook-Pro:hello jianglinghua$ adb devices
List of devices attached
98333978    device

Upvotes: 106

Views: 356105

Answers (30)

Deepak Singh
Deepak Singh

Reputation: 1145

In my case

I just add

org.gradle.jvmargs=-Xmx4608m

enter image description here

Upvotes: 0

satywan kumar
satywan kumar

Reputation: 215

if everything was working fine and you got this error suddenly then no need to do anything just open your emulator and do wipe data. I had the same problem and fixed it by using this step.

Upvotes: 0

Mahdieh Shavandi
Mahdieh Shavandi

Reputation: 8645

On my android device, the problem was about the previous build versions of the application that I had installed on my phone before. the following steps solved my problem:

  1. removing any previous build of the application, including debugging version and signed apk version

  2. On windows: On the root directory of your project, run :


 cd android
 gradlew clean
 cd ..
 npm cache clean --force

On MacOS or Linux: On the root directory of your project, run :

 cd android
 ./gradlew clean
 cd ..
  1. reboot your android device
  2. run react-native run-android

Upvotes: 78

128
128

Reputation: 1030

After trying every answer on this thread and many others. Finally what solved it:

  1. Go to file > invalidate caches > invalidate and restart.
  2. Let the gradle and indexes rebuild fully
  3. In device manager > menu > wipe data
  4. npx react-native start --port 8084 --reset-cache
  5. npx react-native run-android
  6. Try to reapply hair that I have pulled out

Upvotes: 0

suman95
suman95

Reputation: 69

Open android studio and check the Device Manager option if you are using a physical device then connect the device. and then run again npm run android .Your app will be running. enter image description here

Upvotes: 0

Jin Zihang
Jin Zihang

Reputation: 41

I also faced this issue today, tried many methods online but none of them worked. Here is how I solved this issue:

I used Android Studio to run the app in emulator, it worked. After using npx react-native run-android to run (which failed), running using Android Studio directly also failed, and I got the error INSTALL_FAILED_INSUFFICIENT_STORAGE. This message was much more helpful than the error message from react-native. Then I assigned a bigger storage to my virtual Android phone by going to Device Manager > Device Name > Edit > Show Advanced Settings > Internal Storage. Wipe virtual device's data. Then using the react-native method can work.

1. Increase virtual device's internal storage in Android Studio
2. Wipe virtual device's data
3. Run

Upvotes: 1

Oscar Velandia
Oscar Velandia

Reputation: 1166

I solved this adding more memory to the device, I did that in this way:

  1. Open Android studio
  2. click More Actions and open Virtual Device Manager
  3. Click the pencil icon
  4. Click "Show advance settings"
  5. Increase memory in "Internal Storage option"
  6. Click "Finish"

Upvotes: 9

Yuniac
Yuniac

Reputation: 571

For me I solved it by uninstalling the already existing app from my phone first (which I was working on the day before the day I got this issue) then building again, it happened to me a few times I think that's how I solved it always.

Upvotes: 2

Hadrien Jaubert
Hadrien Jaubert

Reputation: 154

I solved this issue by deleting the current device and just creating a new one.

Upvotes: 2

shankar upadhyay
shankar upadhyay

Reputation: 941

cd android and run ./gradlew clean

After that create a new virtual device that should work

Upvotes: 5

Acid Coder
Acid Coder

Reputation: 2747

my solution is delete the android/app/build folder

Upvotes: 2

Parveen Chauhan
Parveen Chauhan

Reputation: 1496

I got the same error but the issue was I did on the USB Debugging after unable this is working for me.

enter image description here

Upvotes: 2

Android device running out of memory, may be that is the reason.

Upvotes: 4

Hai Dinh
Hai Dinh

Reputation: 1513

Step 1: Close Android Emulator.

Step 2: Open Android Virtual Device Manager and wipe data by the following image: enter image description here

Step 3: Open your terminal and type

cd android
.\gradlew clean
cd ..
npm cache clean --force

Step 4: In terminal, run:

yarn run android

Note: If you are using yarn, just run:

yarn cache clean

Upvotes: 18

Rutuja Kherde
Rutuja Kherde

Reputation: 44

In my case, It is problem of permissions or we can say that setting problem present inside developer options. I am using MI Note 10.To avoid this issue,permit some setting such as common one developer option and USB debugging as well as Install via USB,USB debugging(Security settings), Verify apps over USB.

Upvotes: 3

Sunwoo Yang
Sunwoo Yang

Reputation: 1243

For me, restarting my phone did the trick.

Upvotes: 4

Justin.Mathew
Justin.Mathew

Reputation: 481

As you add more modules to Android, there is an incredible demand placed on the Android build system, and the default memory settings will not work. To avoid OutOfMemory errors during Android builds, you should uncomment the alternate Gradle memory setting present in /android/gradle.properties:

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Upvotes: 2

Moh .S
Moh .S

Reputation: 2090

  1. Delete the app from the device.
  2. Edit the file (YourAppName -> android -> app -> build.gradle) enter the line below on the defaultConfig field

multiDexEnabled true

defaultConfig {
    multiDexEnabled true //this is the line you need to enter
    applicationId "xxxxxx"
    minSdkVersion xxxxx
    targetSdkVersion xxxxx
    versionCode xx
    versionName "xx"
}
  1. rebuild the app

Upvotes: 4

Abraham Anak Agung
Abraham Anak Agung

Reputation: 141

In my case, I manually delete the app-debug.apk file and run it again.

Upvotes: 6

anmolakhilesh
anmolakhilesh

Reputation: 1683

Since you are using Mi phone which has MIUI

try this

go to Developer options, scroll down to find 'Turn on MIUI optimization' & disable it. Your Phone will be rebooted

check now


If you are using any other android phone, which has a custom skin/UI on top of android OS, then try disabling the optimization provided by that UI and check.
(usually you can find that in 'Developer options')

Upvotes: 71

Amit Kumar Trivedi
Amit Kumar Trivedi

Reputation: 543

Just go to the Developer option in your phone and disable and again enable usb debugging. It will work.

Upvotes: 3

Jahanzeb Nawaz
Jahanzeb Nawaz

Reputation: 1228

In my case, I have set up a new app but I was getting errors, tried many possible ways and answers from github and stackoverflow. nothing worked

error enter image description here The solution for me was .. check if you already have an app with the same name is installed in android..

Delete old apps and run react-native run-android

Worked for me.

Upvotes: 74

CPJ
CPJ

Reputation: 128

In my case, I had the app downloaded from PlayStore and I was trying to debug the APK with the same name. I just uninstalled the app and debugged successfully.

Upvotes: 5

Umair Raees
Umair Raees

Reputation: 139

open avd manager click on the arrow next to the pencil icon and wipe data works for me...

Upvotes: 4

Mohsen Biglari
Mohsen Biglari

Reputation: 402

I had this issue. Mine worked on the emulator well but it didn't work on the device and the error was

app:installDebug FAILED.

If you have a different app with the same name (or package name) on the device: Rename the app or delete it from your device.

Upvotes: 30

sumukha hegde
sumukha hegde

Reputation: 85

In my case, I did not have enough space on my device to install the app, so I cleared up some space and tried again

Upvotes: 3

Hammad Hassan
Hammad Hassan

Reputation: 622

This works for me

  1. Uninstall the app from your phone
  2. cd android
  3. gradlew clean
  4. cd ..
  5. react-native run-android

Upvotes: 26

Zeeshan Ansari
Zeeshan Ansari

Reputation: 10808

Just lock and unlock the android solved my issue then

adb reverse tcp:8081 tcp:8081

Upvotes: 1

Sharthak
Sharthak

Reputation: 41

On MIUI , inside developer option by default "Install via USB" is disabled.Enable it and than it allows installing app via usb.

Upvotes: 3

Larry
Larry

Reputation: 1322

In my case (with React Native), my Android phone was unrecognized by my PC where I was running the server, which can be seen by the message:

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No online devices found.

If that is the case, as highlighted in ADB Android Device Unauthorized, make sure that in Developer Options on your phone USB Debugging is set to true, and enter the following commands in terminal or cmd to restart the Android server.

adb kill-server
adb start-server

And adb devices should list your phone as device instead of unauthorized

Upvotes: 7

Related Questions