104

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
2
  • Did you run Yarn before running the project. If yes, can you please let me know if there is any error on that.
    – Saeid
    Commented Sep 20, 2018 at 14:17
  • I forgot to replug my phone after restarting my pc, maybe some of you also forgot this.
    – Myzel394
    Commented Jun 6, 2020 at 16:10

37 Answers 37

75

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
5
  • 7
    npm cache clean --force was an extra step I needed to do in conjunction to gradlew clean, deleting the apk, and uninstalling the app on device. Commented Oct 5, 2020 at 2:04
  • 1
    this works for me because I have created a signed apk of my app. thanks again Commented May 10, 2021 at 11:20
  • 2
    @John: npm cache clean --force this code save my day
    – SAM
    Commented Mar 1, 2022 at 10:53
  • It worked for me reverting from .\gradlew to ./gradlew Commented Feb 1, 2023 at 13:20
  • npm cache clean --force seems to have fixed it for me on macbook
    – Dazzle
    Commented Jun 25, 2023 at 0:36
74

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.

3
  • This error was created for me too and I did not know the reason for it. I read your answer. I noticed that in the past, I had a release of the application installed on my mobile. I deleted it and ran the command to run the application again. The application ran properly on the device Commented Dec 30, 2021 at 7:43
  • deleting old apps and running the command works for me but why this is happening . i used macbook air before so there were no issues like this Commented Jan 5, 2022 at 5:14
  • @shailPatel I see, that means this is due to build package setting in react-native. might need to explore react-native repo with this issue. there could be more details if it is listed as an issue. Commented Jan 5, 2022 at 20:02
69

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

1
  • make sure you have already logged in xiaomi community (mi commnuity) successufly cd android ./gradlew clean cd ..
    – مصطفى
    Commented May 15, 2023 at 8:57
30

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.

1
  • Worked for me, I uninstalled the app from emulator and did npm start (in my case, will be your command in your case) and it worked
    – Dholu
    Commented Sep 7, 2023 at 18:53
26

This works for me

  1. Uninstall the app from your phone
  2. cd android
  3. gradlew clean
  4. cd ..
  5. react-native run-android
1
  • 1
    In my case the problem appears when I already have an app installed on the devices. So its important to unisntall the old app. Commented May 1, 2022 at 9:56
18

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
2
  • 1
    Thanks, It worked for me. After doing wipe data. Commented Jan 9, 2022 at 7:23
  • Today this one saved the day. But all other answers worked for me at one point in past :D.
    – Biosonic
    Commented Sep 10, 2023 at 2:00
12

I got the same problem and did some research. This problem happens a lot on Chinese android phones.

It was solved by change the gradle version to 1.2.3 in file android/build.gradle line 8

classpath 'com.android.tools.build:gradle:1.2.3'
1
  • 8
    its did not work for me, minimum 2.2 is required , I have 2.14.1 installed, i am using Micromax Q348 , its found under adb devices , running 5.1 .
    – Amit Bravo
    Commented Apr 10, 2017 at 11:41
10

If none of the above solutions works then try the following steps to cold boot the emulator

open AVD manager -> Edit device -> Show Advanced Settings -> Boot option -> select Cold Boot instead of Quick boot.

9

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"
2
  • 1
    Make sure to restart zour device in case it's already running
    – Andru
    Commented Sep 4, 2022 at 12:36
  • 1
    Really works! Although it was not obvious that this can be the reason.
    – Ann
    Commented Nov 1, 2022 at 15:24
8
  1. Go to android/build.gradle, change

    classpath 'com.android.tools.build:gradle:2.2.3' to

    classpath 'com.android.tools.build:gradle:1.2.3'

  2. Then, go to android/gradle/wrapper/gradle-wrapper.properties, change distributionURL to https://services.gradle.org/distributions/gradle-2.2-all.zip

  3. Run again.

0
7

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

1
  • This works for me. don't need to close the emulators, and just type those two commands will fix the issue Commented Jan 10, 2022 at 6:53
6

I had this problem and I removed the apk file from my android device/emulator and then run react-native run-android and run successfuly .

3
  • This worked for me as well. Opened up list of apps (in my case swipe up from bottom), held on the app, clicked on app info and finally uninstalled.
    – Natetronn
    Commented Feb 27, 2021 at 5:36
  • Also worked for me but I can imagine it won't work for everyone. Simply uninstalled from the device then tried again. Incredibly simple and quick to do so worth trying first. Commented Mar 30, 2021 at 14:30
  • It worked for me,I think you have to do that when you rename the package of the application Commented Mar 14, 2022 at 23:42
6

I also got troubles with app using gradle 2.14, though with gradle 4 it's ok. By using --deviceID flag app instals without any issue.

react-native run-android --deviceId=mydeviceid
2
  • 2
    how did you get your device id
    – Ikechukwu
    Commented Jun 29, 2019 at 5:20
  • 3
    adb devices in terminal
    – Nerius Jok
    Commented Jun 29, 2019 at 7:28
6

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

5

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.

1
  • 1
    I also had the release version of the app installed on my phone. Uninstalling it and running react-native run-android worked.
    – Se7eN
    Commented Jul 2, 2019 at 7:03
5

cd android and run ./gradlew clean

After that create a new virtual device that should work

4

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

2
  • 1
    If still didn't work out, you can create new virtual device as it worked for me. Commented Jun 22, 2021 at 8:32
  • yes creating a new virtual works, thanks @RoshanBagde Commented Oct 31, 2021 at 18:36
4
  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
4

For me, restarting my phone did the trick.

4

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

2
  • Yeah, if none of the above methods work, try to free your memory a bit Commented Aug 4, 2021 at 16:57
  • this was the issue for me, thanks.
    – Sami Ullah
    Commented Oct 12, 2022 at 9:50
3

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

0
3

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

1
  • Yeah, worked for me two times Commented Mar 19, 2022 at 7:36
3

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

3

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.

2

I had the same issue with wrong AVD settings. Probably, "Target Android 6.0" was wrong choice.

Next settings were changed to fix ":app:installDebug FAILED" issue: System Image: Marshmallow , API 23, ABI x86, Target Google API.

see the detail information about this here: RN Android Setup

2

Previously, I had installed npm and then installed yarn, and that is when I started to have problems compiling, even when creating new projects with react-native init . Uninstalling yarn, I was able to create and compile.

0
2

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
2

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

2

my solution is delete the android/app/build folder

2

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

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