Wednesday, July 6, 2011

Android: How to install and uninstall an apk to Android Emulator from Ubuntu

Android emulator that is installed with the SDK does not have Android Market installed. So you can not install apps from the market. But if you can find the .apk file for the app that you are looking for you can still install it.
Recently I needed to install Zxing Barcode Scanner app to emulator so that I can use barcode scanning in my app. Zxing's website provides the apk for most recent Barcode Scanner. So I downloaded BarcodeScanner3.6.apk from project website and placed it in my Downloads folder. Then from command line I used the following command to install the apk to the emulator.
adb install ~/Downloads/BarcodeScanner3.6.apk
This installed Barcode Scanner in the emulator. Please note that this command requires a running emulator because if emulator is not running adb command can not make a connection to it.

You can also remove an installed app from emulator using adb uninstall command but this requires a little more work. To uninstall an app you need the package name for that app. If you have the source code available then you can open the AndroidManifest.xml file and see its package attribute. But if you dont have the source then you will need to do an extra step. From command line issue the following command:
adb shell
this will open a shell/terminal interface to the running emulator. Now issue the following command
cd data/app
this will change the current directory to app directory which is where the user installed apps are found. Use ls command to see all the files in this directory. In my case, as I have only installed Barcode Scanner, I see only one file i.e Removing -1.apk from the file name will give you the package name. So to uninstall this app use the follwoing command:
adb uninstall

No comments: