Mobile/Fennec/Android: Difference between revisions

From MozillaWiki
< Mobile‎ | Fennec
Jump to navigation Jump to search
No edit summary
(Fix link to current build doc)
 
(388 intermediate revisions by 61 users not shown)
Line 1: Line 1:
== 构建 Fennec ==
{{Admon/important|Fennec has been replaced by Fenix.  The build documentation has moved!|See the most up to date documentation at https://firefox-source-docs.mozilla.org/contributing/build/building_mobile_firefox.html}}


下面这些命令是用来设置构建环境和在Linux(Ubuntu),Max OS X系统下构建Fennec. 目前还没有可能在Windows下编译
Here is a table of contents of all the in-depth information you might need to find about Firefox for Android development.
Fennec. 如果您的系统是Windows, 您可以阅读一下文章在Linux虚拟机上编译Fennec:


* http://blog.lassey.us/2010/07/09/android-development-vm/
New to the community? Welcome! [[Mobile/Get_Involved|Start here!]]
* http://blog.lassey.us/2011/07/22/updated-android-development-vm/


另外, 这里[https://wiki.mozilla.org/Mobile/Fennec/Android_OtherBuildEnvs OtherBuildEnvs page] 也有
== Develop ==
一些在其他环境下不同的提示,如果你有一个环境或者配置偏离“正常”,您应该看一看.  
*[[Mobile/Get Involved|New contributor page]]
**[[Mobile/Fennec/Android/Suggested workflow|Suggested workflow]]
*[https://developer.mozilla.org/en-US/docs/Simple_Firefox_for_Android_build Build documentation]
*[[Mobile/Fennec/Android/Testing|Testing]]
*[[Mobile/Fennec/Android/CommonTips|Common tips & how-to's]]
*[[Mobile/Fennec/Android/Multilocale_Builds|Multilocale Builds]] - how to build an apk containing multiple languages (instead of just en-US by default).
*[[Mobile/Fennec/Android/Development/Addons|Useful addons for development (e.g. copy profile)]]
*[[Mobile/Fennec/Android/AdvancedTopics|Advanced topics (e.g. special build configs & advanced debugging)]]
*[https://gecko.readthedocs.org/en/latest/mobile/android/fennec/index.html In-tree Firefox for Android documentation]
*[[Mobile/Triage|Triage]]
*[[Mobile/Metrics|Metrics]]
*[[Mobile/Fennec/Android/png_optimisation|png optimisation]] - a guide on how to prepare png and raster images for landing in the tree, in order to minimise their size. This includes details on webp conversion, when applicable.


首先按照特定平台的指令去在你的机器上设置构建环境. 你也可以选择升级到最新的Android NDK (目前版本是 r8c). 一旦你
=== App and development overview ===
这样做了就可以按照步骤获取源代码,设置你的mozconfig并构建Fennec.
* [[Mobile/Fennec/Android/App_Structure|App Structure]]: Fennec is a combination of Java frontend code, Javascript glue and display code, and C++ rendering code. Here's a brief 9000m (30'000ft) overview of what each of those parts does.
** [[Mobile/Fennec/Android/Build_Systems|Build Systems]]: Our app structure results in a complex build process. Moreover, we are in the process of migrating our builds from a custom (Makefile based) build, to using Gradle for the frontend/Java portions of our app. This is a brief description of our parallel build systems and what we're trying to achieve in the future.


=== Linux ===
=== Feature development ===
* [[Mobile/Distribution_Files|Distribution files]]
* [[Mobile/Fennec/Android/Java_telemetry|Java telemetry]]
* [[Mobile/Fennec/Android/Switchboard|Switchboard]]
* [[Mobile/Fennec/Android/Downloadable_Content|Downloadable Content]]


==== 快速脚本 ====
=== Test results ===
*[https://scan.coverity.com/projects/firefox-mobile Coverity static analysis]


这是一个快速设置脚本,下面会对它进行详细的解释.
=== Build infrastructure ===
*[[Mobile/Fennec/Android/Task Cluster notes|Task Cluster notes]]
*[[Mobile/Fennec/Android/mach_bootstrap_SDK_dependencies|`./mach bootstrap` SDK dependencies]]


# 确保 “partner" 库在/etc/apt/sources.list中可用. 或者 sun-java6-jdk 不会被找到
=== General developer resources ===
# 在 Ubuntu 11.10 中 Java 已经从 partner 中移走, 但是可以从Oracle下载
*[https://mozilla-version-control-tools.readthedocs.org/en/latest/hgmozilla/index.html Mercurial for Mozillians]
# http://www.oracle.com/technetwork/java/javase/downloads/index.html
*[https://moz-conduit.readthedocs.io/en/latest/phabricator-user.html Mozilla Phabricator User Guide]
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来允许工具链二进制文件的运行
=== Crash Stats ===
 
* The crash-stats page lives at https://crash-stats.mozilla.com/home/product/FennecAndroid
  sudo apt-get install ia32-libs
** Be careful to select "'''FennecAndroid'''" under the product dropdown to see Firefox on Android crashes.
 
*** Nightly has the name XX.0a1 (e.g. 52.0a1)
如果你使用64位的Fedora安装
*** Aurora has the name XX.0a2 (e.g. 51.0a1 - the number is one lower than nightly)
 
*** Beta is XX.0bN (e.g. 50.0b12). N is increased every time a new beta is released (usually weekly).
  yum install glibc.i686 ncurses-libs.i686 libstdc++.i686 zlib.i686
**** '''Note:''' Multiple beta versions can be listed under the versions dropdown, the first one listed might not be the currently released beta.
 
*** Release is XX.0.N (e.g. 49.0.2). N is increased every time there is a dot release, we usually try to avoid dot releases.
==== 详解 ====
** Beware: a single device (which potentially has a hardware issue and/or a user who has done something strange with their configuration) can result in a crash-spike on nightly, or even aurora - not every crash is something significant.
 
** You can view devices that are affected by selecting a crash-signature, then going to "Aggregations", followed by clicking on the "Aggregate on" dropdown and selecting "Android device". Some issues might be device or manufacturer specific.
这一节将详细的描述所有的依存关系和在Linux下得到一个工作构建环境的要求.
** To create a bugzilla entry for a given crash, open a crash report (if you are viewing a signature, go to "reports" and click on one of the items there). From the crash report search for "Bugzilla - Report this bug in" and select the appropriate module.
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之前的版本,那么你需要在
[https://help.ubuntu.com/community/Repositories/Ubuntu#Adding_Canonical_Partner_Repositories 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 =====
 
下载并解压 [http://developer.android.com/sdk/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 =====
 
你应该安装最新的版本[http://developer.android.com/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中,因此你可以运行
[http://developer.android.com/guide/developing/tools/adb.html 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 [https://developer.mozilla.org/en-US/docs/Developer_Guide/Build_Instructions/Mac_OS_X_Prerequisites 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 [http://developer.android.com/sdk/ndk/ 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 [http://developer.android.com/sdk/ 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 [http://developer.android.com/guide/developing/tools/adb.html 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 <i>gold</i> instead of <i>ld</i> can reduce this time (from around 7 minutes to a bit more than 1 minute on my machine&#160;; 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 [http://dl.google.com/android/ndk/android-ndk-r8c-darwin-x86.tar.bz2 Mac OS X] or [http://dl.google.com/android/ndk/android-ndk-r8c-linux-x86.tar.bz2 Linux] and unpack it. Then, update your mozconfig to point to the new NDK by setting the <code>--with-android-ndk</code> and <code>--with-android-toolchain</code> 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 [https://developer.mozilla.org/en-US/docs/Installing_Mercurial#Configuration 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.
 
<pre>
# 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"
</pre>
 
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 [http://mxr.mozilla.org/mozilla-central/source/mobile/android/config/mozconfigs/android/nightly 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  [http://developer.android.com/guide/developing/device.html 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).

Latest revision as of 14:52, 16 February 2023

Important.png
Fennec has been replaced by Fenix. The build documentation has moved!
See the most up to date documentation at https://firefox-source-docs.mozilla.org/contributing/build/building_mobile_firefox.html

Here is a table of contents of all the in-depth information you might need to find about Firefox for Android development.

New to the community? Welcome! Start here!

Develop

App and development overview

  • App Structure: Fennec is a combination of Java frontend code, Javascript glue and display code, and C++ rendering code. Here's a brief 9000m (30'000ft) overview of what each of those parts does.
    • Build Systems: Our app structure results in a complex build process. Moreover, we are in the process of migrating our builds from a custom (Makefile based) build, to using Gradle for the frontend/Java portions of our app. This is a brief description of our parallel build systems and what we're trying to achieve in the future.

Feature development

Test results

Build infrastructure

General developer resources

Crash Stats

  • The crash-stats page lives at https://crash-stats.mozilla.com/home/product/FennecAndroid
    • Be careful to select "FennecAndroid" under the product dropdown to see Firefox on Android crashes.
      • Nightly has the name XX.0a1 (e.g. 52.0a1)
      • Aurora has the name XX.0a2 (e.g. 51.0a1 - the number is one lower than nightly)
      • Beta is XX.0bN (e.g. 50.0b12). N is increased every time a new beta is released (usually weekly).
        • Note: Multiple beta versions can be listed under the versions dropdown, the first one listed might not be the currently released beta.
      • Release is XX.0.N (e.g. 49.0.2). N is increased every time there is a dot release, we usually try to avoid dot releases.
    • Beware: a single device (which potentially has a hardware issue and/or a user who has done something strange with their configuration) can result in a crash-spike on nightly, or even aurora - not every crash is something significant.
    • You can view devices that are affected by selecting a crash-signature, then going to "Aggregations", followed by clicking on the "Aggregate on" dropdown and selecting "Android device". Some issues might be device or manufacturer specific.
    • To create a bugzilla entry for a given crash, open a crash report (if you are viewing a signature, go to "reports" and click on one of the items there). From the crash report search for "Bugzilla - Report this bug in" and select the appropriate module.