Apple M1芯片中编译WebRTC

环境

设备: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开发实战》

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值