react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Android] Upload package to device fails

Open ghost opened this issue 11 years ago • 127 comments

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.```

ghost avatar Sep 15 '15 16:09 ghost

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

  1. cd into /android and run ./gradlew assemble**
  2. upload* app-debug.apk from android/app/build/outputs/apk/ to phone and install it (you might need to enable unknown sources)
  3. Run app, ignore the red screen, errors on the left and Unable to load JS bundle
  4. Shake device to inflate the dev menu:
    • check (true) Auto reload on JS change
    • open Debug server host for device and type your computer IP address
  5. return to your host computer and run on terminal react-native start
  6. restart the app/reload js on your phone and it's ready to go

* I use Pushbullet and it works like charm for this kind of tasks ** Optional: Enable the daemon for faster builds

ghost avatar Sep 15 '15 18:09 ghost

Do you have device debugging enabled on your phone? Do you see your device in the output of adb devices command?

kmagiera avatar Sep 15 '15 18:09 kmagiera

@kmagiera correct, I tried under adb tcpip (wifi) -> adb connect and usb and got the same error.

ghost avatar Sep 15 '15 18:09 ghost

Glad you got this to work. "Unable to upload some APKs" is a generic Gradle error, do you have spaces in your project name by chance? Google gives me: https://code.google.com/p/android/issues/detail?id=180674

mkonicek avatar Sep 15 '15 19:09 mkonicek

I'm experiencing the same issue.

Huawei P8 - Android 5.0 OS: OSX 10.10.4

Enabled usb debugging and allowing all sources. My project name does not contain any special characters or spaces.

Edit: I can confirm that the remote dev server workaround by @peduxe works though.

flipace avatar Sep 15 '15 19:09 flipace

@mkonicek nope the project name is just: rn

ghost avatar Sep 15 '15 20:09 ghost

Looks like there are two separate issues here:

  • "Unable to upload some APKs" from Gradle. This is Gradle-specific and I'd Google to find out why this is happening.
  • Getting the app to load JS from the host machine. The steps you described are very similar to the docs, looks like we should add the step to restart the app.

Do you need the step react-native start? I would expect react-native run-android to start the packager in a new window before failing in Gradle.

mkonicek avatar Sep 15 '15 22:09 mkonicek

@mkonicek It doesn't get to the point of uploading the app to my device, fails on the first step - also no new window (terminal tab?) is open during react-native run-android.

The react-native server needs to be executing before running react-native run-android?

ghost avatar Sep 15 '15 22:09 ghost

@peduxe Try entering android dir inside your project and running ./gradlew :app:installDebug from there.

kmagiera avatar Sep 15 '15 22:09 kmagiera

@kmagiera same errors.

ghost avatar Sep 15 '15 22:09 ghost

Try running it with --debug

kmagiera avatar Sep 15 '15 22:09 kmagiera

@kmagiera nothing, but now outputs much more verbose logs

ghost avatar Sep 15 '15 22:09 ghost

Do you mind posting your logs here?

kmagiera avatar Sep 15 '15 22:09 kmagiera

@kmagiera It's a bit long

ghost avatar Sep 15 '15 22:09 ghost

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.

conechan avatar Sep 16 '15 15:09 conechan

@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 run react-native start.

ghost avatar Sep 16 '15 19:09 ghost

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.

everplus avatar Sep 21 '15 05:09 everplus

@everplus yep it does work with AS, I believe it's the adb task to deploy the apk being used by react-native does not work for every device, I tested with a S5 and it worked.

ghost avatar Sep 21 '15 15:09 ghost

I have the same problem, make sure you have allocate enough SD storage for your AVD. That's works for me!

lazybios avatar Sep 24 '15 04:09 lazybios

@lazybios But i'm deploying to my own device, not the emulator :)

ghost avatar Sep 24 '15 08:09 ghost