Android: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
Line 217: Line 217:


oprofile is enabled in the kernel on the G1 dev phone and SDK emulator images. The oprofile programs (opcontrol, oprofiled) are in /system/xbin.
oprofile is enabled in the kernel on the G1 dev phone and SDK emulator images. The oprofile programs (opcontrol, oprofiled) are in /system/xbin.
= Device-Specific Information =
== Nexus One ==
* You can build a full Android OS from source [http://wiki.cyanogenmod.com/index.php/Building_from_source following the instructions on Cyanogen's site].  This helps tremendously with debugging.
== Droid ==
* You can build a full Android OS from source [http://wiki.cyanogenmod.com/index.php/Building_from_source following the instructions on Cyanogen's site].  This helps tremendously with debugging.


= Other Resources =
= Other Resources =

Revision as of 23:29, 25 March 2010

Android

Central location for information about the Android port of Gecko.

Current Status

Getting Source Code

Currently, the source lives in a user hg repo:

http://hg.mozilla.org/users/vladimir_mozilla.com/mozilla-droid

Work is being done on the "android" branch, so be sure to use:

hg update -C android

to switch to it before building.

Building

Prerequisites

Quickstart (Linux)

Download the SDK and NDK:

wget http://dl.google.com/android/android-sdk_r05-linux_86.tgz
wget http://dl.google.com/android/ndk/android-ndk-r3-linux-x86.zip

Then unpack them:

unzip android-ndk-r3-linux-x86.zip
tar xvfz android-sdk_r05-linux_86.tgz

Ubuntu note: be sure to install the sun version of java, gcj will not work

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

The 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. Optinally you can install API levels 4 and 7.
  • Click Install, Accept, etc.

Building

Full Build

Normal Firefox build, with the following mozconfig. If building fennec, clone the mobile-browser repo as 'mobile' in the toplevel mozilla dir. Make sure you set the paths to the NDK/SDK appropriately.

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

ac_add_options --enable-application=browser
# For Fennec use this instead:
#ac_add_options --enable-application=mobile

ac_add_options --disable-ogg
ac_add_options --disable-wave

ac_add_options --with-arm-kuser

# Global options
ac_add_options --enable-debug
ac_add_options --disable-optimize
# libxul is required
ac_add_options --enable-libxul

# mobile options
ac_add_options --disable-installer
ac_add_options --disable-crashreporter
ac_add_options --disable-printing
ac_add_options --disable-javaxpcom

# android options
ac_add_options --target=arm-android-eabi

ac_add_options --with-android-ndk="CHANGE/PATH/TO/android-ndk-r3"
ac_add_options --with-android-sdk="CHANGE/PATH/TO/android-sdk-linux_86/platforms/android-6"
ac_add_options --with-android-tools="CHANGE/PATH/TO/android-sdk-linux_86/tools"
ac_add_options --with-endian=little
ac_add_options --enable-tree-freetype
ac_add_options --enable-faststripe
ac_add_options --disable-dbm
ac_add_options --disable-ctypes

# other options
ac_add_options --disable-necko-wifi
ac_add_options --disable-plugins

# ssltunnel can't build because the ndk doesn't have string, vector, or algorithm headers
ac_add_options --disable-tests

A standard build should succeed with those paths.

After that build finishes, a make -C embedding/android should generate a gecko.apk that's installable on an Android device using adb install gecko.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.

Running

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

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 . &&
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

  • 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.
  • Attach gdbserver to the process
    • (Device) gdbserver localhost:1234 --attach 6036
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.

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.

Device-Specific Information

Nexus One

Droid

Other Resources