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!

9 comments:

  1. Thanks for your post it helps me a lot.
    But U say that
    "make sure to set the correct paths for the Android SDK, NDK and tools directories"
    How to do that cause your mozconfig is empty ...
    Thanks

    ReplyDelete
  2. Hi Harini,
    I really appreciate your hard-work in putting the procedure above. Could you please update the links, I guess those links are old now and doesn't have the relevant information.
    Fennec is still slow and unstable on Android emulator. if you know any stable version of Fennec please let me know. If possible provide me the link.
    thanks in advance

    ReplyDelete
  3. finally fixed the link!:S but didn't come across any stable build of fennec for the emulator:I

    ReplyDelete
  4. hi i am getting this error while building..
    ==========================================================
    ../../../config/./nsinstall -R -m 444 /home/vijayendra/Venkat/mozilla-central-a7346f028fd6/nsprpub/pr/include/md/ /home/vijayendra/Venkat/mozilla-central-a7346f028fd6/objdir-android/dist/include/nspr
    ../../../config/./nsinstall: cannot make symbolic link /home/vijayendra/Venkat/mozilla-central-a7346f028fd6/objdir-android/dist/include/nspr/md: File exists
    make[6]: *** [export] Error 1
    make[6]: Leaving directory `/home/vijayendra/Venkat/mozilla-central-a7346f028fd6/objdir-android/nsprpub/pr/include/md'
    make[5]: *** [export] Error 2
    make[5]: Leaving directory `/home/vijayendra/Venkat/mozilla-central-a7346f028fd6/objdir-android/nsprpub/pr/include'
    make[4]: *** [export] Error 2
    make[4]: Leaving directory `/home/vijayendra/Venkat/mozilla-central-a7346f028fd6/objdir-android/nsprpub/pr'
    make[3]: *** [export] Error 2
    make[3]: Leaving directory `/home/vijayendra/Venkat/mozilla-central-a7346f028fd6/objdir-android/nsprpub'
    make[2]: *** [tier_nspr] Error 2
    make[2]: Leaving directory `/home/vijayendra/Venkat/mozilla-central-a7346f028fd6/objdir-android'
    make[1]: *** [default] Error 2
    make[1]: Leaving directory `/home/vijayendra/Venkat/mozilla-central-a7346f028fd6/objdir-android'
    make: *** [build] Error 2
    ======================================================
    please help me out .........

    ReplyDelete
  5. Are you running make as root?

    sudo make -f client.mk

    Try deleting objdir-android folder and running make again.

    ReplyDelete
  6. Hi Harini sirisena,

    Still iam getting the same error.

    ReplyDelete
  7. Hi Harini,

    Thanks for your reply.
    I have tried with root, even though i am getting the same error. please help me to resolve this issue......

    ReplyDelete
  8. Hi Harini,

    Can u Tell me where exactly .mozconfig file has to be placed ?. Please give me the exact path.

    ReplyDelete
  9. Hi Harini,

    Can you please provide the .apk file which you generated for the android emulator?

    ReplyDelete