环境
设备:MacBook Air (M1, 2020)
系统:macos Monterey 12.01
下载指定版本webrtc
本文不指定版本,直接下载能够下到的最新代码,如需要指定版本可以更具分支名称切下分支。例如,git checkout /branch/3367.
webrtc Release Notes
安装depot_tools
非常重要的工具集,下载编译都需要靠它。
export WORKSPACE=$(pwd)
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=$WORKSPACE/depot_tools:$PATH
代理配置
一般不进行科学上网的话根本下载不下来,毕竟有十几个G的大小。终端可以通过配置http和https代理来克隆源码:
# 终端中设置临时变量
export http_proxy=http://39.105.13.136:8080 #换成自己vpn的代理
export https_proxy=http://39.105.13.136:8080 #换成自己vpn的代理
# 不使用了可以恢复代理
export http_proxy=“”
export https_proxy=“”
下载webrtc源码
1、mkdir webrtc && cd webrtc_ios
2、fetch --nohooks webrtc_ios
Running: gclient root
WARNING: Your metrics.cfg file was invalid or nonexistent. A new one will be created.
Running: gclient config --spec 'solutions = [
{
"url": "https://webrtc.googlesource.com/src.git",
"managed": False,
"name": "src",
"deps_file": "DEPS",
"custom_deps": {},
},
]
target_os = ["ios", "mac"]
3、gclient sync更新代码
源码构建
IOS
python tools_webrtc/ios/build_ios_libs.py --output-dir out/ios --arch arm64 --extra-gn-args rtc_include_tests=false rtc_build_tools=false rtc_build_examples=false
MacOS
gn gen out/mac --args='target_os="mac" is_debug=false target_cpu="arm64" rtc_include_tests=false rtc_build_tools=false rtc_build_examples=false'
#gn gen 依赖于BUILD.gn文件,webrtc工程中可能存在多个BUILD.gn,例如execmple中的BUILD.gn就是独立的。
Ninja编译:
gn 只是生成ninja文件,编译还是需要ninja的。
生产framework
// mac_framework_objc 为framework, 可以为其它的target
ninja -C out/mac mac_framework_objc
生成libwbrtc.lib
ninja -C out/mac webrtc
/src/out/mac/obj libwebrtc.a
AppRTCMobile例子编译
以mac为例:
$ cd /src/examples
$ gn gen out/mac --args='target_os="mac" target_cpu="arm64"' --ide=xcode
$ ninja -C out/mac AppRTCMobile_executable #在这里编译快点,不然xcode哪里还要调用ninja编译超慢的。
$ open -a Xcode.app out/mac/all.xcworkspace #打开xcode,也可直接点击文件打开
# 问题处理
1、左侧选product,右侧选AppRTCMobile作为target
2、general>>identify中选AppRTCMobile对应的info.plist
3、2中还有问题的话,在signing&capabilities中勾选auto,并填些可用的team
4、运行即可
参考
1、https://github.com/webrtc-mirror/mirror
2、http://depthlove.github.io/2019/10/18/webrtc-development-5-run-mac-project/
3、《webrtc native开发实战》