- 安装 depot_tools
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
把 depot_tools 加入环境变量
export PATH=`pwd`/depot_tools:"$PATH"
- clone 源代码
创建一个文件夹用来存放 WebRTC 源代码,比如 mkdir ~/webrtc, 进入刚才创建的文件夹执行
fetch --nohooks webrtc_ios
gclient sync
然后就是漫长的等待中...
完全 sync 完成后会在 webrtc 目录下生成一个 src 目录,进入 src 目录会看到类似 https://chromium.googlesource.com/external/webrtc/+/master 这个样的目录,只不过多了 third-party 的一些依赖文件, branch 57 之后 sync 很快哦
- 编译 framework
运行命令 gclient runhooks
进入 src 目录,然后执行
./tools_webrtc/ios/build_ios_libs.py
就可以编译出 framework 文件了。
可以通过 ./tools_webrtc/ios/build_ios_libs.py --help
查看编译选项
默认会编译出全部架构的 ['arm64', 'arm', 'x64', 'x86'] 的 framework 文件,如果想要编译成静态库也可以加上 -b static_only
,如果只想编译 ARM 的架构可以 ./tools_webrtc/ios/build_ios_libs.py --arch {'arm64','arm'}
(老版本的目录为 tools-webrtc)
- 使用 Xcode 查看和编译 WebRTC 源码
WebRTC 不支持 Xcode 原生编译,用 Xcode 编译也是调用的 ninja 去编译
先生成 workspace 文件,还是进入上面提到的 src 的目录
gn gen out/ios --args='target_os="ios" target_cpu="arm64" is_component_build=false' --ide=xcode
打开工程文件,就可以编译和查看源码了
open -a Xcode.app out/ios/all.xcworkspace
-
代码更新
以后更新 webrtc 代码只需要进入 src 目录git pull
就行, 定期的更新依赖,使用gclient sync
-
有不能编译成功的可以留言哦 😄
相关 App 碰碰 http://www.pengpeng.us
本文参考 https://webrtc.org/native-code
网友评论
-bash: gn: command not found
大佬,这种应该怎么解决呢
gn.py: Could not find gn executable at: /Users/mac/Desktop/copy/webrtc_ios/src/buildtools/mac/gn
Traceback (most recent call last):
File "./build_ios_libs.py", line 272, in <module>
sys.exit(main())
File "./build_ios_libs.py", line 194, in main
args.use_goma, gn_args, args.build_type == 'static_only')
File "./build_ios_libs.py", line 135, in BuildWebRTC
_RunCommand(cmd)
File "./build_ios_libs.py", line 81, in _RunCommand
subprocess.check_call(cmd, cwd=SRC_DIR)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python', '/Users/mac/Desktop/copy/webrtc_ios/src/third_party/depot_tools/gn.py', 'gen', '/Users/mac/Desktop/copy/webrtc_ios/src/out_ios_libs/arm64_libs', '--args=target_os="ios" ios_enable_code_signing=false use_xcode_clang=true is_component_build=false is_debug=false target_cpu="arm64" ios_deployment_target="9.0" rtc_libvpx_build_vp9=false enable_ios_bitcode=false use_goma=false enable_dsyms=true enable_stripping=true']' returned non-zero exit status 2
大神,这个log主要是什么错误引起的,需要怎么做呢
-bash: ./tools-webrtc/ios/build_ios_libs.py: No such file or directory ,ls 后是有对应文件的.我后面直接py文件拖到终端raceback (most recent call last):
File "./build_ios_libs.py", line 258, in <module>
sys.exit(main())......false use_goma=false enable_dsyms=true enable_stripping=true']' returned non-zero exit status 2的问题
Traceback (most recent call last):
File "/Users/mmj/Desktop/视频/depot_tools/fetch.py", line 299, in <module>
sys.exit(main())
File "/Users/mmj/Desktop/视频/depot_tools/fetch.py", line 293, in main
spec, root = run_config_fetch(config, props)
File "/Users/mmj/Desktop/视频/depot_tools/fetch.py", line 257, in run_config_fetch
spec['alias']['config'], spec['alias']['props'] + props, aliased=True)
File "/Users/mmj/Desktop/视频/depot_tools/fetch.py", line 245, in run_config_fetch
os.path.join(SCRIPT_PATH, 'fetch_configs', config))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 73, in join
path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 19: ordinal not in range(128)
问下楼主,我第一次安装好后编译不成功,后来我删除了重新编译结果报上面的错误~~
File "/Users/mmj/Desktop/sp/w/ship/depot_tools/gclient.py", line 2618, in <module>
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '('gclient', 'sync', '--nohooks', '--with_branch_heads')' returned non-zero exit status 1 ,,,,,,,,,,,,这安装也不对吧
报下面的错:
INFO:root:Building WebRTC with args: target_os="ios" ios_enable_code_signing=false use_xcode_clang=true is_component_build=false is_debug=false target_cpu="arm64" ios_deployment_target="8.0" rtc_libvpx_build_vp9=false enable_ios_bitcode=false use_goma=false enable_dsyms=true enable_stripping=true
Traceback (most recent call last):
File "/Users/tianjinfeng/Desktop/Projects/WebRTC/depot_tools/gn.py", line 38, in <module>
sys.exit(main(sys.argv))
File "/Users/tianjinfeng/Desktop/Projects/WebRTC/depot_tools/gn.py", line 33, in main
return subprocess.call([gn_path] + args[1:])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
Traceback (most recent call last):
File "./tools-webrtc/ios/build_ios_libs.py", line 253, in <module>
sys.exit(main())
File "./tools-webrtc/ios/build_ios_libs.py", line 175, in main
args.use_goma, args.extra_gn_args)
File "./tools-webrtc/ios/build_ios_libs.py", line 134, in BuildWebRTC
_RunCommand(cmd)
File "./tools-webrtc/ios/build_ios_libs.py", line 75, in _RunCommand
subprocess.check_call(cmd, cwd=WEBRTC_SRC_DIR)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
在终端:
chmod+x src/buildtools/mac/gn
即可解决:OSError: [Errno 13] Permission denied
参考链接:https://github.com/ChenYilong/WebRTC/blob/master/WebRTC%E5%9C%A8iOS%E7%AB%AF%E7%9A%84%E5%AE%9E%E7%8E%B0/WebRTC%E5%9C%A8iOS%E7%AB%AF%E7%9A%84%E5%AE%9E%E7%8E%B0.md
谢谢回复!
INFO:get_syzygy_binaries.py:Output directory does not exist, skipping cleanup.
________ running '/usr/bin/python src/third_party/instrumented_libraries/scripts/download_binaries.py' in '/Users/ios-bulixin'
ios-bulixindeMac-mini:~ ios-bulixin$
今天下载到这里下载停止了,简主,遇到过吗