adb install: connection reset by peer

I’m attempting to build an Android project and test it on my device. Usually, when I try to push the build to my device either through the Unity Build Settings menu (Build and Run option) or manually through the adb install command, I receive an error and the build fails:

adb: error: failed to copy 'C:\Users\Path\To\Project\Temp\StagingArea\Package.apk' to '/data/local/tmp/Package.apk': no response: Connection reset by peer

I also see an stdout print in the log that shows the progress ticking upward. When the connection is reset and fails to build, the final percentage is anywhere between 0% - 99%. Here is a sample:

stdout[
[  0%] /data/local/tmp/Package.apk
[  0%] /data/local/tmp/Package.apk
[  0%] /data/local/tmp/Package.apk
[  0%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  2%] /data/local/tmp/Package.apk
[  2%] /data/local/tmp/Package.apk
...
[ 41%] /data/local/tmp/Package.apk

However, by disconnecting my device from my PC or rebuilding, I can sometimes (as in, very rarely) successfully push to the device.

Has anyone else encountered this “Connection reset by peer” issue when attempting to install via adb? The error message prompts me to check my Android SDK installation, though the build process will sometimes succeed. Here is the full error message, with the stdout portion truncated:

Error building Player: CommandInvokationFailure: Unable to install APK to device. Please make sure the Android SDK is installed and is properly configured in the Editor. See the Console for more details. 
C:/Android\platform-tools\adb.exe -s "64d32755" install -r "C:\Users\Path\To\Project\Temp\StagingArea\Package.apk"

stderr[

]
stdout[
[  0%] /data/local/tmp/Package.apk
[  0%] /data/local/tmp/Package.apk
[  0%] /data/local/tmp/Package.apk
[  0%] /data/local/tmp/Package.apk
[  0%] /data/local/tmp/Package.apk
[  0%] /data/local/tmp/Package.apk
[  0%] /data/local/tmp/Package.apk
[  0%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  1%] /data/local/tmp/Package.apk
[  2%] /data/local/tmp/Package.apk
[  2%] /data/local/tmp/Package.apk
...
[ 41%] /data/local/tmp/Package.apk
adb: error: failed to copy 'C:\Users\Path\To\Project\Temp\StagingArea\Package.apk' to '/data/local/tmp/Package.apk': no response: Connection reset by peer
]

switching to a raw USB port worked for me

I have a USB hub and switching ports on the hub didn’t work
but when I switched to a raw USB port on my PC it worked again

got the USB hub to work again by disconnecting its Power and USB cables for a few seconds

so if you don’t have a USB hub i guess you could try a full power off, meaning after shut down removing all power sources for at least 30 secs

Update Android SDK work for me

My smartphone is very unstable when it comes to USB connections, so even when I’m moving files from my computer to it, the connection often resets. It’s annoying and , but the only way I found to get around this problem when building my game or profiling is to connect to my smartphone through wi-fi. You can do it easily this way:

  1. Open cmd
  2. Go to your Android SDK folder (if in Windows, type “cd C:\Users\YourUser\AppData\Local\Android\sdk\platform-tools”).
  3. Type “adb tcpip 5555” (This command is pretty tricky if the next isn’t working).
  4. Get your Smartphone’s IP and type “adb connect ip” (eg. adb connect 192.168.0.12, note your smartphone MUST be on the same local network).
  5. If it works, a message will be shown telling you are “connected to ip” and the ip:5555 will be listed when you type “adb devices”. Then, disconnect your smartphone from USB and Unity will attach to your smartphone through wifi.