react-native: [Android] Upload package to device fails
I’m trying to build the default example but it fails uploading the package to my device (Android 5.0):
Exceptions thrown while deploying.
command: react-native run-android
OS: Linux 15.04 64-bits
Log:
: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: Unable to upload some APKs
* 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: 20.863 secs
Could not install the app on the device, see the error above.```
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 21
- Comments: 127 (17 by maintainers)
Commits related to this issue
- change settings to install apk on device see https://github.com/facebook/react-native/issues/2720 — committed to builderscon/session-timer by januswel 8 years ago
I had to type: adb kill-server adb connect 192.168.0.14:5555
Wait a moment then run:
adb devices
This will show you the DEVICE_ID (which i’m gonna call XYZ) of your device running android. It is usually its IP adress followed by the port 5555 (usually, not always).
react-native run-android --deviceId XYZ
The important part was the --deviceId XYZ. Without this, the apk would never get uploaded to the phone.
Then, the app launched with a red screen… i had to shake it, dev settings, adjust the “debug server host & port for device”, putting my computer’s IP address and port, like this:
192.168.0.15:8081
Lastly, i had to shake my phone again and select REALOD…
it worked for me!
So I managed to enable the remote dev server via wi-fi and got everything to work generating a debug apk.
It works for now.
Steps (for those who are interested):
cdinto /android and run./gradlew assemble**app-debug.apkfromandroid/app/build/outputs/apk/to phone and install it (you might need to enable unknown sources)Unable to load JS bundleAuto reload on JS changeDebug server host for deviceand type your computer IP addressreact-native start* I use Pushbullet and it works like charm for this kind of tasks ** Optional: Enable the daemon for faster builds
as @peduxe mentioned, after I downgrade my gradle plugin from: 1.3.1 to 1.2.3, everything just works.
my-project/android/build.gradle :
I got the same error after I call
then I call react-native run-android
I tried gradle 1.2.3, not working.
Then tried
adb install android/app/build/outputs/apk/app-debug.apk, success.@conechan you can connect with adb reverse, no need to set the host machine.
Make sure your device is connected via USB and run
adb reverse tcp:8081 tcp:8081, then runreact-native start.Same issue in MI 4a. but found the solution: Step1: go settings -> developer option -> close MIUI optimization Step2: gradle 1.3.0 to 1.2.3
I can deploy it by using the gradle plugin version: 1.2.3 and below
Met the same issue.
Device: MEIZU m2 note - Android 5.1 OS: OSX 10.10.5
BTW, the workaround provided by @peduxe is also worked for me.
The same application can run on my Nexus 7 (Android 5.1) without issues.
For react-native Examples:
Step 1: Change
react-native/build.gradleversion to1.2.3Step 2: Change
react-native/gradle/wrapper/gradle-wrapper.propertiestogradle-2.2-all.zipStep 3: Run
Have fun
In my case, the most likely cause to the problem was gradle version 1.3.1 which seems buggy. Switching from gradle version 1.3.1 to 1.2.3 in android/build.gradle fixed the issue for me.
Changing the version of com.android.tools.build:gradle to 1.5.0 worked for me.
same here using Xiomi Redmi Note 2:
~/Projects/AwesomeProject$ react-native run-android Starting JS server… Building and installing the app on the device (cd android && ./gradlew installDebug)… … :app:installDebug Installing APK ‘app-debug.apk’ on ‘Redmi Note 2 - 5.0.2’ 02:24:04 E/1771561989: Error while uploading app-debug.apk : Unknown failure Unable to install /Users/wharsojo/Projects/AwesomeProject/android/app/build/outputs/apk/app-debug.apk com.android.ddmlib.InstallException: Unable to upload some APKs at com.android.ddmlib.Device.installPackages(Device.java:920) …
solved with @peduxe workaround: https://github.com/facebook/react-native/issues/2720#issuecomment-140860192
@conechan, @everplus, @flipace
So I just downgraded this classpath from the gradle build files,
from 1.3.0 (there’s also a newer version: 1.3.1 but it doesn’t work as well) to 1.2.0 and successfully it pushed the apk to my device and started the activity, although there’s a new error.
Prolly worth a look now:
classpath 'com.android.tools.build:gradle:1.2.0'I also met this problem.
:app:installDebug Installing APK ‘app-debug.apk’ on ‘Redmi Note 2 - 5.0.2’ 01:19:19 E/1160857647: Error while uploading app-debug.apk : Unknown failure Unable to install /Users/everplus/Documents/Project/CtripFxReactNative/android/app/build/outputs/apk/app-debug.apk com.android.ddmlib.InstallException: Unable to upload some APKs at com.android.ddmlib.Device.installPackages(Device.java:920) at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:113) at com.android.builder.testing.ConnectedDevice$installPackages$0.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
I try to use android studio with project, and that’s ok.
@olojiang “Failed to establish session”, it is likely the building process failed to communicate with your device via adb. Did you try
adb devicesoradb install android/app/build/outputs/apk/app-debug.apk?Platform: Win 7 x64
I had the same issue trying to deploy to my device “'Redmi Note 2 - 5.0.2”. Downgrading Gradle to 1.2.3 also worked for me. I also tried Gradle 1.5.0 but that did not work either.
I think we could find out more by running the
pmcommands manually how Gradle does it:And see if anything does fail.
restarting adb helps me resolve this issue
I had the same error too, with a virtual device. I got around it by deleting a couple of my apps that were installed on the device, including the previous version of the react native app that I was trying to test. Once I did that the error went away.
@peduxe Try entering
androiddir inside your project and running./gradlew :app:installDebugfrom there.I’m getting
@thiagoufg thank you so much! Really works with
--deviceIdfromadb devices, without gradle version fix.Same here, fixed with 1.2.3 in
android/build.gradle, but it works with the lasted with other devices, so I think this is related somehow in the android version running at the target deviceChanging the gradle version to 1.2.3 in
android/build.gradleworked for me too.I created a project in react native
my android\build.gradle has classpath ‘com.android.tools.build:gradle:2.0.0’
when i am running command
react-native run-android apk generated but not uploaded on the connected device
but when i am running command adb install -r ./android/app/build/outputs/apk/app-debug.apk apk uploaded and working fine
also when i change my android\build.gradle classpath ‘com.android.tools.build:gradle:2.0.0’ to ‘com.android.tools.build:gradle:1.2.3’ react-native run-android works fine for me but some plugin are not working
Yep downgrade to 1.2.0 the gradle and you will be fine
@jiyinyiyong May be need ‘开发版’ not ‘稳定版’
The step described by @cablegunmaster is working for me,
I downgraded graddle to 1.2.3 in build.gradle after that 1 terminal open with: $ adb reverse tcp:8081 tcp:8081 //startup server. $ react-native start
//open new terminal Ctrl + Alt + T in ubuntu go to project folder $ react-native run-android
@denghongcai You should have something like this:
<project-name>/android/app/build.gradle<project-name>/android/build.gradleAlso:
npm upgrade react-native-0.12.0-rcon your rn projectThose steps worked for me.