Skip to main content

编译 iOS 版本的 WebRTC

· 2 min read

iOS 平台的官方编译说明:https://webrtc.googlesource.com/src/+/main/docs/native-code/ios/index.md

基于官方文档总结一下,下载的源码库很大,整个编译过程就相当长时间,差不多花费一个小时。

获取源码

fetch --nohooks webrtc_ios

一定要确保上面的命令成功,如果出错,需要删除所有文件重来。大部分是网络问题,实在不行用代理。

PS: 这个命令会自动执行gclient sync

生成项目文件

gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64"'

默认是 debug 模式,如果要 Release 模式,增加is_debug=false

gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64"' is_debug=false

这里可能会出现 code signing 的问题:

Automatic code signing identity selection was enabled but could
not find exactly one code signing identity matching
iPhone Developer. Check that your keychain
is accessible and that there is a valid code signing identity
listed by `xcrun security find-identity -v -p codesigning`
TIP: Simulator builds don't require code signing...
ERROR at //build/config/ios/ios_sdk.gni:142:7: Assertion failed.
assert(false)

增加一个ios_enable_code_signing=false参数,禁用掉 code signing

gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64" ios_enable_code_signing=false' is_debug=false

编译

ninja -C out/ios_64 framework_objc

可能出现下面的情况:

ninja: Entering directory `out/ios_64'
[1/5] COPY_BUNDLE_DATA gen/sdk/framework_objc_info_plist.plist WebRTC.framework/Info.plist
FAILED: WebRTC.framework/Info.plist
rm -rf WebRTC.framework/Info.plist && /bin/cp -Rc gen/sdk/framework_objc_info_plist.plist WebRTC.framework/Info.plist
cp: WebRTC.framework/Info.plist: clonefile failed: Operation not supported
ninja: build stopped: subcommand failed.

这个问题是因为cp命令不能包含c参数,通过搜索"&& /bin/cp -Rc"找到位置,删除c即可,重新允许编译命令即可。