1. Install depot_tools
Clone the /depot_tools/ repository:
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
2. Add path
$ export PATH=/path/to/depot_tools:$PATH
Cmd
+ Shift
+ .
在Finder中显示隐藏的文件,找到~/.zshrc
,如果没有的话新建一个
如果depot_tools
位于~/depot_tools
export PATH=$HOME/depot_tools:$PATH
3. 修改Python3 BIN
修改~/depot_tools/bootstrap_python3
:
-BOOTSTRAP_PYTHON_BIN="${BOOTSTRAP_PATH}/python3/bin/python3"
+BOOTSTRAP_PYTHON_BIN="$/usr/bin/python3"
4. Get source code
fetch —nohooks webrtc_ios
如果terminal没有反应可能是在下载中
5. vpython3报错
错误:找不到.cipd_bin/vpython3
文件 :
❯ fetch --nohooks webrtc_ios
/Users/admin/Projects/depot_tools/vpython3: line 52: /Users/admin/Projects/depot_tools/.cipd_bin/vpython3: No such file or directory
/Users/admin/Projects/depot_tools/vpython3: line 52: exec: /Users/admin/Projects/depot_tools/.cipd_bin/vpython3: cannot execute: No such file or directory
解决方案: 在终端执行update_depot_tools
命令
如果遇到update也报错:
fatal: unable to access 'https://chromium.googlesource.com/chromium/tools/depot_tools.git/': Failed to connect to chromium.googlesource.com port 443 after 75080 ms: Operation timed out
说明网络不通,ping下chromium.googlesource.com
看看,需要科学上网工具
基本上折腾到这里,应该是可以进入gclient sync
阶段了
6. GN Project files生成
# debug build for 64-bit iOS
gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64"'
# debug build for simulator
gn gen out/ios_sim --args='target_os="ios" target_cpu="x64"'
根据文档选择自己的目标架构编译,源码可能无法编译通过,可能会报这个错:
ERROR at //webrtc.gni:504:32: Assignment had no effect.
xctest_module_target = "//test:google_test_runner_objc"
^-------------------------------
You set the variable "xctest_module_target" here and it was unused before it went
out of scope.
See //testing/test.gni:706:5: whence it was called.
target(ios_test_target_type, _test_target) {
^-------------------------------------------
See //webrtc.gni:463:3: whence it was called.
test(target_name) {
^------------------
See //BUILD.gn:550:3: whence it was called.
rtc_test("rtc_unittests") {
^--------------------------
解决方案:
暴力注释
注释掉webrtc.gni
第504行:
- xctest_module_target = "//test:google_test_runner_objc"
+# xctest_module_target = "//test:google_test_runner_objc"
加上rtc_include_tests=false
再compile:(注意要写到单引号前面)
#debug build for 64-bit iOS
gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64" rtc_include_tests=false'
# debug build for simulator
gn gen out/ios_sim --args='target_os="ios" target_cpu="x64" rtc_include_tests=false'
基本上折腾到这里是能compile通过了:
❯ gn gen out/ios_sim --args='target_os="ios" target_cpu="x64"' ⏎
Done. Made 1958 targets from 278 files in 2348ms
8.Ninja comple
ninja -C out/ios_sim AppRTCMobile
这一步基本上没啥问题,4000多个文件,其实还是算少的,编下来挺快hhh(别问我问什么4000多个文件还觉得少),但是我发现我需要的是在xcode中运行,所以……
9.通过Xcode运行
最后发现自己遗漏了一个问题,就是我还是希望使用xcode运行的,所以得用以下方式,整体上是在上面的gn compile
命令里加了一个--ide=xcode
:
gn gen out/ios_sim --args='target_os="ios" target_cpu="x64" rtc_include_tests=false' --ide=xcode
open -a Xcode.app out/ios_sim/all.xcworkspace
经过前面的折腾,这一步非常顺利:
❯ gn gen out/ios_sim --args='target_os="ios" target_cpu="x64" rtc_include_tests=false' --ide=xcode
open -a Xcode.app out/ios/all.xcworkspace
Generating Xcode projects took 82ms
Done. Made 1315 targets from 253 files in 1574ms
The file /Users/admin/src/out/ios_sim/all.xcworkspace does not exist.
工程找不到,看了下可能是工程结构有所改变,.xcworkspace
在out中估计已经被移除了,改成.xcodeproj
是合理的
gn gen out/ios_sim --args='target_os="ios" target_cpu="x64" rtc_include_tests=false' --ide=xcode
open -a Xcode.app out/ios_sim/all.xcodeproj
加上这两行很快就可以打开工程了:
10.运行
第一次run有一个Legacy Build System的error,这个问题很好解决,我就不说了,改完以后运行了一下成功了
问题不大,接下来研究下demo怎么运行