Monday, December 3, 2012

Deploy app to Android Virtual Device

This is the easy part.  If you have been following along the previous blog posts, we now have our first Android app called "HelloGalaxy.apk" packaged as an APK file ready to install on run on our virtual Android device (AndroVM on VirtualBox).

To install this package file, which contains the app, icons and metadata, we will need to use a command  line tool called Android Debug Bridge (adb).  This tool that lets you communicate with an Android emulator instance.  If you connect your phone with a USB cable, the adb tool also allows you to connect and install apps directly onto your phone.

To get started, we will need to fire up our Android emulator with VirtualBox.  (In the previous blog post, we showed you how to install and configure AndroVM under virtual box).  When you start the AndroVM with VirtualBox, you will end up on the Android home screen and see the androVM Configuration app.



When you run the androVM Configuration appyou will see the IP address of your Android emulator instance.



Take note of the IP Address.  Now we can run the adb tool.  This command line tool is found in the .../sdk/platform-tools/ folder.

cd to the platform-tools directory and execute the adb connect command.  For Example:

cd ~/develop/adt-bundle-mac/sdk/platform-tools$

$ ./adb connect 192.168.56.101
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
connected to 192.168.56.101:5555

If successful, you will see a message similar to the above.

Now that we are connected to the device, we can install the APK file in our HelloGalaxy project's bin directory that we generated in a previous post where we showed how to "build" the package.

$ ./adb install ../../workspace/HelloGalaxy/bin/HelloGalaxy.apk 
7639 KB/s (179361 bytes in 0.022s)
pkg: /data/local/tmp/HelloGalaxy.apk
Success

If you see the success message, you should be able to see the HelloGalaxy app on the Apps Screen in the emulator.




Click on the app icon to run your first android application.



Nothing too exciting, but we have an App that is up and running.  You can uninstall the app from the emulator by going to Settings -> Apps and selecting HelloGalaxy and click on the Uninstall button.



Note: The adb tool starts up a small background daemon that communicates with the device.  To shut down the adb sever, execute:

$ ./adb kill-server

Thats it.  Now that we know the lifecycle of how to create, build and deploy an Android app, on an emulator, its time to start building something useful and then get it running on my phone.  Stay tuned...



2 comments:

  1. Does adb tool requires an active internet connection..??
    Please help

    ReplyDelete
    Replies
    1. Hi Sudipta - adb does not require an internet connection.

      Delete