WebRTC源码下载及编译(Ubuntu20.04)

一、环境准备

1.1 win10主机+虚拟机(Ubuntu20.04,建议硬盘可用空间40G以上)

bash 复制代码
$ cat /etc/issue
Ubuntu 20.04.5 LTS

1.2 网络配置(虚拟机借助主机的VPN来访问外网)

  1. 主机开启VPN网络
  2. 虚拟机网络配置为NAT模式
  3. 在主机上执行ipconfig查看vnet8的IP,查看vpn软件使用的端口
  4. 在ubuntu系统中配置网络代理,代理的IP和端口为步骤3中的IP和端口
  5. 主机开启vpn后,在虚拟机中浏览器中输入www.google.com可以打开即表示可以访问外网
  6. git 配置代理的IP和端口(步骤4中的IP和端口)
bash 复制代码
rtc@ubuntu:~$ cat ~/.gitconfig
[http]
	proxy = IP:PORT
[https]
	proxy = IP:PORT

二、下载流程

2.1 安装depot_tools工具,WebRTC使用depot工具管理和下载源码

  • 下载工具
bash 复制代码
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
  • 添加depot_tools到系统的环境变量PATH
    方法1: 在终端直接设置环境变量
    export PATH=$PATH:/path/to/depot_tools
    方法2:添加到~/.bashrc文件结尾,重新打开终端即可
bash 复制代码
 export PATH=$PATH:/path/to/depot_tools
  • 增加权限
bash 复制代码
 chmod 777 depot_tools -R
  • 验证测试
    终端输入fetch命令,如果提示找不到,则说明depot工具没有配置成功
bash 复制代码
$ fetch
usage: fetch.py [-h] [-n] [--nohooks] [--nohistory] [--force] [-p PROTOCOL_OVERRIDE] config ...
fetch.py: error: the following arguments are required: config, props

2.2 新建存储WebRTC源码的目录

bash 复制代码
   mkdir webrtc-checkout
   cd webrtc-checkout

2.3 使用fetch命令下载源码

fetch --nohooks webrtc

2.4 执行第3步后,如果报网络等异常断开情况时,需要用gclient sync继续下载

bash 复制代码
gclient sync

2.5 建立编译依赖

bash 复制代码
   cd src
   ./build/install-build-deps.sh

2.6 使用gn生成编译配置

bash 复制代码
gn gen out/Default

2.7 使用ninja编译代码

bash 复制代码
 ninja -C out/Default

编译完成会在out/Default目录下生成很多文件(包括各种库等)

三 问题及解决方法:

3.1 下载过程中出现以下问题

bash 复制代码
0:00:00] Started.
----------------------------------------
Traceback (most recent call last):
  File "/home/rtc/Project/office/depot_tools/metrics.py", line 302, in print_notice_and_exit
    yield
  File "/home/rtc/Project/office/depot_tools/gclient.py", line 4638, in <module>
    sys.exit(main(sys.argv[1:]))
             ^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient.py", line 4624, in main
    return dispatcher.execute(OptionParser(), argv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/subcommand.py", line 254, in execute
    return command(parser, args[1:])
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient.py", line 3977, in CMDsync
    ret = client.RunOnDeps('update', args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient.py", line 2436, in RunOnDeps
    work_queue.flush(revision_overrides,
  File "/home/rtc/Project/office/depot_tools/gclient_utils.py", line 1026, in flush
    reraise(e[0], e[1], e[2])
  File "/home/rtc/Project/office/depot_tools/gclient_utils.py", line 53, in reraise
    raise value
  File "/home/rtc/Project/office/depot_tools/gclient_utils.py", line 1105, in run
    self.item.run(*self.args, **self.kwargs)
  File "/home/rtc/Project/office/depot_tools/gclient.py", line 1251, in run
    self._got_revision = self._used_scm.RunCommand(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient_scm.py", line 137, in RunCommand
    return getattr(self, command)(options, args, file_list)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient_scm.py", line 664, in wrapper
    return_val = f(*args)
                 ^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient_scm.py", line 866, in update
    strp_current_url = current_url[:-4] if current_url.endswith(
                                           ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'endswith'
  • 问题原因:git版本过低
  • 解决方法:升级git版本

升级前:

bash 复制代码
git --version
git version 2.25.1

升级后:

bash 复制代码
$ git --version
git version 2.46.1

升级流程:

  • 方法一: 直接安装更新
bash 复制代码
sudo apt-get install git
  • 方法二: 如果没更新,需要添加源
bash 复制代码
sudo add-apt-repository ppa:git-core/ppa

sudo apt update

sudo apt-get install git

四 其它说明

  1. 国外源码下载需要VPN支持,稳定、速度快的VPN能更快的下载代码
  2. 源码大小24G左右,下载前需要确认硬盘可用空间大小和VPN流量限制问题
bash 复制代码
rtc@ubuntu:~/Project/office/webrtc-checkout$ du -sh src
  24G	src
  1. 出现下载异常中断时,查明原因并解决后,可以通过gclient sync继续下载
  2. 声网提供的国内镜像下载源,在没有VPN时,可以尝试下面链接中的方法
bash 复制代码
https://webrtc.org.cn/mirror/
相关推荐
西木九1 小时前
记录:ubuntu20.04的安装和必要的开发准备
ubuntu·ubuntu20.04
太上绝情4 小时前
webrtc-candidate形成分析
webrtc
Jtti4 小时前
如何在Ubuntu上查看和刷新DNS缓存
linux·ubuntu·缓存
Shine.Zhang4 小时前
ubuntu server设置wifi和静态IP
tcp/ip·ubuntu
FHKHH16 小时前
ubuntu使用Vscode进行实现UDP编程
vscode·ubuntu·udp
寻爱的希斯克利夫18 小时前
jenkins 部署到tomcat
ubuntu·servlet·tomcat·jenkins
FHKHH20 小时前
计算机网络第二章:作业 2: UDP ping 程序
运维·服务器·vscode·计算机网络·ubuntu·udp
new_abc1 天前
ALSA ubuntu 编译
linux·ubuntu
-Harvey1 天前
ubuntu 自带截图快捷键
ubuntu·截屏·截图