Tuesday, November 27, 2012

Building "Hello Galaxy"

In the previous post, we created a new Android project called "HelloGalaxy"using the Android Developer Tools (ADT).
In this post we will build and package the project.  The final package is "HelloGalaxy.apk" file which is really just a jar file that can be installed on an Android device.  The .apk file contains all the code, metadata, icons, etc.which needs to be installed in the /system/apps folder on your Android device.

At first we will want to install and run this on a "virtual" device (i.e. an Android simulator) instead of on a real device.  Sadly the QEMU emulators that come with the ADT are too slow for my Mac.  In the next post we will show how to set up a emulator based on VirtualBox that is much faster.

At this point, we will assume you do not have any emulators configured or running.  To compile, build and generate the HelloGalaxy.apk file, simply choose Run-> Run As -> Android Application.  This will compile, build and package the HelloGalaxy.apk file.




Assuming you have not created any Android Virtual Devices yet, an error message will pop up saying no compatible targets were found, asking if you wish to add a new Android Virtual Device.  Select "No".



After selecting "No", an "Android Device Chooser" dialog pops up.  Click the "Cancel" button.



The build will succeed and the log file will indicate that the Launch was cancelled.



Even though the app did not run, the HelloGalaxy.apk file was generated in your project's bin directory.  This is the file we will install and run on a suitable Android (Virtual) Device.



The APK file is not signed with your developer private key, so you shouldn't distribute or or upload it to the market.

Another way to generate the APK file is to export an unsigned .apk from Eclipse, right-click the project in the Package Explorer and select Android Tools > Export Unsigned Application Package. Then specify the file location for the unsigned .apk.



To see the contents of the APK file, which is simply a jar file, run "jar -tvf HelloGalaxy.apk"  This will list the contents of the package.  You should see the icons, xml metadata files, etc.

In the next post we will show how to set up an Android Virtual Device using VirtualBox and install the APK file onto a virtual device and run our first Droid app.



No comments:

Post a Comment