一旦建立B2G的构建系统与完成代码的初始化提取和配置,你就可以生成B2G系统了。
更新代码
在生成B2G系统前,如果这不是你第一次构建B2G, 你也许想要获取最新的代码。要实现这一点,你应该使用下面两个命令更新B2G工具和依赖项:
git pull ./repo sync
You can update a specific make target's repository by specifying its name:
./repo sync gaia
The repo command has other options available that might be interesting; repo help
will give you a lot of information.
编译
Note: Before building, you may want to set up a .userconfig
file to customize the build. See Customization with the .userconfig file for details.
To build Boot to Gecko, simply use the build.sh
tool:
cd B2G ./build.sh
Time for another coffee break, or possibly a nap (especially if this is your first build).
编译具体的模块
If you want to build just a particular module, such as Gecko, you can specify it by name:
./build.sh gecko
To get a list of the modules you can build, you can do:
./build.sh modules
设置所使用的处理器的核心数
By default, the B2G build scripts use the number of cores your system has plus two as the number of parallel tasks to run. You can change this by specifying the -j
parameter when running build.sh
. This can be handy if you're using your system for other things while building in the background and need to reduce CPU load a bit. It's also handy when you're having build problems, as it can make reading error output from the build process easier if you have just one task going at a time!
For example, to build using just two parallel tasks:
./build.sh -j2
The most common use case for this, however, is to prevent builds from running in parallel at all. This makes the output of the process much easier to read, making it easier to sort out build problems. To do this:
./build.sh -j1
若你的编译系统在运行测试的时候出了差错
Sometimes (especially after build tool or operating system updates) you'll get weird errors like this when the build system runs its post-build tests:
Generating permissions.sqlite... test -d profile || mkdir -p profile run-js-command permissions WARNING: permission unknown:offline-app WARNING: permission unknown:indexedDB-unlimited build/permissions.js:122: NS_ERROR_UNEXPECTED: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPermissionManager.add] make[1]: *** [permissions] Error 3 make: *** [gaia/profile.tar.gz] Error 2
In this situation, try deleting the gaia/xulrunner-sdk
directory and re-pulling the code:
rm -r gaia/xulrunner-sdk
This deletes the downloaded, precompiled copy of XULRunner that the build system retrieves automatically; on your next build, a new copy of XULRunner will be automatically retrieved.
已知错误
“构建错误!”("Build failed!")
如果你得到一个普通的“构建错误”信息,你应该尝试重新连接你的手机到电脑上;有时手机可能会因为各种原因被卸载。
注意不能在Mac上为Keon配置和构建B2G. 你需要使用Linux来为它构建系统。
美洲狮(Mountain Lion)特定错误
1.如果你正在OS X 10.8 “美洲狮”(Xcode 4.4.1或更新)上构建并发生了如下错误:
external/qemu/android/skin/trackball.c:130:25: error: 'M_PI' undeclared (first use in this function)
编辑文件: B2G/external/qemu/Makefile.android
并在第78行加上:MY_CFLAGS += -DM_PI=3.14159265358979323846264338327950288 #/* B2G_fix: not finding M_PI constant */
/System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h:797:9: error: too many #pragma options align=reset
Replace all instances of '#pragma options align=reset' with '#pragma pack()' inside /System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h
未定义符号(Undefined symbols )"_sqlite3_androidopt_handle_pragma" 和 "_sqlite3_androidopt_open"
这个错误会在你在OS X 10.7 及更新系统上使用 Xcode 4.5 及更新构建使出现,为解决这个问题,请在external/sqlite/dist/Android.mk文件上应用补丁https://groups.google.com/forum/#!msg/android-building/yAfPyUqCsiQ/7zvICk4GWjYJ。
KeyedVector.h:193:31: error: indexOfKey was not declared in this scope
这个错误在你使用较新的gcc版本时出现,安装gcc/g++/g++-multilib 4.6.x版本。详见使用.userconfig文件自定应.
社区友情提示: 稍微的修改一下B2G的代码(gcc会告诉你如何改),使用gcc 4.7.x也是可能的,但是这并没有任何的帮助,无论是对于修改的代码还是你会遇到的bug来说。
arm-linux-androideabi-g++: Internal error: Killed (program cc1plus)
如果你见到了这样的信息,很有可能是内存不足造成的,在执行./build.sh之前
确保你有足够的可用内存,如果你的系统有4GB RAM应该就可以正常运行。
"...is referenced by DSO" error
如果在构建模拟器时你得到了这样的信息: /usr/bin/ld: out/host/linux-x86/obj/EXECUTABLES/triangleCM_intermediates/triangleCM: hidden symbol `_XGetRequest' in out/host/linux-x86/obj/STATIC_LIBRARIES/libSDL_intermediates/libSDL.a(SDL_x11dyn.o) is referenced by DSO.
你可以通过各种版本的二进制包工具获得,如果你使用Debian Stable,你可以通过安装binutils-gold包来使用
gold连接器,注意,binutils已经安装了gold
连接器,但是并没有默认使用;binutils-gold
就是来做这件事的(让它默认使用)。
如果你在编译系统运行测试时遇到编译错误
有时,特别是编译工具或操作系统升级之后,在编译系统运行编译后测试时,你会遇到一些奇怪的错误。
Generating permissions.sqlite...
test -d profile || mkdir -p profile
run-js-command permissions
WARNING: permission unknown:offline-app
WARNING: permission unknown:indexedDB-unlimited
build/permissions.js:122: NS_ERROR_UNEXPECTED: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPermissionManager.add]
make[1]: *** [permissions] Error 3
make: *** [gaia/profile.tar.gz] Error 2
在这种情况下,尝试删除 gaia/xulrunner-sdk 目录并从重新拷贝一份代码:
rm -r gaia/xulrunner-sdk
这会删除编译系统自动恢复的已下载的XULRunner的预编译副本,在你下一次编译时,系统会自动恢复一个新的副本。
(无法获取)Cannot fetch platform/libcore
如果你尝试为Nexus S编译B2G(./config.sh nexus-s
)并遇到了libcore相关的错误,那是我们使用开源项目git的缘故,为了解决这个问题,像下面这样检出B2G manifest:
git clone https://github.com/mozilla-b2g/b2g-manifest.git
在这个仓库中编辑文件 nexus-s.xml
, 用一个aosp的入口引用来替换开源git的入口,像下面这个样子:
<default revision="refs/tags/android-4.0.4_r1.2"
remote="aosp"
sync-j="4" />
提交这些改变并改变B2G主仓库主分支中的config.sh文件,使你的检出指向你本地修改过的manifest而不是Mozilla提供的:
GITREPO=${GITREPO:-"file:///home/path/to/my/b2g-manifest"}
clang errors when building with Xcode 5 on Mac
If you are building on Mac OS X 10.8 with Xcode 5, you will likely see errors like the following:
clang: error: argument unused during compilation: '-include system/core/include/arch/darwin-x86/AndroidConfig.h'
clang: error: argument unused during compilation: '-U DEBUG'
clang: error: argument unused during compilation: '-U DEBUG'
clang: error: argument unused during compilation: '-MF out/host/darwin-x86/obj/EXECUTABLES/obbtool_intermediates/Main.d'
make: *** [out/host/darwin-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1
This is because Xcode 5 changes the g++ compiler in /usr/bin
, which breaks the build process if you try to use it to compile. In order to work around the problem, edit the following line in build/core/combo/HOST_darwin-x86.mk:
HOST_CXX := g++
to
HOST_CXX := g++-4.6
ifeq (,$(wildcard /usr/local/bin/g++-4.6))
HOST_CXX := g++
endif
Next, you'll want to uninstall gcc, using brew (this assumes you've run the Mac OS bootstrap script — if not, you'll need to complete that step before continuing):
brew uninstall gcc-4.6
Now reinstall gcc with multilib and c++ support:
brew install --enable-cxx https://gist.github.com/artlogic/6988658/raw/aeb9d1ea098274ad3f3fe2637b9df7f308a8a120/gcc-4.6.rb
Make sure /usr/local/bin is on your PATH. You can do this temporarily by typing the following into the command prompt:
export PATH=/usr/local/bin:$PATH
You can make the above change permanent by adding it to the .bash_profile
file in your home directory.
After you've set your PATH, make sure you can run both of the following commands:
gcc-4.6 -v
g++-4.6 -v
If either of these commands fail, you may need to relink your gcc using brew with the following command:
brew link --overwrite gcc-4.6
It's also possible that /usr/bin/c++
is not pointing at clang++ as it should be with Xcode 5 installed. You can determine if it is by typing the following:
ls -l /usr/bin/c++
It should return something that looks like this:
lrwxr-xr-x 1 root admin 7 Sep 19 11:40 /usr/bin/c++ -> clang++
If c++ is pointing at something other than clang++, update it with the following commands:
sudo rm /usr/bin/c++
sudo ln -s /usr/bin/clang++ /usr/bin/c++
Cannot pull files from backup directory
This could happen when the USB connection is broken while the script pulls data from device to computer.
When you run the script again, you'll probably get the following (the example is for the Peak device):
Pulling files from ../../../backup-peak
cat: ../../../backup-peak/system/build.prop: No such file or directory
Found firmware with build ID
Pulling "libaudioeq.so"
cp: cannot stat `../../../backup-peak/system/lib/libaudioeq.so': No such file or directory
Failed to pull libaudioeq.so. Giving up.
> Build failed! <
Build with |./build.sh -j1| for better messages
If all else fails, use |rm -rf objdir-gecko| to clobber gecko and |rm -rf out| to clobber everything else.
To solve this, it is not necessary to remove the whole objdir-gecko or out directories. Just remove the backup directory, like this (for the example above):
$rm -rf backup-peak
Emulator build issues
If you are making an emulator build, you need to pay attention to these issues:
First, note that you shouldn't use the x86 emulator — it is hard to install and not well supported.
Next, the build-system for the emulator builds both 32bit and 64bit versions of the emulator. As the emulator depends on OpenGL, this means that you need to have both 32bit and 64bit versions of OpenGL libraries installed on your system. See the discussion in bug 897727.
There are two ways that you can solve this problem:
Solution #1: have both 32bit and 64bit OpenGL libs installed, with the right symlinks
If your linux distro has multilib packages for OpenGL libraries, you can attempt installing them. You might then have to manually create some symlinks.
For example, here is the situation on Ubuntu 12.04 LTS x86-64. On this distribution, the libgl1-mesa-dev
package cannot be installed simultaneously in x86-64 and i386 versions, but you can have the following combination of packages simultaneously installed:
sudo apt-get install libgl1-mesa-dev libglapi-mesa:i386 libgl1-mesa-glx:i386
After having run this command, you will still have to manually create some symlinks for the emulator build to succeed:
sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
Solution #2: just patch the emulator so it only builds 64bit
Just apply this patch to the sdk/ git repository under the B2G repo. This will cause the B2G emulator to only attempt to build the 64bit emulator if you're on a 64bit system, thus avoiding any multilib issues. The 32bit emulator is unused anyway on a 64bit system. This is the simplest solution, until this patch eventually bit-rots.
下一步
After building, your next step depends on whether you built Boot to Gecko for the emulator or for a real mobile device; see the following articles for details: