Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 892
江玲华 Avatar asked May 28 '16 14:05

江玲华


13 Answers

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

like image 151
anmolakhilesh Avatar answered Sep 21 '22 01:09

anmolakhilesh


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.

like image 30
Jahanzeb Nawaz Avatar answered Sep 22 '22 01:09

Jahanzeb Nawaz


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: On the root directory of your project, run :

 <code>cd android</code>
 <code>./gradlew clean</code>
 <code>cd .. </code>
  1. reboot your android device
  2. run react-native run-android
like image 41
Mahdieh Shavandi Avatar answered Sep 21 '22 01:09

Mahdieh Shavandi


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.

like image 39
Mohsen Biglari Avatar answered Sep 25 '22 01:09

Mohsen Biglari


This works for me

  1. Uninstall the app from your phone
  2. cd android
  3. gradlew clean
  4. cd ..
  5. react-native run-android
like image 28
Hammad Hassan Avatar answered Sep 23 '22 01:09

Hammad Hassan


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'
like image 45
Dubbo Avatar answered Sep 25 '22 01:09

Dubbo


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
like image 37
Hai Dinh Avatar answered Sep 21 '22 01:09

Hai Dinh


  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.

like image 22
Ikhwanul Muslimin Avatar answered Sep 23 '22 01:09

Ikhwanul Muslimin


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.

like image 25
CodeZombie Avatar answered Sep 22 '22 01:09

CodeZombie


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

like image 45
Larry Avatar answered Sep 25 '22 01:09

Larry


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 .

like image 31
Hamed Damirchi Avatar answered Sep 23 '22 01:09

Hamed Damirchi


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
like image 6
Nerius Jok Avatar answered Sep 24 '22 01:09

Nerius Jok


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.

like image 5
CPJ Avatar answered Sep 22 '22 01:09

CPJ