If you want to start to develop applications for Android you need to install the Android SDK. The installation instructions advise you to install Eclipse and to add the Android Development Tools (ADT) plugin. Not everybody is a fan of this dinosaur-like IDE and luckily it is not really needed. The plugin is just a wrapper for some tools that you can use in the command line, too. Here I will give you a description about how to setup an Eclipse-free, lightweight and transparent developing environment in Ubuntu GNU/Linux and how to use some to the SDK tools.
$ dpkg -l | egrep "jdk|ant1" | cut -c -30 ii ant1.8 ii ant1.8-optional ii default-jdk ii openjdk-6-jdk ii openjdk-6-jre ii openjdk-6-jre-headless ii openjdk-6-jre-lib
If anything is missing fill the gap. Then choose a suitable version of the Android SDK and download it:
$ wget http://dl.google.com/android/android-sdk_r06-linux_86.tgz
Unpack the downloaded file and move the resulting folder to location that you prefer for this purpose:
$ tar xfz android-sdk_r06-linux_86.tgz $ mv android-sdk-linux_86 /opt/
Let’s have a quick look into our new tool box.
$ ls /opt/android-sdk-linux_86/tools/ adb dmtracedump hierarchyviewer mksdcard traceview android draw9patch hprof-conv NOTICE.txt zipalign apkbuilder emulator layoutopt source.properties ddms etc1tool lib sqlite3
To make these tool available without their full path we add their folders path to the PATH environment variable in our .bashrc, .profilerc or a similar file:
if [ -d "/opt/android-sdk-linux_86/tools/" ] ; then PATH="/opt/android-sdk-linux_86/tools/:$PATH" fi
The first program will use it the AVD Manager that we launch via the SDK. We need it to install further components e.g. the Android platform 2.1 files.
$ android Starting Android SDK and AVD Manager No command line parameters provided, launching UI. See 'android --help' for operations from the command line.
… starts a gui:
… and there we can choose the component to install. We add the package 7 with Android 2.1.
After this we have even more tools:
$ /opt/android-sdk-linux_86/platforms/android-7/tools/ aapt aidl dexdump dx lib NOTICE.txt
Having all our tools at hand we now create our first project
$ android create project \ --name ARockingApp \ --target 1 \ --path ./a_rocking_app \ --package com.android.arockingapp \ --activity ARockingApp
What does this command create?
$ find a_rocking_app/ a_rocking_app/ a_rocking_app/build.xml a_rocking_app/local.properties a_rocking_app/build.properties a_rocking_app/default.properties a_rocking_app/src a_rocking_app/src/com a_rocking_app/src/com/android a_rocking_app/src/com/android/arockingapp a_rocking_app/src/com/android/arockingapp/ARockingApp.java a_rocking_app/AndroidManifest.xml a_rocking_app/bin a_rocking_app/libs a_rocking_app/res a_rocking_app/res/layout a_rocking_app/res/layout/main.xml a_rocking_app/res/drawable-mdpi a_rocking_app/res/drawable-mdpi/icon.png a_rocking_app/res/values a_rocking_app/res/values/strings.xml a_rocking_app/res/drawable-hdpi a_rocking_app/res/drawable-hdpi/icon.png a_rocking_app/res/drawable-ldpi a_rocking_app/res/drawable-ldpi/icon.png
This is the basic scaffold of an Android app and without any changes we can build the app using ant (actually you don’t have to use ant but run dx & Co. manually). Use the option debug to sign the app (and maybe read some background about signing apps).
$ ant debug Buildfile: /home/kuf/jo/a_rocking_app/build.xml [...] BUILD SUCCESSFUL Total time: 6 seconds
This should give us the following application files:
$ find . -name "*apk" ./bin/ARockingApp-debug-unaligned.apk ./bin/ARockingApp-debug.apk
To run the app we create a new virtual device by using the SDK. Call android and click on “New” under “Virtual devices”. Give the device a name and select a target platform. Click on the newly created device and then on “Start”. Depending on your hosting system it might take a while until the emulator shows a proper home screen.
To get a list of running device use adb (Android Debug Bridge) with the option devices.
$ adb devices List of devices attached emulator-5554 device
Now we know to which device we can install our new app to. As we have only one the option “-s” is not really needed but I add it here to show its usage:
$ adb -s emulator-5554 install bin/ARockingApp-debug.apk 205 KB/s (13207 bytes in 0.062s) pkg: /data/local/tmp/ARockingApp-debug.apk Success
The emulator shows an icon of the app.
If you click on this icon the app starts. As we haven’t changed anything in the source code after creating the app project we should see the default welcoming text.
Now you can fire up your favorite text editor and hack your first proper application!