ChatGPT解决这个技术问题 Extra ChatGPT

com.android.ddmlib.InstallException: Failed to establish session react-native

I am trying to run react-native android app in my nexus5 emulator

adb devices
List of devices attached
emulator-5554   device

started packager react-native start

running app - react-native run-android

Installing APK 'app-debug.apk' on 'reactnative(AVD) - 6.0' Unable to install examples/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 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:483)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:226)
Note that react-native run-android also starts the packager, no need to start it manually.
I resolved this issue, by simply creating a new android virtual device. Not exactly sure what was causing it.

B
Bhargav Rao

For Mi devices

for those who suffer from this, try what lironess mentions in a Github Comment

enable developer mode - In your phone, go to Settings, About phone and click on MIUI version 7 times. You’ll see a pop up which says you are a developer now. Go back to Settings, Additional settings, Developer options and enable USB Debugging. Connect your phone to your PC/Mac and on the phone authorize your computer go back to Developer options, scroll down to find Turn on MIUI optimization and disable it. Your phone will be rebooted Try it now :)


B
Badis Merabet

Try : react-native run-android --deviceId YOUR_ID.


M
Martin Konicek

adb is known to be flaky. Try:

Restarting adb with $ adb kill-server

Restarting the emulator

Using Genymotion instead of stock Google emulator.


@invariant Does Genymotion support google play services
E
Edward Tan

For your AVD emulator settings, try to make sure the "Use Host GPU" setting is checked, and relaunch the emulator and try again.


For me - I was able to get this working without Host GPU (in fact I had to turn on software rendering to get the emulator to even start, likely due to my old video card/driver). I too was getting this error but it turns out I wasn't being patient enough - it took forever for the emulator to finish coming up, once it did (ie phone showed its 'desktop') then react-native was able to install the build
m
max

In my case, I have to run this command in /sdklocation/platform-tools/

 adb kill-server

then run again and watch for install request on the phone. hope this help some one


C
Cosmitar

For those like me having this issue in the emulator, one more tip: try to free up the available storage space in the emulator. That worked for me.

So many test apps and previous developed apps installed XD


Yes, the insufficient storage was causing this error for me also. Editing the emulator and adding more memory solved the issue.
Same here, just storage on a real device was full in my case.
C
Codemaker

If your device or emulator have an application having same name with the application you are building. Just remove the old one. It will resolve the issue.


K
Khalid Ahmada

If you had already installed app on device go delete it. It's work for me


R
Rafael Tavares

Simply go to developer options and enable Install via USB below Debugging options.


T
Thanmai C

Even i had the same problem,but restarting the genymotion and running the "react-native run-android" again worked for me. Ensure genymotion is running before running the above command.


D
Daggie Blanqx - Douglas Mwangi

Probable Cause

I faced this issue recently , I had first developed an app called 'myApp' in CordovaJS where the app domain was com.myapp and had it installed (this was months before I got into react ). Then when I switched to react-native I did an app with a domain com.myapp and ran into the same problem you are in.

So I figured out that there was conflicts when it came to domain and source .

Solution :

Uninstall the app that has a similar domain as the one that you are installing eg com.example , then reboot your phone .

It worked for me , I hope it works for you too.


R
Rumesh Madushanka

01 - Uninstall the app installed in device

03- then run

adb kill-server

02 -Then run again

react-native run-android


A
Aishwarya Mundada

This issue happens to occur in Xiomi devices. In developers option, you don't have to disable MIUI optimization(disabling this won't sync your accounts) instead, enable 'USB debugging' option along with 'Install via USB' and 'USB debugging(Security settings)'. This will solve the issue :)


S
Sanakhatun Shaikh
Sometimes it may happened due to insufficient storage within emulator.Try something like below:
   1. Stop emulator
   2. Open AVD Manager -> Wipe Data
   3. Start emulator and run your project.

ß
ßãlãjî

step :1 run(kill all adb)

 adb kill-server

step 2:list all connected devices(get your emulator id)

adb devices 

step 3:(replace ID to listed id from step2)

react-native run-android --deviceId ID

Note: make sure your previous app uninstalled in your emulator or physical device


D
Dung Nguyen

In MI Devices. I solve this problem by goto Developer options -> turn on Install via USB. I hope it useful!