本文描述的是macOS下编译webRTC frmework的过程及编译过程中遇到的问题,并提供解决方案
步骤
-
安装depot_tools,配置环境变量
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git export PATH=$PATH:/Users/suntongmian/Documents/develop/webrtc/depot_tools
-
下载WebRTC源码
#cd 到希望放置源代码的目录 执行以下命令 fetch --nohooks webrtc_ios #执行完毕上面命令后 gclient sync
-
编译WebRTC
gn gen out/ios --args='target_os="ios" target_cpu="arm64" is_debug=true' ninja -C out/ios framework_objc 或 gn gen out/ios --args='target_os="ios" target_cpu="arm64" is_debug=true' python tools_webrtc/ios/build_ios_libs.py --bitcode #执行完毕后可以在src/out/ios目录中看到生成的项目工程
问题记录
1. Exception: No 10.12+ SDK found
Traceback (most recent call last):
File "/Users/zhouyongchao/Documents/WorkingSpaces/webrtc_build/webrtc/src/build/mac/find_sdk.py", line 127, in <module>
print(main())
File "/Users/zhouyongchao/Documents/WorkingSpaces/webrtc_build/webrtc/src/build/mac/find_sdk.py", line 96, in main
raise Exception('No %s+ SDK found' % min_sdk_version)
Exception: No 10.12+ SDK found
解决方案:
- 通过命令
xcrun --show-sdk-version
可以知道当前SDK的版本 - 修改
.gn
文件的mac_sdk_min
选项为当前系统版本:如:11.0
- 打开
find_sdk.py
阅读代码发现了只支持10.xx
的系统,修改11
即可
2. LASTCHANGE.committime
Traceback (most recent call last):
File "/Users/zhouyongchao/Documents/WorkingSpaces/webrtc_build/webrtc/src/build/compute_build_timestamp.py", line 127, in <module>
sys.exit(main())
File "/Users/zhouyongchao/Documents/WorkingSpaces/webrtc_build/webrtc/src/build/compute_build_timestamp.py", line 113, in main
last_commit_timestamp = int(open(lastchange_file).read())
IOError: [Errno 2] No such file or directory: '/Users/zhouyongchao/Documents/WorkingSpaces/webrtc_build/webrtc/src/build/util/LASTCHANGE.committime'
解决方案:
在src目录执行./build/util/lastchange.py build/util/LASTCHANGE
3. gn gen out/ios --args='target_os="ios" target_cpu="arm64" is_debug=true'报错
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...
解决方案:
- 打开
src/build/config/ios/ios_sdk.gni
文件,把ios_code_signing_identity_description="iPhone Develoer"
修改为ios_code_signing_identity_description="Apple Development"
- 如果方法1不生效,可以尝试把命令更改为
gn gen out/ios --args='target_os="ios" target_cpu="arm64" is_component_build=false ios_enable_code_signing=false' --ide=xcode
编译APP报错
/bin/sh: ../../third_party/llvm-build/Release+Asserts/bin/clang++: No such file or directory
解决方案:手动到官网https://commondatastorage.googleapis.com/chromium-browser-clang/index.html下载clang++,放到相应的文件夹(src/third_party/llvm-build/Release+Asserts)
下面,注意clang++和macOS的版本对应问题
代码报错 set but not used [-Werror,-Wunused-but-set-variable]
variable 'zeroGainLvl' set but not used [-Werror,-Wunused-but-set-variable]
原因:这只是警告,只是clang++编译器将警告当作了错误输出
解决方案:
进入`build/config/compile/BUILD.gn`文件中,将`treat_warnings_as_errors`置为false
网友评论