Google+ Badge

Thursday, June 6, 2013

Use adb to update APK on device even with emulator running

For my Android development I use the fast HAX based emulator on both my PC and Mac. I do the bulk of my testing on the emulator and push the APK to a real device maybe once a day to to make sure everything still looks good and runs as expected.

If you try adb install {yourapp}.apk it gets mad if it finds multiple devices such as a physical device and the emulator. Plus install gets annoyed if the program is already installed on the device.

You should use the following command

adb -d install -r {yourapp}.apk

The -d option tells it to find a device attached via USB. The -r tells it to upgrade which keeps all the existing app data in place which is handy if you are using SQLite databases or have settings saved such as username and login server. This command can save a lot of time and headaches as you don't have to shut down the emulator to push to a device and you don't have to lose any saved data.

If you have a lock screen enabled you will have to unlock the phone before you can push the update to it.

You can also use adb -devices to make sure it is finding the USB connected device. There are times you have to unplug and replug the USB cable to get things working.