参考:https://webrtc.github.io/webrtc-org/native-code/development/prerequisite-sw/
目的
做webrtc有些功能不能满足现有需求的,需要扩展源码,修改源码之后需要重新编译,生成各个Android平台所需的包
Android 使用webrtc需要两个包 libwebrtc.aar 和 libjingle_peerconnection_so.so,这两个都是编译自动生成的
1、安装depot_tools
//克隆源码
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
//配置路径
export PATH=/path/to/depot_tools:$PATH
配置完后输入gclient命令不报错说明安装成功
2、下载webrtc-Android 源码
fetch --nohooks webrtc_android //(很大,十几个G) , 必须linux, 最好找个香港或者国外的服务器,自己配置翻墙麻烦
gclient sync //用来同步checkout的,如果上次fetch没有完成就断了,第二次进来执行一下这个就可以继续下载
这个过程比较长
3、在src目录执行:./build/install-build-deps.sh
注意:注:需要安装python2.7,直接apt install python就可以
4、全量编译参数
gn gen out/release_arm --args='target_os="android" target_cpu="arm" is_debug=false rtc_include_tests=false rtc_libvpx_build_vp9=true symbol_level=0 proprietary_codecs=true treat_warnings_as_errors=false'
#out/build : 编译生成文件的目录,随意指定
#target_os : 编译目标平台 android ios 等
#target_cpu : CPU架构平台 arm arm64 x86 x64等
i#s_debug : Release模式或者Debug模式
5、编译
ninja -C out/release _arm
这步时间会比较长
6、生成aar
执行如下命令:
tools_webrtc/android/build_aar.py --build-dir out --arch "armeabi-v7a" --output "libwebrtc.aar"
–output设置输出目录
在out / armeabi-v7a 下面可以找到 libjingle_peerconnection_so.so
7、编译过程中遇到的问题
问题1:No such file or directory: ‘D:\code\webrtc\src\build\util\LASTCHANGE.committime’
解决:python build/util/lastchange.py build/util/LASTCHANGE
问题:ERROR at //webrtc.gni:118:22: Undefined identifier
rtc_use_pipewire = is_desktop_linux && use_sysroot
^---------------
See //BUILD.gn:17:1: whence it was imported.
import(“webrtc.gni”)
^------------------
解决:打开webrtc.gni去掉is_desktop_linux
问题2:ERROR at //build/config/sysroot.gni:64:7 (//build/toolchain/linux:clang_x64): Assertion failed.
assert(
^-----
Missing sysroot (//build/linux/debian_sid_amd64-sysroot). To fix, run: build/linux/sysroot_scripts/install-sysroot.py --arch=amd64
See //build/config/sysroot.gni:65:11:
exec_script("//build/dir_exists.py",
^-----------------------------------
This is where it was set.
See //build/config/gcc/BUILD.gn:8:1: whence it was imported.
import("//build/config/sysroot.gni")
^----------------------------------
See //build/config/BUILDCONFIG.gn:351:11: which caused the file to be included.
[ “//build/config/gcc:symbol_visibility_hidden” ]
解决:build/linux/sysroot_scripts/install-sysroot.py --arch=amd64
问题3:ninja: Entering directory `out/Default’
ninja: error: ‘…/…/resources/audio_processing/test/py_quality_assessment/noise_tracks/city.wav’, needed by ‘py_quality_assessment/noise_tracks/city.wav’, missing and no known rule to make it
**解决:这个是因为gclient sync没有成功,资源没有同步下来,有时候会卡在Hook那里,需要等待一会或者Ctrl+C后重新执行,成功后的结果是:
Running depot tools as root is sad.
Syncing projects: 100% (258/258), done.
Hook 'download_from_google_storage --directory --recursive --num_threads=10 --no _auth --quiet --bucket chromium-webrtc-resources src/resources' took 15.44 secs
Running hooks: 100% (23/23), done.