Mobile/Fennec/Android

From MozillaWiki
< Mobile‎ | Fennec
Revision as of 18:47, 11 August 2010 by Mbrubeck (talk | contribs) (update NDK download instructions)
Jump to navigation Jump to search

Developing Fennec for Android

This page contains developer information about Firefox for Android, part of the Fennec project.

To download Firefox for Android or learn more about it, see the main Fennec for Android page.

Current Status

  • Current bugs
  • Most things mostly working
  • Keyboard input works but needs more work
  • Audio randomly works

Download Source Code

Check out the mozilla-central Mercurial repository, and the separate mobile-browser repository in a subdirectory called "mobile":

hg clone http://hg.mozilla.org/mozilla-central
cd mozilla-central
hg clone http://hg.mozilla.org/mobile-browser mobile

Install Dependencies

Set up a build environment

Ubuntu 10.04

 sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
 sudo apt-get update
 sudo apt-get build-dep firefox
 sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts sun-java6-jdk ia32-libs
 wget http://dl.google.com/android/android-sdk_r06-linux_86.tgz
 tar xjf android-sdk_r06-linux_86.tgz
 wget http://ftp.mozilla.org/pub/mozilla.org/mobile/source/android-ndk-r4c-0moz3.tar.bz2
 tar xjf http://ftp.mozilla.org/pub/mozilla.org/mobile/source/android-ndk-r4c-0moz3.tar.bz2
 .android-sdk-linux_86/tools/android update sdk

Quickstart (Linux)

Download the SDK and NDK:

wget http://dl.google.com/android/android-sdk_r06-linux_86.tgz
wget http://ftp.mozilla.org/pub/mozilla.org/mobile/source/android-ndk-r4c-0moz3.tar.bz2

Then unpack them:

tar xvfj android-ndk-r4c-0moz3.tar.bz2
tar xvfz android-sdk_r06-linux_86.tgz

Install Java runtime and JDK:

sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts sun-java6-jdk

Ubuntu note: be sure to install the Sun or OpenJDK version of Java, gcj will not work. In Ubuntu 10.04 Sun Java was moved to the Partner repository. Open the Software Center, edit Software Sources and enable the Partner repository.

Android SDK needs to be setup manually.

  • In the SDK directory, run tools/android
  • Check Settings->Force https://... sources to be fetched using http://...
  • Click Save & Apply
  • Installed Packages->Update All...
  • Select at least the Android SDK, API level 6. Optionally you can install API levels 4 and 8.
  • Click Install, Accept, etc.

Build Fennec for Android

Full Build

Normal Firefox build, with the following mozconfig. (Put this in a file called "mozconfig" in your top-level source directory.)

# Uncomment these two lines to use objdir with client.mk
#OBJDIR=objdir-android
#mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/$OBJDIR

# Add the correct paths here:
ac_add_options --with-android-ndk="CHANGE/PATH/TO/android-ndk-r4"
ac_add_options --with-android-sdk="CHANGE/PATH/TO/android-sdk-linux_86/platforms/android-8"
ac_add_options --with-android-tools="CHANGE/PATH/TO/android-sdk-linux_86/tools"

# android options
ac_add_options --enable-application=mobile
ac_add_options --target=arm-android-eabi
ac_add_options --with-endian=little

ac_add_options --disable-tests

export MOZ_DEBUG_SYMBOLS=1

A standard build should succeed with those paths.

After that build finishes, a make -C embedding/android (in the OBJDIR if one exists) should generate a fennec.apk that's installable on an Android device using adb install fennec.apk

JS/NSPR only

In the commands below, replace these with the appropriate paths:

  • $NDK is the NDK location
  • $moz is the mozilla-droid repo checkout
  • $out is some base destination directory

First, regenerate configure in the js dir (the nspr configure is checked in):

cd $moz/js/src && autoconf2.13

Then create a nspr directory, configure nspr, and build it:

cd $out
mkdir nspr
cd nspr
$moz/nsprpub/configure \
  --target=arm-android-eabi \
  --with-android-ndk=$NDK 
make -s

Then do the same for JS, telling it where to find the NSPR you just built:

cd $out
mkdir js
cd js
$moz/js/src/configure \
  --target=arm-android-eabi \
  --with-android-ndk=$NDK \
  --with-nspr-cflags=-I$out/nspr/dist/include/nspr \
  --with-nspr-libs='-L$out/nspr/dist/lib -lnspr4 -lplc4 -lplds4' \
  --enable-threadsafe \
  --with-endian=little \
  --with-arm-kuser
make -s

More information about NSPR is on this separate page.

Run Fennec on Android

You'll need to copy the NSPR libraries and the js shell to the emulator or your device. Whether you're running on a physical device or an emulator, /data/local should be writable by the user.

cd $out/nspr/dist/lib
for f in *.so ; do adb push $f /data/local ; done
cd $out/js/shell
adb push js /data/local

Then, connect to a shell on the device, and run js (adb shell prompts prefixed with "android"):

% adb shell
android% cd /data/local
android% LD_LIBRARY_PATH=. ./js
js> 1+1
2

Debugging with GDB

Preparation

Debugging with gdbserver requires root access. If you have not rooted your phone, search the web for instructions for your particular device.

If you do not already have gdbserver on your device (use adb shell gdbserver to check), you can push a pre-built version from the NDK.

adb push /PATH/TO/android-ndk-r4/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/gdbserver /data/local

Note: Fennec might crash when attaching using the gdb binaries included in the Google NDK. In that case use the nVidia gdb binaries here

The images included with the SDK for emulation are yaffs2 images and require some work to mount and extract files from. An alternative is to just copy the necessary files from your device via adb pull. /system/bin/linker is referred to by absolute path so setting solib-absolute-prefix in gdb will be necessary for it to be found. Other files can be placed anywhere as long as they can be found in solib-search-path.

In short, find a directory to put some libraries, make sure adb is in your path, and paste this into your terminal:

adb pull /system/bin/linker . &&
adb pull /system/bin/app_process . &&
mkdir -p system/bin &&
mv linker system/bin &&
for LIB in libc.so libm.so libstdc++.so liblog.so libz.so libGLESv1_CM.so
do
adb pull /system/lib/$LIB .
done

Alternately, unpack the system image of your device somewhere. (eg. signed-dream_devphone_userdebug-ota-14721.zip)

Attach GDB

  • launch in debug mode:
 adb shell am start -a org.mozilla.gecko.DEBUG -n org.mozilla.fennec/org.mozilla.fennec.App
  • Forward a port for gdb between your device and computer using adb. Any port you can open should work. 1234 is used here.
    • (Host) adb forward tcp:1234 tcp:1234
  • Find the pid of your process if you don't know it. Every message in adb logcat specifies the PID of the process that produced the message, so gecko's PID can be found there, or you can look at the second column of adb shell ps|grep fennec.
  • Attach gdbserver to the process
    • (Device) gdbserver localhost:1234 --attach 6036
    • Use /data/local/gdbserver if gdbserver is not in your PATH.
Attached; pid = 6036
Listening on port 1234
  • Run arm-eabi-gdb on your binary. (android-ndk-1.6_r1/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin) For debugging gecko, a copy of app_process from your device should be used.
    • (Host) ~/android-ndk-1.6_r1/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-gdb app_process
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=arm-elf-linux"...
  • Configure solib-absolute-prefix. This will point to the directory where you unpacked your system image or where you copied the libraries.
    • (Host gdb) set solib-absolute-prefix /home/user/android/sysimg
  • Configure solib-search-path. This needs to point to the directories you need debugging symbols from - /system/lib or where ever you copied the libraries.
    • (Host gdb) set solib-search-path /home/user/android/sysimg/system/lib:/home/user/android/moz-build/dist/bin
  • Connect to gdbserver
    • (Host gdb) target remote localhost:1234
  • These three Host gdb commands can be placed in a .gdbinit file to automate future gdb runs. .gdbinit should be located where you normally run gdb.

You can use the script below to setup gdbserver with a single command:

#!/bin/sh
PORT=1234
adb forward tcp:$PORT tcp:$PORT &&
adb shell am start -a org.mozilla.gecko.DEBUG -n org.mozilla.fennec/org.mozilla.fennec.App &&
PID=`adb shell ps|grep org.mozilla.fennec|cut -c11-16` && sleep 3 &&
adb shell /data/local/gdbserver localhost:$PORT --attach $PID

Profiling

oprofile is enabled in the kernel on the G1 dev phone and SDK emulator images. The oprofile programs (opcontrol, oprofiled) are in /system/xbin.

Android Development Tips

  • You can build a full Android OS from source following the instructions on Cyanogen's site. This helps tremendously with debugging.
  • You might want to change the emulator options to give it enough space to install and run Fennec: emulator -partition-size 256 -memory 512
  • Pass command line arguments to Fennec as "extras" using the -es argument: adb shell am start -n org.mozilla.fennec/org.mozilla.fennec.App -es -safe-mode

Nightly builds are available unsigned, so that you can sign them with your local debug key and install them on top of your own debug builds (without uninstalling and losing your profile). To sign and install the unsigned nightly build:

wget http://ftp.mozilla.org/pub/mozilla.org/mobile/nightly/latest-mozilla-central-android-r7/gecko-unsigned-unaligned.apk
jarsigner -keystore ~/.android/debug.keystore -storepass android -keypass android gecko-unsigned-unaligned.apk androiddebugkey
zipalign -f -v 4 gecko-unsigned-unaligned.apk gecko-signed-aligned.apk
adb install -r gecko-signed-aligned.apk

Other Resources