Category Archives: development

Testing an Android image built from source

So you just built a new android system from source and you would like to test it first in the emulator before flashing it onto your phone.  Or perhaps you would just like to know how the bleeding edge version of android straight from the source repositories looks.  Fortunately, the emulator used by android SDK is flexible enough, so you can specify what image it should use for the data, system or the other partitions — thus you can build your own flavor of android and test it in the emulator easily.

Once you have checked out the android source tree via repo (either the official one, cyanogenmod or some other mod which published its source via a manifest file) apply your changes if any (add a new component to the system, modify the framework etc).  Then just pick a build target (it can be for example full-eng, it will work with the emulator) and build it the usual way.  By default the qemu-based emulator is also built, and it will be placed to out/host/linux-x86/bin/.  When it’s done the images will be in out/target/product/(your target device name)/.  From now on I’ll assume you picked the generic target.

You will also likely need an SD card image that can mounted by the emulator.  The SDK contains a tool, mksdcard with which it’s simple enough to create one:

$ mksdcard 1024M out/target/product/generic/sdcard.img

The SDK tools/ folder should be in your $PATH for this to work.

Now the only thing left is to fire up the emulator with your newly built images:

$ ./out/host/linux-x86/bin/emulator \
-sysdir out/target/product/generic \
-kernel prebuilt/android-arm/kernel/kernel-qemu \
-data out/target/product/generic/userdata.img \
-sdcard out/target/product/generic/sdcard.img

That’s all, the emulator should start up, and if you are lucky your new android hack will come to light and work.  You can use adb to copy files to/from the emulator image, or just fire up a root shell in the emulator via adb shell and take a look what is going on.

Building cyanogenmod from source

Cyanogenmod 5.0.7 stable has just been released for the Dream, Magic, Nexus One and Droid phones.  This is a great alternative to get Android 2.1 Eclair, especially to G1 (aka Dream) owners, who are still stuck with Android 1.6 — that is likely not going to change, due to the way the flash storage of the Dream is partitioned, not leaving enough room for a full 2.1 software update.

For the brave, it is also possible to build a Cyanogen ROM from source.  However, I haven’t been able to find any complete guide how to do that, so here’s one quick recap how it can be done.

It’s recommended to use Linux for the build process.  Ubuntu 8.04 or later will do.  You need the following packages:

sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
This is for a 32-bit installation, on a 64-bit system they may have different names or you may have to install the 32-bit version from certain packages.  Ubuntu 9.10 and later doesn’t include Java5 from Sun anymore, but the Jaunty repositories can be used — just add the following lines to /etc/apt/sources.list:
deb http://us.archive.ubuntu.com/ubuntu/ jaunty multiverse
deb http://us.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse
You also need the repo tool to fetch and manage Android source repositories:
curl http://android.git.kernel.org/repo > ~/bin/repo
chmod 755 ~/bin/repo
Once all the tools above are installed you can grab the Cyanogen Eclair repository:
mkdir cm
cd cm
repo init -u git://github.com/cyanogen/android.git -b eclair-ds
repo sync
This will clone all git repositories needed for the build.  It takes some time, so relax and have a coffee or two…  You can also use this time to install the Android SDK if you haven’t done so before, since you will need adb to access your phone.  Make sure the tools folder from the unpacked SDK is in your PATH.
Once you have the repositories you’ve got to extract the proprietary HTC files from your device.  Hook your phone up to your PC via USB.  Make sure your computer can see it:
% adb devices
List of devices attached
HT851N000044    device
Then you can go ahead and fetch the files:
cd vendor/htc/dream_sapphire
./extract_files.sh
If you don’t have your phone at hand you can also download an official HTC firmware and get the necessary files from it.  Go to htc.com and get signed-dream_devphone_userdebug-img-150275.zip.  You can use unyaffs to unpack system.img after you uncompressed the zip file, and then you can copy all necessary files from the folder it was extracted into.
Then go back to your build root, set up the build environment and choose your build target:
cd ../../..
source build/envsetup.sh
lunch
If you use zsh envsetup.sh may fail, but you can simply
unsetopt NOMATCH
in your shell and you’re good to go.  You can build everything with a simple
m
If you only need the OTA-format update zip use:
TARGET_NO_RADIOIMAGE=true make otapackage
One drawback of this process is that it produces an image that barely fits onto the G1 even after repartitioning it with the Danger SPL — there won’t be enough space left for Google applications like Gmail, Market and Talk.  I haven’t been able to find any clue how “official” Cyanogenmod images are built so that it remains slim enough to make Google’s applications also fit onto the phone — the xbin folder contains a squashfs image that spares some megabytes, but it is not enough in itself.  If you install this image you have just built, the Google applications won’t fit.  Perhaps the key is some build option which optimizes for size — if you figure it out, let me know.
Happy hacking!

Email sending example

As promised, here’s a simple example on how to use the SMTP library. If the username and the password are replaced with actually existing user credentials then this code snippet can send mails via Gmail.
Continue reading