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

Most upvoted comments

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

  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

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 :

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'  

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
    }
}

I got the same error after I call

./adb reverse tcp:8081 tcp:8081
AwesomeProject  react-native start
 ┌────────────────────────────────────────────────────────────────────────────┐
 │  Running packager on port 8081.                                            │
 │                                                                            │
 │  Keep this packager running while developing on any JS projects. Feel      │
 │  free to close this tab and run your own packager instance if you          │
 │  prefer.                                                                   │
 │                                                                            │
 │  https://github.com/facebook/react-native                                  │
 │                                                                            │
 └────────────────────────────────────────────────────────────────────────────┘
Looking for JS files in
   /Users/yejianfeng/Documents/baichebao/AwesomeProject


React packager ready.

[15:38:20] <START> Building Dependency Graph
[15:38:20] <START> Crawling File System

then I call react-native run-android

  AwesomeProject  react-native run-android
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72300Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42300Library UP-TO-DATE
:app:prepareComFacebookFrescoDrawee061Library UP-TO-DATE
:app:prepareComFacebookFrescoFbcore061Library UP-TO-DATE
:app:prepareComFacebookFrescoFresco061Library UP-TO-DATE
:app:prepareComFacebookFrescoImagepipeline061Library UP-TO-DATE
:app:prepareComFacebookFrescoImagepipelineOkhttp061Library UP-TO-DATE
:app:prepareComFacebookReactReactNative0110Library UP-TO-DATE
:app:prepareOrgWebkitAndroidJscR174650Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug UP-TO-DATE
:app:zipalignDebug UP-TO-DATE
:app:assembleDebug UP-TO-DATE
:app:installDebug
Installing APK 'app-debug.apk' on 'GEM-703L - 5.1.1'
03:40:44 E/1825629402: Error while uploading app-debug.apk : Unknown failure
Unable to install /Users/yejianfeng/Documents/baichebao/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)
    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)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
    at com.android.build.gradle.internal.tasks.InstallVariantTask.install(InstallVariantTask.groovy:119)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:226)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:219)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:208)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:589)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:572)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:310)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:90)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
    at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:50)
    at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:27)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:40)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:169)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:33)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:127)
    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: 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: 11.617 secs
Could not install the app on the device, see the error above.

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 run react-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.gradle version to 1.2.3

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

Step 2: Change react-native/gradle/wrapper/gradle-wrapper.properties to gradle-2.2-all.zip

distributionUrl=https://services.gradle.org/distributions/gradle-2.2-all.zip

Step 3: Run

./gradlew :Examples:UIExplorer:android:app:installDebug

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. screen shot 2016-10-14 at 1 30 51 pm

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

  • manually install app-debug.apk
  • run: adb reverse tcp:8081 tcp:8081
  • run: react-native start
  • open up the App: AwesomeProject from my device.

@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 devices or adb 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 pm commands manually how Gradle does it:

>> pm install-create -S [APK bytes]

sess id: [sess id]

>> pm install-write -S [APK bytes] [sess id] 0_app-debug -[stream binary APK here]

??? no idea which response would come here

>> pm install-commit [sess id]

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 android dir inside your project and running ./gradlew :app:installDebug from there.

I’m getting

error: unknown option `--deviceId'
$ node -v
v8.4.0
$ npm -v
4.6.1
$ react-native --version
react-native-cli: 2.0.1
react-native: 0.40.0

@thiagoufg thank you so much! Really works with --deviceId from adb 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 device

Changing the gradle version to 1.2.3 in android/build.gradle worked 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

image

@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.gradle

Also: npm upgrade react-native-0.12.0-rc on your rn project

Those steps worked for me.