Android: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
 
(5 intermediate revisions by 3 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
* JS builds and shell runs
* xpcshell builds and runs
* Android packaging (apk) works
** application.ini is copied to a file on startup
** components directory is copied on startup
** startup fails on first and sometimes second start
* Android widget draws stuff - http://blog.vlad1.com/2010/02/02/android-progress-more-pixels-edition/
** Keyboard input works
** Softkb works
** Event loop halfway working
* Fennec starts. Some issues with initial sizing. - http://www.flickr.com/photos/madhava_work/4389974241/
 
== 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 ===
 
* Standard [https://developer.mozilla.org/En/Linux_Build_Prerequisites Linux build environment] or [https://developer.mozilla.org/En/Developer_Guide/Build_Instructions/Mac_OS_X_Prerequisites Mac OS X build environment]
* [http://developer.android.com/sdk/ndk/index.html Android r3 NDK]
* [http://developer.android.com/sdk/ Android SDK]
 
==== 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 sun-java6-jdk
 
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 <tt>make -C embedding/android</tt> should generate a fennec.apk that's installable on an Android device using <tt>adb install fennec.apk</tt>
 
==== 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 [[Android/NSPR|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 [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. 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 ==
 
* 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 =
 
* [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