Tuesday, May 26, 2009

Hacking Android on Ubuntu

I have been interested in Android for some time now. Having been a Java developer in my past life, I find it to be a powerful runtime for Mobile devices.

I thought it would be interesting to see if I could run Android applications natively on Ubuntu UNR (Ubuntu Netbook Remix).

It seems like the perfect mesh of technologies. Netbook OS / Mobile Application runtime environment.

My first go at it:
I know that others have built Android for x86. After digging deeper I realized that this is not enough to make it "run" under Ubuntu. It turns out that Android uses it own version of libc and all binaries get linked against that.
This causes a problem when a libc already exists on your system.
To get around this -- I started with the not documented method of building Android against the libc of the host system.


Finally -- it compiles:
Great now I can run Android, right? Not yet. I came to find out that there are many things in the Android code that rely on specific hardware features. For example, is the device powered on? Of course it is on -- we are a computer :)


Running Dalvik VM:
The one thing that I could do was run a simple Hello World Java application
under the Dalvik VM. With the below script I was able to run Java apps compiled down to .dex files. But -- without and use of Android services.

#!/bin/sh
base=`pwd`
# configure root dir
root=$base/out/host/linux-x86/product/sim/system

export ANDROID_ROOT=$root

export ANDROID_PRODUCT_OUT=$ANDROID_ROOT

# configure bootclasspath

bootpath=$root/framework
export BOOTCLASSPATH=$bootpath/core.jar:$bootpath/ext.jar:$bootpath/framework.ja
r:$bootpath/android.policy.jar:$bootpath/services.jar:$bootpath/android.awt.jar: $bootpath/am.jar
# this is where we create the dalvik-cache directory

export ANDROID_DATA=/tmp/dalvik_$USER
mkdir -p $ANDROID_DATA/dalvik-cache
exec $root/bin/am $@




Now on to getting the runtime actually running...

2 comments:

  1. Hi,
    I am able to run Hello World application by using the method mentioned by you on Ubuntu.

    I now want to run other Android apps on ubuntu 8.4,can you please share some more information on how to get the other android apps run on ubuntu.

    Thanks for sharing...

    ReplyDelete
  2. how do you do this???? id like to know

    ReplyDelete