Generating binaries

[article] [edit page] [discussion] [history]

From Humanitarian-FOSS Project Development Site



Since android doesn't use the Sun JVM, using some of the more familiar tools will be out of hand when you need to compile your files for distribution. Android uses the .apk files for distribution. Think of them as the ubiquitous .sis files that are used in symbian phones for installing applications.

How to generate the apk files

Using the IDE's compiled file

There are basically two methods to do this. One is to use the file automatically compiled by your IDE in your <project folder>/bin In my case, it's the <eclipse-workspace>/posit/hfoss-posit/hfoss-posit.apk

Go to step three if you decide you don't really want to package it using the second method.

Right click on the project folder, and select Android Tools at the very bottom. There's a "export application package." It will export the apk file for you.

Using aapt

The other way is to use the aapt tool provided by google android in the <android-installation-directory>/tools directory.

A nifty trick here that I use is to make an alias for this tool so that I don't need to keep putting the whole location. 
Alternatively, you can add the directory to your $PATH variable and you get all the tools. Of course, remember to add them 
to your ~/.bashrc file.

The command

  • Go to the project folder
$cd /the/folder/

  • Run the aapt with the following command
$aapt p -M AndroidManifest.xml -I org.hfoss.posit -S res/ posit.apk
(Please remember to replace the org.hfoss.posit with your own base package name and posit.apk with the apk name you want to generate)

How to load the executable to the phone

  • Run the emulator with the emulator command unless it's already running
  • Install file
$adb install posit.apk

This saves the file into the /Data/ folder in the android device.

How to clean Android#Clean /Data/

How to Run the file

Running can be a bit tricky, especially if you haven't added access to the activity launcher by adding this to your AndroidManifest.xml file

<category android:name="android.intent.category.LAUNCHER" />


<activity android:name=".Activity" android:label="@string/app_name">

I recommend adding this provision of loading the file from the launcher. Helps loads. However, it's a nice feature to have some option for loading file from the command line itself. You need to use the am command to do this The syntax goes like this

am [start|instrument]
am start [-a <action>] [-d ] [-t <mime_type>]
[-c <category> [-c <category>] ...]
[-e <extra_key> <extra_value> [-e <extra_key> <extra_value> ...]
[-n <component>] [-D] [<uri>]
am instrument [-e <arg_name> <arg_value>] [-p <prof_file>]
[-w] <component>

Here it goes:

  • Enter the shell
$adb shell
#am start -n org.hfoss.posit/org.hfoss.posit.PositMain

As you can see that I'm running using the base package name and the full Activity name. Post here if you find any different/better ways.

Personal tools