Mobile/Fennec/Android

From MozillaWiki
< Mobile‎ | Fennec
Revision as of 06:21, 9 December 2012 by Liungkejin (talk | contribs)
Jump to navigation Jump to search

构建 Fennec

下面这些命令是用来设置构建环境和在Linux(Ubuntu),Max OS X系统下构建Fennec. 目前还没有可能在Windows下编译 Fennec. 如果您的系统是Windows, 您可以阅读一下文章在Linux虚拟机上编译Fennec:

另外, 这里OtherBuildEnvs page 也有 一些在其他环境下不同的提示,如果你有一个环境或者配置偏离“正常”,您应该看一看.

首先按照特定平台的指令去在你的机器上设置构建环境. 你也可以选择升级到最新的Android NDK (目前版本是 r8c). 一旦你 这样做了就可以按照步骤获取源代码,设置你的mozconfig并构建Fennec.

Linux

快速脚本

这是一个快速设置脚本,下面会对它进行详细的解释.

# 确保 “partner" 库在/etc/apt/sources.list中可用. 或者 sun-java6-jdk 不会被找到
# 在 Ubuntu 11.10 中 Java 已经从 partner 中移走, 但是可以从Oracle下载
# http://www.oracle.com/technetwork/java/javase/downloads/index.html
sudo apt-get update
sudo apt-get install sun-java6-jdk mercurial ccache
sudo apt-get build-dep firefox
wget http://dl.google.com/android/ndk/android-ndk-r5c-linux-x86.tar.bz2
tar -xjf android-ndk-r5c-linux-x86.tar.bz2
wget http://dl.google.com/android/android-sdk_r20.0.3-linux.tgz
tar -xzf android-sdk_r20.0.3-linux.tgz
./android-sdk-linux/tools/android update sdk -u
./android-sdk-linux/tools/android update adb

如果你使用64位的Ubuntu安装,你需要ia32-libs来允许工具链二进制文件的运行

 sudo apt-get install ia32-libs

如果你使用64位的Fedora安装

 yum install glibc.i686 ncurses-libs.i686 libstdc++.i686 zlib.i686

详解

这一节将详细的描述所有的依存关系和在Linux下得到一个工作构建环境的要求. This section describes in greater detail all the dependencies and requirements of getting a working build environment on Linux.

安装Java

首先安装Sum Java jdk6, Android SDK也依赖于此. 如果你使用的是Ubuntu 11.10之前的版本,那么你需要在 enable the partners repo 上得到它. Java 7 应该也可以使用, 尽管有时候会歇菜(java 6 为buildbots所使用, 所以它是“官方支持”的).

# Ubuntu 11.10 之前的版本
sudo apt-get update
sudo apt-get install sun-java6-jdk
sudo update-java-alternatives -s java-6-sun
# Ubuntu 11.10 和之后的版本
# 从http://www.oracle.com/technetwork/java/javase/downloads/index.html 下载java和最新版本的JDK
# 以下这些命令假设这个文件叫做jdk-6u35-linux-x64.bin
sudo mkdir /opt/java
sudo mv ~/Downloads/jdk-6u35-linux-x64.bin
sudo chmod +x ./jdk-6u35-linux-x64.bin
sudo ./jdk-6u35-linux-x64.bin
ln -f -s /opt/java/jdk1.6.0_35/bin/* /usr/local/bin/
# 类似命令sudo update-alternatives --install /usr/local/bin/java java /opt/java/jdk1.6.0_35/bin/1
# 关闭注册Java发行版的方式

如果你使用64位Ubuntu, 此时你仍需要安装 ia32-libs(如果你没有安装,诸如 adb 这样的将不会工作)

 apt-get install -y ia32-libs
安装 Gecko 的要求

安装需要一个firefox构建

sudo apt-get install mercurial ccache
sudo apt-get build-dep firefox
安装 Android NDK

下载并解压 Android NDK. NDK revs 4-8已经测试并能正常工作. 目前使用的自动构建器的版本是r5c.

wget http://dl.google.com/android/ndk/android-ndk-r5c-linux-x86.tar.bz2
tar -xjf android-ndk-r5c-linux-x86.tar.bz2
安装 Android SDK

你应该安装最新的版本Android SDK, 我们在manifest文件中设置的API级 别. sdk的下载可能需要花费相当长的时间,请确保你有良好的网络连接. 然后你可以去喝杯咖啡,甚至吃个午餐.

你所需要的SDK版本至少是16.

wget http://dl.google.com/android/android-sdk_r20.0.3-linux.tgz
tar -xzf android-sdk_r20.0.3-linux.tgz
./android-sdk-linux/tools/android update sdk --no-ui
./android-sdk-linux/tools/android update adb

你可能想在你的shell中将SDK的 "tools" 和 “platform-tools" 文件夹加入到环境变量PATH中,因此你可以运行 adb 和其他简单的工具,例如: 如果 你在$HOME/opt 下安装了SDK,你可以在你的.bashrc最后加入以下一行:

 export PATH=$PATH:$HOME/opt/android-sdk-linux/platform-tools:$HOME/opt/android-sdk-linux/tools

Mac OS X

To set up a build environment on Mac OS X, you first need to install XCode and a few supplementary build tools via a package manager. To do this, follow steps 1 and 2 of the Mac OS X Build Prerequisites page. Once you have completed steps 1 and 2, come back here and continue with the instructions below.

After installing XCode make sure you also have wget installed. If wget is not a recognized command in terminal follow these steps to install it:

curl -O http://ftp.gnu.org/gnu/wget/wget-1.14.tar.gz
tar -xzvf wget-1.14.tar.gz
cd wget-1.14
./configure --with-ssl=openssl
make
sudo make install
which wget #Should output: /usr/local/bin/wget
Install Gecko Requirements

Then install the usual stuff needed for a firefox build.

sudo apt-get install mercurial ccache
sudo apt-get build-dep firefox
Install Android NDK

Download and extract the Android NDK. NDK revs 4-8 have been tested and are known to work. The automated builders currently use version r5c.

wget http://dl.google.com/android/ndk/android-ndk-r5c-darwin-x86.tar.bz2
tar -xjf android-ndk-r5c-darwin-x86.tar.bz2
Install Android SDK

You should just install the latest Android SDK, we set the API level in our manifest files. The sdk download will take a while, make sure you have a decent internet connection and go get coffee, or maybe lunch.

You will need SDK version at least 16.

wget http://dl.google.com/android/android-sdk_r20.0.3-macosx.zip
unzip android-sdk_r20.0.3-macosx.zip
./android-sdk-macosx/tools/android update sdk --no-ui
./android-sdk-macosx/tools/android update adb

You will probably want to add the SDK's "tools" and "platform-tools" directory to the PATH environment variable in your shell, so that you can run adb and other tools easily. For example, if you installed the SDK in $HOME, you could add the following line to the end of your .bashrc:

 export PATH=$PATH:$HOME/android-sdk-macosx/platform-tools:$HOME/android-sdk-macosx/tools

Optional: Using NDK r8c

On some systems, linking libxul can takes several minutes. Using gold instead of ld can reduce this time (from around 7 minutes to a bit more than 1 minute on my machine ; YMMV, on another machine, it gets from 25 seconds to 10, or from 2 minutes to 1 minute with all system caches dropped).

To use gold, the best way is to just use the r8c Android NDK. You can also build gold yourself from binutils source and replace your existing ld binaries in the NDK folder to use gold. However it's simpler to just upgrade the NDK. There are currently no known issues with using the r8c NDK, except that you also need to remove the --enable-warnings-as-errors option in your mozconfig because the gcc-4.6 that comes with r8c is stricter with respect to warnings. There is some discussion in bug 769099 about how r8c is awesome stuff and should be used by default on the buildbots, but that hasn't happened yet.

To upgrade your NDK, download the NDK for Mac OS X or Linux and unpack it. Then, update your mozconfig to point to the new NDK by setting the --with-android-ndk and --with-android-toolchain options in your mozconfig.

For example, assuming that on a Mac OS X platform the NDK is unpacked into $HOME/android-ndk-r8c, you would need the following two lines in your mozconfig:

ac_add_options --with-android-ndk="$HOME/android-ndk-r8c"
ac_add_options --with-android-toolchain="$HOME/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86"

Getting the source

Once you have build tools set up, you should configure Mercurial as described here. (It is not required, but highly recommended if you plan on touching the code in any way). Once you have done that, grab a clone of the repository:

hg clone http://hg.mozilla.org/mozilla-central/ src

Setup Fennec mozconfig

The mozconfig file is what tells the mozilla build scripts how your build environment is set up, and sets various build options. To build scripts will read the mozconfig file from the $MOZCONFIG environment variable, if one is set, or the .mozconfig file in your src directory, if there is one. So you could do either this:

cd src
vim .mozconfig # put mozconfig here

or this:

cd some/random/folder
vim my-fennec-mozconfig # put mozconfig here
export MOZCONFIG=$PWD/my-fennec-mozconfig

Here is an example mozconfig file for building Fennec, assuming you have followed the instructions above and are using version r5c of the NDK.

 # Add the correct paths here:
 ac_add_options --with-android-ndk="$HOME/android-ndk-r5c"
 ac_add_options --with-android-sdk="$HOME/android-sdk-linux/platforms/android-16"
 ac_add_options --with-android-version=5

 # android options
 ac_add_options --enable-application=mobile/android
 ac_add_options --target=arm-linux-androideabi
 ac_add_options --with-ccache

 mk_add_options MOZ_OBJDIR=./objdir-droid
 mk_add_options MOZ_MAKE_FLAGS="-j9 -s"

Remember to use $HOME instead of ~ in the mozconfig, because ~ will not get expanded to the right path! If you are building on Mac OS X you will also need to add this:

ac_add_options --disable-crashreporter

because the crash reporter does not build properly on Mac OS X.

If you want to build for armv6 add this:

 ac_add_options --with-arch=armv6

You can also look at the mozconfig used for official nightly builds.

Building the code

This will build (compile+link), package into apk, and deploy to the Android device. Therefore, before you start building connect your Android device and enable USB debugging

cd src
make -f client.mk build_and_deploy

You can also just do:

make -f client.mk
make -C objdir-droid package

to build and package the code into an APK. The APK file can be found in your objdir-droid/dist/ folder, and will be called something like fennec-18.0a1.en-US.android-arm.apk. You can install this APK to your device manually using "adb install". The name of the app that shows up on your phone will be "Fennec $USER" (where $USER is the username under which you built the code).