Tuesday, October 12, 2010

Run Fennec on the Android Emulator




I was curious about Fennec ( Mozilla's mobile browser ) but since I don't own an android phone ( not yet.. ) I couldn't try it out. I recently discovered that Fennec can be made to run on the Android emulator, and here's how..

Note: My OS is Lucid Lynx and all instructions are as per my OS.

Here's how you make a Fennec build that runs on the Android emulator:

1. Install Android SDK ( you need to have JDK 5 or 6 )

you can get the Android SDK from here : http://developer.android.com/sdk/index.html

unzip the tar ball in a suitable location
cd android-sdk-linux_x86/tools
./android

This will open up the Android SDK and AVD manager. Here you should install the SDK Platform Android 2.2, API 8 and setup a new AVD ( Android Virtual Device ) with it as the Target.

now you can run the emulator inside the tools directory with..

./emulator -avd name_of_your_avd


check http://developer.android.com/sdk/installing.html for detailed installation instructions.


2. make a Fennec build that will run on the emulator

currently available Fennec nightlies wont run on the emulator so you need to build a version that will, by using the correct build instructions in the .mozconfig file. Here's how..

- First download the Android NDK and unzip it in the same location you unzipped the SDK.
http://ftp.mozilla.org/pub/mozilla.org/mobile/source/android-ndk-r4c-0moz3.tar.bz2 

- Clone the Fennec repository inside your mozilla-central repo ( cd to mozilla code folder and run

hg clone http://hg.mozilla.org/mobile-browser mobile )

If you don't already have a mozilla-central code repository you will need to get it first and setup mozilla build requirements on your system. See https://developer.mozilla.org/En/Simple_Firefox_build).

- Create the following .mozconfig file inside your mozilla-central code directory

http://pastebin.mozilla.org/1158636

( make sure to set the correct paths for the Android SDK, NDK and tools directories)

- run sudo make -f client.mk inside your mozilla-central repo.

(Fennec took about an hour and a half to build:I)

- When build is complete cd into the newly created objdir-android folder and run sudo make package. This will create a fenneck.apk file inside the objdir-android/embedding/android folder.

-Now copy the fennec.apk file into the android-sdk-linux_x86/tools folder and run

emulator -avd name_of_your_avd -partition-size 256 -memory 512

-While the emulator is running, in a new terminal install the fennec.apk in the emulator using

android-sdk-linux_x86/tools/adb install fennec.apk

The installation will print 'Success' confirming Fennec has been installed on your emulator!