aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/archive/b2g_os/building/index.html
blob: 838fe7c56fd4fe91b64d3fb150880eeade546a62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
---
title: 构建B2G
slug: Archive/B2G_OS/Building
translation_of: Archive/B2G_OS/Building
---
<div>
 </div>
<div class="summary">
 <p>一旦建立B2G的构建系统与完成代码的初始化提取和配置,你就可以生成B2G系统了。</p>
</div>
<h2 id="更新代码">更新代码</h2>
<p>在生成B2G系统前,如果这不是你第一次构建B2G, 你也许想要获取最新的代码。要实现这一点,你应该使用下面两个命令更新B2G工具和依赖项:</p>
<pre>git pull
./repo sync
</pre>
<p>You can update a specific make target's repository by specifying its name:</p>
<pre>./repo sync gaia
</pre>
<p>The repo command has other options available that might be interesting; <code>repo help</code> will give you a lot of information.</p>
<h2 id="编译">编译</h2>
<div class="note">
 <p><strong>Note:</strong> Before building, you may want to set up a <code>.userconfig</code> file to customize the build. See <a href="/en-US/docs/Mozilla/Boot_to_Gecko/Customization_with_the_.userconfig_file" title="/en-US/docs/Mozilla/Boot_to_Gecko/Customization_with_the_.userconfig_file">Customization with the .userconfig file</a> for details.</p>
</div>
<p>To build Boot to Gecko, simply use the <code>build.sh</code> tool:</p>
<pre>cd B2G
./build.sh
</pre>
<p>Time for another coffee break, or possibly a nap (especially if this is your first build).</p>
<h3 id="编译具体的模块">编译具体的模块</h3>
<p>If you want to build just a particular module, such as Gecko, you can specify it by name:</p>
<pre>./build.sh gecko
</pre>
<p>To get a list of the modules you can build, you can do:</p>
<pre>./build.sh modules
</pre>
<h3 id="设置所使用的处理器的核心数">设置所使用的处理器的核心数</h3>
<p>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 <code>-j</code> parameter when running <code>build.sh</code>. 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!</p>
<p>For example, to build using just two parallel tasks:</p>
<pre>./build.sh -j2
</pre>
<p>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:</p>
<pre>./build.sh -j1
</pre>
<h3 id="若你的编译系统在运行测试的时候出了差错">若你的编译系统在运行测试的时候出了差错</h3>
<p>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:</p>
<pre>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</pre>
<p>In this situation, try deleting the <code>gaia/xulrunner-sdk</code> directory and re-pulling the code:</p>
<pre>rm -r gaia/xulrunner-sdk
</pre>
<p>This deletes the downloaded, precompiled copy of <a href="/en-US/docs/XULRunner" title="/en-US/docs/XULRunner">XULRunner</a> that the build system retrieves automatically; on your next build, a new copy of XULRunner will be automatically retrieved.</p>
<h2 id="已知错误">已知错误</h2>
<h3 id="“构建错误!”(Build_failed!)">“构建错误!”("Build failed!")</h3>
<p>如果你得到一个普通的“构建错误”信息,你应该尝试重新连接你的手机到电脑上;有时手机可能会因为各种原因被卸载。</p>
<div class="note">
 <p><strong>注意不能在Mac上为Keon配置和构建B2G</strong>. 你需要使用Linux来为它构建系统。</p>
</div>
<h3 id="美洲狮(Mountain_Lion)特定错误">美洲狮(Mountain Lion)特定错误</h3>
<div>
 <p>1.如果你正在OS X 10.8 “美洲狮”(Xcode 4.4.1或更新)上构建并发生了如下错误:</p>
 <pre class="language-html" style="font-size: 14px;"><code class="language-html">external/qemu/android/skin/trackball.c:130:25: error: 'M_PI' undeclared (first use in this function)</code></pre>
 编辑文件: <code style="font-size: 14px;">B2G/external/qemu/Makefile.android</code> 并在第78行加上:<br>
 <pre class="language-html" style="font-size: 14px;"><code class="language-html">MY_CFLAGS += -DM_PI=3.14159265358979323846264338327950288   #/* B2G_fix: not finding M_PI constant */</code></pre>
</div>
<div>
 2. If you are on Mountain Lion and you receive an error during ./build.sh like:</div>
<div>
 <pre class="language-html"><code class="language-html">/System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h:797:9: error: too many #pragma options align=reset</code></pre>
 <p>Replace all instances of '#pragma options align=reset' with '#pragma pack()' inside /System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h</p>
</div>
<h3 id="未定义符号(Undefined_symbols_)_sqlite3_androidopt_handle_pragma_和__sqlite3_androidopt_open">未定义符号(Undefined symbols )"_sqlite3_androidopt_handle_pragma" 和 "_sqlite3_androidopt_open"</h3>
<p>这个错误会在你在OS X 10.7 及更新系统上使用 Xcode 4.5 及更新构建使出现,为解决这个问题,请在external/sqlite/dist/Android.mk文件上应用补丁<a href="https://groups.google.com/forum/#%21msg/android-building/yAfPyUqCsiQ/7zvICk4GWjYJ">https://groups.google.com/forum/#!msg/android-building/yAfPyUqCsiQ/7zvICk4GWjYJ</a></p>
<h3 id="KeyedVector.h19331_error_indexOfKey_was_not_declared_in_this_scope">KeyedVector.h:193:31: error: indexOfKey was not declared in this scope</h3>
<p>这个错误在你使用较新的gcc版本时出现,安装gcc/g++/g++-multilib 4.6.x版本。详见<a href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS/Customization_with_the_.userconfig_file" title="Mozilla/Firefox_OS/Customization_with_the_.userconfig_file">使用</a><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS/Customization_with_the_.userconfig_file" title="Mozilla/Firefox_OS/Customization_with_the_.userconfig_file">.userconfig文件自定应</a>.</p>
<div class="note">
 <p><strong>社区友情提示:</strong> 稍微的修改一下B2G的代码(gcc会告诉你如何改),使用gcc 4.7.x也是可能的,但是这并没有任何的帮助,无论是对于修改的代码还是你会遇到的bug来说。</p>
</div>
<h3 id="arm-linux-androideabi-g_Internal_error_Killed_(program_cc1plus)">arm-linux-androideabi-g++: Internal error: Killed (program cc1plus)</h3>
<p>如果你见到了这样的信息,很有可能是内存不足造成的,在执行<code>./build.sh之前</code>确保你有足够的可用内存,如果你的系统有4GB RAM应该就可以正常运行。</p>
<h3 id="...is_referenced_by_DSO_error">"...is referenced by DSO" error</h3>
<p>如果在构建模拟器时你得到了这样的信息: /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.</p>
<p>你可以通过各种版本的二进制包工具获得,如果你使用Debian Stable,你可以通过安装<code>binutils-gold包来使用</code><em>gold</em>连接器,注意,<code>binutils已经安装了<em>gold</em></code>连接器,但是并没有默认使用;<code>binutils-gold</code>就是来做这件事的(让它默认使用)。</p>
<h3 id="如果你在编译系统运行测试时遇到编译错误">如果你在编译系统运行测试时遇到编译错误</h3>
<p>有时,特别是编译工具或操作系统升级之后,在编译系统运行编译后测试时,你会遇到一些奇怪的错误。</p>
<pre class="language-html"><code class="language-html">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</code></pre>
<p>在这种情况下,尝试删除 <code>gaia/xulrunner-sdk 目录并从重新拷贝一份代码:</code></p>
<pre class="language-html"><code class="language-html">rm -r gaia/xulrunner-sdk</code></pre>
<p>这会删除编译系统自动恢复的已下载的<a href="https://developer.mozilla.org/en-US/docs/XULRunner" title="/en-US/docs/XULRunner">XULRunner</a>的预编译副本,在你下一次编译时,系统会自动恢复一个新的副本。</p>
<h3 id="(无法获取)Cannot_fetch_platformlibcore">(无法获取)Cannot fetch platform/libcore</h3>
<p>如果你尝试为Nexus S编译B2G(<code>./config.sh nexus-s</code>)并遇到了libcore相关的错误,那是我们使用开源项目git的缘故,为了解决这个问题,像下面这样检出B2G manifest:</p>
<pre class="brush: bash language-html"><code class="language-bash">git clone https://github.com/mozilla-b2g/b2g-manifest.git</code></pre>
<p>在这个仓库中编辑文件 <code>nexus-s.xml</code>, 用一个aosp的入口引用来替换开源git的入口,像下面这个样子:</p>
<pre class="brush: xml  language-xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>default</span> <span class="token attr-name">revision</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>refs/tags/android-4.0.4_r1.2<span class="token punctuation">"</span></span>
              <span class="token attr-name">remote</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>aosp<span class="token punctuation">"</span></span>
              <span class="token attr-name">sync-j</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>4<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span></code></pre>
<p>提交这些改变并改变B2G主仓库主分支中的<code>config.sh文件,使你的检出指向你本地修改过的manifest而不是Mozilla提供的:</code></p>
<pre class="brush: bash language-html"><code class="language-bash">GITREPO=${GITREPO:-"file:///home/path/to/my/b2g-manifest"}</code></pre>
<h3 id="clang_errors_when_building_with_Xcode_5_on_Mac">clang errors when building with Xcode 5 on Mac</h3>
<p>If you are building on Mac OS X 10.8 with Xcode 5, you will likely see errors like the following:</p>
<pre class="brush: bash language-html"><code class="language-bash">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</code></pre>
<p>This is because Xcode 5 changes the g++ compiler in <code>/usr/bin</code>, 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 <code>build/core/combo/HOST_darwin-x86.mk:</code></p>
<pre class="brush: bash language-html"><code class="language-bash">HOST_CXX := g++</code></pre>
<p>to</p>
<pre class="brush: bash language-html"><code class="language-bash">HOST_CXX := g++-4.6
ifeq (,$(wildcard /usr/local/bin/g++-4.6))
 HOST_CXX := g++
endif</code></pre>
<p>Next, you'll want to uninstall gcc, using brew (this assumes you've run the <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS/Firefox_OS_build_prerequisites#Run_Firefox_OS_Mac_Bootstrap">Mac OS bootstrap script</a> — if not, you'll need to complete that step before continuing):</p>
<pre class="brush: bash language-html"><code class="language-bash">brew uninstall gcc-4.6</code></pre>
<p>Now reinstall gcc with multilib and c++ support:</p>
<pre class="brush: bash language-html"><code class="language-bash">brew install --enable-cxx https://gist.github.com/artlogic/6988658/raw/aeb9d1ea098274ad3f3fe2637b9df7f308a8a120/gcc-4.6.rb</code></pre>
<p>Make sure /usr/local/bin is on your PATH. You can do this temporarily by typing the following into the command prompt:</p>
<pre class="brush: bash language-html"><code class="language-bash">export PATH=/usr/local/bin:$PATH</code></pre>
<p>You can make the above change permanent by adding it to the <code>.bash_profile</code> file in your home directory.</p>
<p>After you've set your PATH, make sure you can run both of the following commands:</p>
<pre class="brush: bash language-html"><code class="language-bash">gcc-4.6 -v

g++-4.6 -v</code></pre>
<p>If either of these commands fail, you may need to relink your gcc using brew with the following command:</p>
<pre class="brush: bash language-html"><code class="language-bash">brew link --overwrite gcc-4.6</code></pre>
<p>It's also possible that <code>/usr/bin/c++</code> is not pointing at clang++ as it should be with Xcode 5 installed. You can determine if it is by typing the following:</p>
<pre class="brush: bash language-html"><code class="language-bash">ls -l /usr/bin/c++</code></pre>
<p>It should return something that looks like this:</p>
<pre class="brush: bash language-html"><code class="language-bash">lrwxr-xr-x 1 root admin 7 Sep 19 11:40 /usr/bin/c++ -&gt; clang++</code></pre>
<p>If c++ is pointing at something other than clang++, update it with the following commands:</p>
<pre class="brush: bash language-html"><code class="language-bash">sudo rm /usr/bin/c++

sudo ln -s /usr/bin/clang++ /usr/bin/c++</code></pre>
<h3 id="Cannot_pull_files_from_backup_directory">Cannot pull files from backup directory</h3>
<p>This could happen when the USB connection is broken while the script pulls data from device to computer.</p>
<p>When you run the script again, you'll probably get the following (the example is for the Peak device):</p>
<pre class="brush: bash language-html"><code class="language-bash"><code>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.

&gt; Build failed! &lt;

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.</code></code></pre>
<p>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):</p>
<pre class="brush: bash language-html"><code class="language-bash"><code class="brush: bash">$rm -rf backup-peak</code></code></pre>
<h3 id="Emulator_build_issues"><strong>Emulator build issues</strong></h3>
<p>If you are making an <strong>emulator</strong> build, you need to pay attention to these issues:</p>
<div class="note">
 <p><strong>First, note that you shouldn't use the x86 emulator — it is hard to install and not well supported.</strong></p>
</div>
<p>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 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=897727" title="https://bugzilla.mozilla.org/show_bug.cgi?id=897727">bug 897727</a>.</p>
<p>There are two ways that you can solve this problem:</p>
<h4 id="Solution_1_have_both_32bit_and_64bit_OpenGL_libs_installed_with_the_right_symlinks">Solution #1: have both 32bit and 64bit OpenGL libs installed, with the right symlinks</h4>
<p>If your linux distro has multilib packages for OpenGL libraries, you can attempt installing them. You might then have to manually create some symlinks.</p>
<p>For example, here is the situation on Ubuntu 12.04 LTS x86-64. On this distribution, the <code>libgl1-mesa-dev</code> package cannot be installed simultaneously in x86-64 and i386 versions, but you can have the following combination of packages simultaneously installed:</p>
<pre class="bz_comment_text  language-html" id="comment_text_12"><code class="language-html">sudo apt-get install libgl1-mesa-dev libglapi-mesa:i386 libgl1-mesa-glx:i386</code></pre>
<p>After having run this command, you will still have to manually create some symlinks for the emulator build to succeed:</p>
<pre class="note  language-html"><code class="language-html">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</code></pre>
<h4 id="Solution_2_just_patch_the_emulator_so_it_only_builds_64bit">Solution #2: just patch the emulator so it only builds 64bit</h4>
<p>Just apply <a href="https://bug897727.bugzilla.mozilla.org/attachment.cgi?id=786280" title="https://bug897727.bugzilla.mozilla.org/attachment.cgi?id=786280">this patch</a> 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.</p>
<h2 id="下一步">下一步</h2>
<p>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:</p>
<ul>
 <li><a href="/en-US/docs/Mozilla/Boot_to_Gecko/Using_the_B2G_emulators" title="en-US/docs/Mozilla/Boot_to_Gecko/Using_the_B2G_emulators">Using the B2G emulators</a></li>
 <li><a href="/en-US/docs/Mozilla/Boot_to_Gecko/Using_the_B2G_desktop_client" title="en-US/docs/Mozilla/Boot_to_Gecko/Using_the_B2G_desktop_client">Using the B2G desktop client</a></li>
 <li><a href="/en-US/docs/Mozilla/Boot_to_Gecko/Installing_Boot_to_Gecko_on_a_mobile_device" title="en-US/docs/Mozilla/Boot_to_Gecko/Installing_Boot_to_Gecko_on_a_mobile_device">Installing Boot to Gecko on a mobile device</a></li>
 <li><a href="/en-US/docs/Mozilla/Boot_to_Gecko/Pandaboard" title="en-US/docs/Mozilla/Boot_to_Gecko/Pandaboard">Installing Boot to Gecko on a pandaboard</a></li>
</ul>