ADB commandline Hanging during install (PhoneGap)

2019-02-12 09:59发布

问题:

My Phonegap app refuses to load onto my Android device (even the HellowWorld default app is refusing to load)

Everything was running just great until today. Here's my console log:

***\>adb devices
List of devices attached
4c05609b        device

***\>phonegap run --device -V android
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] compiling Android...
[phonegap] Generating config.xml from defaults for platform "android"
[phonegap] Compiling app on platform "android" via command "cmd" /c ***\platforms\android\cordova\build
[phonegap] Platform "android" compiled successfully.
[phonegap] successfully compiled Android app
[phonegap] installing app onto device
[phonegap] Generating config.xml from defaults for platform "android"
[phonegap] Running app on platform "android" via command "cmd" /c ***\platforms\android\cordova\run --device

It just sits there saying running... forever.

I have another terminal window open with adb logcat running and at some point (maybe 10-15 seconds into that last line getting printed) it stops logging. Termination of the process and subsequent calls to adb logcat result in more hanging (no logging at all)

So then I have to do a kill-server, start-server to break out of this endless hanging at which point the phonegap process terminates with:

       [error] An error occurred while running the android project.
***\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                          ^
ERROR: Failed to launch application on device: ERROR: Failed to install apk to d
evice: Error executing "adb -s 4c05609b install -r "***\platforms\android\bin\Po
ached-debug-unaligned.apk"": protocol failure

I have tried::

  • deleting my .cordova folder in C:\Users\Name
  • running the adb install directly (without phonegap)
  • deploying to an emulator (same problem)
  • unplugging / replugging the device
  • rebooting all devices
  • toggling "developer mode" on the device and revoking USB debugging privileges

I am all out of ideas!

Would greatly appreciate any tips or leads.

ADB version 1.0.31

Galaxy S3 running Android v4.3


EDIT:

Deploying to an emulator claims to complete successfully, but the app never opens and does not appear in the app list inside the emulator. So I have no way of actually testing it on the emulator either.

Would really appreciate some assistance.


EDIT 2:

After some further tinkering I've discovered my issue can be more specifically described as ADB hangs (freezes) when I attempt to talk to my device. I've determined this because adb shell, adb install, and adb push all fail the same way as described above. No error, just finite waiting.

adb logcat, adb devices, and other read functions work perfectly fine until one of the aforementioned write functions hangs in which case I need to do a adb kill-server or TASKKILL to get adb logcat working again.

Not sure if this added information helps, but there you go. The last thing I haven't yet tried is to do a factory reset on my phone as suggested by this fellow. If I can't find a solution soon I will back up my data as best I can and attempt this...

Please save me before this becomes my last option!

回答1:

In case this helps others I had a problem with similar symptoms. ADB install -r "apk path" would hang indefinitely.

I troubleshooted a myriad of things and identified that it was my USB cable length.

I have an USB extender cable as that I plug my devices into. The combined length of my device's cable and the USB extender cable caused this issue. Removing the extension cable fix the issue and eventually I replaced my USB extender cable with a shorter extension cable for the final solution.



回答2:

The issues seems to resolve itself randomly. As others suggested, an arbitrary combination of ADB kill-server, restarting the device, and re-installing SDKs seems to alleviate the problem (even if only for a couple pushes).

I still have no idea what causes this hanging and, though superstitiously believe the arbitrary combination described above fixes it, am unsure how to permanently resolve it.

To future people reading this, until a solid explanation is given my only advice is to square away an hour or so to restart / rebuild your dev environment... and make sure you buy a durable stress ball.



回答3:

Shot in the dark here, but some more things to try:

  1. Are you on a work PC or something? Make sure you have USB write permissions. Also, try different USB ports and cables. You have the latest USB driver for your devices right?
  2. Try updating the SDK tools. Or maybe something got corrupted and a re-install might do the trick.
  3. You have free space on your devices right?
  4. Unknown sources is checked on both devices?
  5. What version of Android are you targeting?


回答4:

Do try restart the device like other suggested. From my experience, kill the adb process, then run the cordova run command helps magically sometimes.



回答5:

In my case adb seemed to hang, but in fact the data transfer from Mac to emulator was really slow:

$ adb push platforms/android/build/outputs/apk/android-debug.apk /data/local/tmp/
150 KB/s (15587200 bytes in 101.223s)

It's a lot faster on USB connected real device. Don't know why...



回答6:

Had the same (original) issue (with cordova / testing on an old device) ie. hang during install.

Tried running adb install directly from cmd line ...

adb [-s <deviceID>] install <apk>

...and same issue so not cordova specific....

Opened android device monitor (ADM) ...

..sdk\tools>monitor

..and ran install from cmd line again and saw logcat message saying package was sdk 16 / device was 15...doh!

So went back to AndroidManifest.xml and changed android:minSdkVersion to 15 and all back to normal again - install worked fine.

( Issue arose because I had installed something else which had changed the minSdkVersion and then removed the something else and never reset the minSdkVersion )

So, possibly device sdk / android version is too low for your build. If not, a look at the ADM logcat output as you initiate the install from the command line might indicate what the issue is.