Android: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(→‎Prerequisites: Add SDK as a prereq now that widgets backend for Android is up)
 
(30 intermediate revisions by 6 users not shown)
Line 1: Line 1:
= Android =
#redirect [[Mobile/Fennec/Android]]
 
Central location for information about the Android port of Gecko.
 
== Current Status ==
 
* Full tree builds
** NSS support requires patches to NDK headers
* JS builds and shell runs
* xpcshell builds and runs
 
== Getting Source Code ==
 
Currently, the source lives in a user hg repo:
 
http://hg.mozilla.org/users/vladimir_mozilla.com/mozilla-droid
 
== Building ==
 
=== Prerequisites ===
 
* Standard [https://developer.mozilla.org/En/Linux_Build_Prerequisites Linux build environment], at least as far as tools like gnu make, gcc, and autoconf2.13 go
* [http://developer.android.com/sdk/ndk/1.6_r1/index.html Android 1.6 NDK]
* [http://developer.android.com/sdk/ Android SDK]
 
The NDK is the only Android-specific prereq for building, though you will probably want the [http://developer.android.com/sdk/ Android SDK] for an emulator and tools such as 'adb'.  Either 2.0 or 1.6 will do.
 
==== Quickstart (Linux) ====
Just paste these commands into your terminal to download and install the NDK and SDK.
 
# get SDK and NDK
wget http://dl.google.com/android/android-sdk_r04-linux_86.tgz &&
wget http://dl.google.com/android/ndk/android-ndk-1.6_r1-linux-x86.zip &&
# unpack SDK and NDK
unzip android-ndk-1.6_r1-linux-x86.zip &&
tar xvfz android-sdk_r04-linux_86.tgz &&
# setup NDK
cd android-ndk-1.6_r1 &&
build/host-setup.sh &&
cd ..
 
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...
* You may uncheck everything you don't need. Just installing the latest 1.x and 2.x SDKs is fine.
* Click Install Accepted
 
=== Building ===
 
==== Fix headers ====
 
Certain header files in the NDK do not compile as C++. Paste this command in your terminal while in the NDK directory to patch them.
 
patch -p1 << "EOF"
--- tmp/android-ndk-1.6_r1/build/platforms/android-4/arch-arm/usr/include/asm-generic/siginfo.h  2009-07-28 17:26:01.000000000 -0700
+++ android-ndk-1.6_r1/build/platforms/android-4/arch-arm/usr/include/asm-generic/siginfo.h      2009-12-09 11:48:46.000000000 -0800
@@ -55,7 +55,7 @@
  struct {
  timer_t _tid;
  int _overrun;
- char _pad[sizeof( __ARCH_SI_UID_T) - sizeof(int)];
+ //char _pad[sizeof( __ARCH_SI_UID_T) - sizeof(int)];
  sigval_t _sigval;
  int _sys_private;
  } _timer;
--- tmp/android-ndk-1.6_r1/build/platforms/android-4/arch-arm/usr/include/dlfcn.h 2009-07-28 17:26:01.000000000 -0700
+++ android-ndk-1.6_r1/build/platforms/android-4/arch-arm/usr/include/dlfcn.h    2009-12-09 11:51:20.000000000 -0800
@@ -42,7 +42,7 @@
    RTLD_LAZY = 1,
    RTLD_LOCAL  = 0,
-  RTLD_GLOBAL = 2,
+  RTLD_GLOBAL = 2
  };
  #define RTLD_DEFAULT  ((void*) 0xffffffff)
EOF
 
==== Full Build ====
 
Normal build, with the following mozconfig:
 
ac_add_options --enable-application=browser
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
# 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="$PWD/../android-ndk-1.6_r1"
ac_add_options --with-endian=little
ac_add_options --enable-tree-freetype
# other options
ac_add_options --disable-necko-wifi
ac_add_options --disable-plugins
# to fix
ac_add_options --disable-crypto
# ssltunnel can't build if we disable crypto
# ssltunnel also can't build because the ndk doesn't have string, vector, or algorithm headers
ac_add_options --disable-tests
 
This assumes the ndk was installed in the parent directory.
 
==== 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
 
== 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 [http://www.yaffs.net/ 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
** (Device) ps js
USER    PID  PPID  VSIZE RSS  WCHAN    PC        NAME
root    6036  6034  6084  1856  ffffffff afe0c27c T ./js
* 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)
** (Host) ~/android-ndk-1.6_r1/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-gdb js
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
 
== 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.
 
= Other Resources =
 
* [https://wiki.mozilla.org/User:Joel_Reymont/Android_Notes Joel's Notes]
* [https://wiki.mozilla.org/User:VladVukicevic/Android_Notes Vlad's Notes]
* [http://hg.mozilla.org/users/vladimir_mozilla.com/android-testapp/ Vlad's Test App Hg Repo]

Latest revision as of 16:50, 4 May 2010