Created Sun 1/5/2011
How-To for creating a "HelloWorld" sample app for Android using command line tools (rather than the eclipse ide). See the android developer site the hello-world tutorial
Install the android sdk (and add /usr/local/android-sdk-linux_x86/tools and /usr/local/android-sdk-linux_x86/platform-tools to the path). Also be sure to install ant and JDK 1.6+
Install git and the android "repo" tool (works on top of git). This information is adapted from http://source.android.com/source/downloading.html. To install repo, use curl:
bash $ curl http://android.git.kernel.org/repo > ~/bin/repo bash $ chmod 755 ~/bin/repo
Initialize the android repo. The following will init at the froyo branch:
bash $ mkdir ~/Android_WorkingCopy bash $ cd ~/Android_WorkingCopy bash $ repo init -u git://android.git.kernel.org/platform/manifest.git -b froyo
Sync the repo:
bash $ repo sync
Import gpg keys (see link above), but essentially "gpg --import somefoo.android.key"
Note 1: Be sure to create an scdard which is at least 9MB at the same time as creating the AVD - do not add one after the AVD is created)
For example, to create a simple android virtual device (AVD) for Android 1.5, execute:
bash $ android create avd --target 1 --sdcard 16M --name android_1.5_avd
The --sdcard 16M option creats a 16M scdard for use with the AVD (see note 1, above). The option '--target 1' tells android to create an AVD with API Level 3 (which is 1.5). To list the SDK-dependent targets, issue:
bash $ android list targets
id: 1 or "android-3"
Name: Android 1.5
Type: Platform
API level: 3
Revision: 4
Skins: HVGA-L, HVGA (default), HVGA-P, QVGA-P, QVGA-L
id: 2 or "Google Inc.:Google APIs:3"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 3
Description: Android + Google APIs
Based on Android 1.5 (API level 3)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: QVGA-P, HVGA (default), HVGA-L, QVGA-L, HVGA-P
id: 3 or "android-4"
[snip]
...
Create an android project with:
bash $ android create project \ --package au.com.foonix.HelloAndroid \ --activity HelloAndroid --target 1 \ --path /home/foo/Android/HelloAndroid
Then edit and compile using ant. E.g., to build a package with debug enabled:
bash $ cd /home/foo/Android/HelloAndroid bash $ ant debug
Make sure the AVD created in step 3 is known to android:
bash $ android list avd
Available Android Virtual Devices:
Name: android_1.5_avd
Path: /home/foo/.android/avd/android_1.5_avd.avd
Target: Android 1.5 (API level 3)
Skin: HVGA
Sdcard: 16M
Next, start the android device emulator with the name of the avd as identified in #3 or in previous step. The device will take some time to boot up (perhaps a minute or two).
bash $ emulator @android_1.5_avd
Then list the devices attached to the adb and note down the emulator identifier and make sure the emulated device is active:
bash $ adb devices List of devices attached emulator-5554 device
Then upload the android package (.apk). E.g.,
bash $ cd /home/foo/Android/HelloAndroid bash $ adb -s emulator-5554 install bin/HelloAndroid-debug-unaligned.apk
The installed package can be executed with by navigating to the android applications menu and double-clicking the HelloAndroid application
An application that exists on a device must be uninstalled first before the same application can be installed again.
For 2.x targets, use the android debug bridge uninstall command, providing the package name as the argument. E.g., to uninstall a package called au.com.foonix.HelloAndroid, issue the command:
bash $ adb -s emulator-5554 uninstall au.com.foonix.HelloAndroid
For older 1.x targets, uninstallation can be done using the adb shell and the rm command:
bash $ adb -s emulator-5554 shell rm data/app/au.com.foonix.HelloAndroid.apk
The Dalvik Debug Monitor Service (DDMS) is a debugging tool for the dalvik jvm used in Android. DDMS is delivered with the Android SDK in .../tools/ddms.
Fedora x86_64 will not be able to start the ddms (out of the box) because it utilises eclipse swt and the sdk is 32bit (as it's name "android-sdk-linux_x86" suggests). The Android SDK R10 packages both the 32bit and 64bit versions of the swt.jar - so the resolution is simple:
bash $ cd /usr/local/android-sdk-linux_x86/tools/lib/x86 bash $ mv swt.jar swt_x86.jar bash $ cp ../x86_64/swt.jar .
There are a number of ways to spoof data such as geo location or telephony data. One way is to use ddms and either manually enter location data by lat/long or provide a gpx file. Another option for geo location spoofing is to use the geo command (via telnet to the emulator). In the following example, a lat/long coordinate is provided to the emulator running on port 5554 via the geo command:
bash $ echo 'geo fix -121.45356 46.51119 4392te^M^]quit^M' | telnet localhost 5554
Note: ^M is ctrl+M and ^] is ctrl+]
See section on "Providing Mock Location Data" in http://developer.android.com/guide/topics/location/obtaining-user-location.html
Stuart Mooroot © 1 May 2011 foo@bund.com.au