Android on Ubuntu 10.04
From Crashcourse Wiki
[edit] Overview
As with most things I play with, a running commentary on what it took to get this up and working on Ubuntu 10.04 -- definitely a work in progress. And since this is meant to be a newbie-level recipe, I'm going to restrict myself to the most recently-released version of Android: 2.2 or "Froyo." If you want to work with older versions, just adjust the recipe accordingly.
Send any thoughts, comments, feedback, large bags of cash to rpjday@crashcourse.ca.
[edit] The relevant Android web pages
A collection of the links I found the most useful as a starting point.
Top-level pages:
SDK pages:
- [Android 2.2 platform].
- [SDK download page].
- [SDK installation page].
- [SDK system requirements page].
- [Ubuntu-specific SDK issues].
Emulator and virtual device pages:
- [Emulator].
- [Virtual devices].
[edit] Downloading and installing the SDK
Get the tarball [here], and install it wherever you want under your (non-root) home directory. In addition, it's probably worth adding the tools/ subdirectory to your search path, if you plan on making use of utilities like android or emulator on a regular basis.
That tarball isn't very large as it contains only the basic Android tools. You'll still have to install at least one version of the Android platform (2.2, 2.1, etc...) to get anything done. Keep reading.
[edit] Ubuntu packages
If you haven't already, you'll need:
$ sudo apt-get install openjdk-6-jdk ant
There's some debate over whether you can use Java 6 for Android 2.2, but it seems to work for me. I suspect this issue isn't closed yet and I'll update this as the situation changes.
[edit] Adding SDK components
This is where you select the Android platform you want to run. Initially, you have no targets or virtual devices:
$ android list Available Android targets: Available Android Virtual Devices: $
So load yourself up with, say, Android 2.2 and all of the associated docs and samples (four packages should be installed if you select all the 2.2-related stuff):
$ android update sdk
after which you should be able to see the difference:
$ android list
Available Android targets:
id: 1 or "android-8"
Name: Android 2.2
Type: Platform
API level: 8
Revision: 1
Skins: QVGA, HVGA (default), WQVGA400, WVGA800, WQVGA432, WVGA854
id: 2 or "Google Inc.:Google APIs:8"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 2.2 (API level 8)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WVGA854, WQVGA400, HVGA (default), WQVGA432, WVGA800, QVGA
Available Android Virtual Devices:
$
[edit] Creating an Android virtual device (AVD)
Initially, you have no AVDs:
$ android list avds $
Just follow the directions [here] to create your first AVD. In a nutshell, run:
$ android
and build one. There's currently a bug (already identified and fixed in development) that rejects trying to select an SD card of 2G or larger, so just pick a smaller size for your SD card.
Once you're done, verify successful AVD creation with:
$ android list avds
If you're interested, all of your AVD information is typically stored in the ~/.android directory and corresponding subdirectories.
[edit] Running your first Android virtual device
Trivially, run your very first AVD using the SDK's Qemu-based emulator with either of:
$ emulator -avd <avdname> $ emulator @<avdname>
Depending on your processor horsepower, give it time. In addition, you can start the emulator with a number of accompanying debugging options, such as:
- -shell: Create a root shell console on the current terminal.
- -show-kernel: Show kernel messages during boot.
In the meantime, go read more about the emulator [here].
[edit] Building your first (Hello, World) app
You can read all about what it takes to build your first simple app [here] -- the ubiquitous "Hello, world" app. But since I prefer to avoid Eclipse for now, here's the condensed version of how to do this on the command line. First, create the project skeleton with some variation of this:
$ android create project \
-t 1 \ # for me, target of "android-8"
-n Hello \ # project name of "Hello"
-p ~/android/projs/hello \ # location for my projects
-a HelloActivity \ # activity name
-k ca.crashcourse.android # my chosen namespace
Once that's done, cd to the appropriate directory and replace the contents of the HelloActivity.java file with your variation of the following:
package ca.crashcourse.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, rpjday");
setContentView(tv);
}
}
Then simply run:
$ ant debug
and if all goes well, you'll end up with an installable package file with a name like bin/Hello-debug.apk.
[edit] Installing your new application
A detailed discussion of how to install an application using the Android Debug Bridge ("adb") can be found [here], so making a long story short, make sure your emulator is running and verify that adb can see it with:
$ adb devices List of devices attached emulator-5554 device $
At that point, it's simple:
$ adb install Hello-debug.apk
Once you verify that the app shows up and runs in your emulator, you can remove it following the instructions [here].
[edit] Outstanding issues
Lots of things to cover yet:
- Debugging.
- Setting up Eclipse.
and on and on.
[edit] Building Android in its entirety
If you want to build all of the current checkout of Android from scratch, the official page is [here], but that page admits that a build on 64-bit Ubuntu is not extensively tested, and even less so for Ubuntu 10.04. So here's what appears to work. (And by "what appears to work," I mean simply that the build finished. Quality assurance is still a bit of a mystery but I'm working on it.)
[edit] Install the repo utility
You'll need to install the git-related repo utility. Ignore the erroneous curl command on that page and use this one that works (note the critical -o option):
$ sudo curl http://android.git.kernel.org/repo -o /usr/local/bin/repo
or install it wherever it will end up on your search path. Movin' on ...
[edit] Install the essential Ubuntu 10.04 packages
That same page has an alleged list of required packages for Ubuntu, but the list needs to be tweaked for 10.04 as some of the package names have changed (for example, lib32z-dev is now lib32z1-dev, minor fixes like that). Here's what I needed to install on top of what was already on my system
$ sudo apt-get install gcc-multilib g++-multilib zlib1g-dev lib32z1-dev lib32ncurses5-dev gperf
Note that I did not install sun-java5-jdk -- more on that in the next section.
If I overlooked anything in my list of required packages, you'll almost certainly be told about it during the build.
[edit] Getting all the Android source
You'll be downloading at least a couple gig for the source so find a suitable location and:
$ mkdir myrepocheckout $ cd myrepocheckout $ repo init -u git://android.git.kernel.org/platform/manifest.git
Go for lunch. Come back.
$ repo sync
Again, go away for a while. And when you come back, you should have something like this as your directory contents:
$ ls bionic cts device hardware ndk sdk bootable dalvik external libcore packages system build development frameworks Makefile prebuilt vendor $
And now, to build. Almost.
[edit] Building with Java 6
Assuming you've installed Ubuntu 10.04's openjdk-6-jdk package, you can override the normal build restriction of Java 5 by editing the file build/core/main.mk and changing the Java version test to match against "1.6" instead of "1.5". Scroll through the file, you'll see what I mean (you'll need to do it in two places, once for java and once for javac). I have no more elegant fix for that.
Finally:
$ make
Once more, go away. Come back when it's done. Any questions? Send feedback or corrections to rpjday@crashcourse.ca.
[edit] Miscellaneous
The official Android page also suggests that you need to create the symlink:
$ sudo ln -s /usr/lib32/libX11.so.6 /usr/lib32/libX11.so
That link appears to already exist so I clearly didn't bother with it.

