WebRTC源码下载和编译

下载和编译步骤

1. GET DEPOT TOOLS

LINUX / MAC

Clone the depot_tools repository:

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

Add depot_tools to the front of your PATH (you will probably want to put this in your ~/.bashrc or ~/.zshrc). Assuming you cloned depot_tools to /path/to/depot_tools:

$ export PATH=/path/to/depot_tools:$PATH

2. 安装python 2.7

3. Download Source

Create a working directory, enter it, and run:

$ fetch --nohooks webrtc_android //会在当前执行目录中下载文件到src文件夹
$ gclient sync

4. preCompile

# 进入到src目录中
cd src # 执行完后,当前目录应为 /home/webrtc/webrtc_android/src
# 下载 java相关命令和包,以及其他一些必要的软件和包
build/install-build-deps-android.sh # 执行过程中要输入 sudo 密码

5. Compile

(需要在ubuntu英文语言环境下编译)

Generate projects using GN.

Make sure your current working directory is src/ of your workspace. Then run:

gn gen out/Debug --args='target_os="android" target_cpu="arm"'

Compile using:

autoninja -C out/Debug

其他注意点

  1. 无需通过fetch android下载chrome的android checkout,如果这么做,可能遇到错误:
error: RPC failed; curl 56 GnuTLS recv error (-9): A TLS packet with unexpected length was received.
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

此时需要更新git版本为官网最新版本,重试fetch android

  1. 下面的多个错误,原因是文件所在位置为macOS,必须放到ubuntu下,文件系统格式不同

OSError: [Errno 1] Operation not permitted

Error: Command ‘vpython src/build/download_nacl_toolchains.py –mode nacl_core_sdk sync –extract’ returned non-zero exit status 1 in /media/psf/Home/git/demo/webrtc/android

makelink Operation not permitted

Cannot utime: Operation not permitted

编译输出文件路径

…./webrtc_android/src/out/Debug/lib.java/sdk/android/libwebrtc.jar

…/webrtc_android/src/out/Debug/libjingle_peerconnection_so.so

…/webrtc_android/src/out/Debug/lib.unstripped/libjingle_peerconnection_so.so

…/webrtc_android/src/out/Debug/clang_x64/protoc

关于HackWebRTC native debug项目

https://github.com/HackWebRTC/webrtc/tree/hack_webrtc/sdk/android_gradle

该项目组在脚本中配置固定的文件路径导致无法在新版webrtc源码上编译

CMakeLists.txt

${WEBRTC_REPO}/sdk/libs/ffmpeg/lib/Android/${ANDROID_ABI}/libswresample.a
  1. Libjingle_peerconnection_so.so位于项目项目webrtc/prebuild_libs/中
  2. 动态配置java source依赖目录
//        def newProjectRoot = "$webrtc_repo/sdk/android_gradle"
        def newProjectRoot = rootProject.rootDir

        sourceSets.main.java.srcDirs = [
                "$newProjectRoot/../android/api",
                "$newProjectRoot/../android/src/java",
                "$newProjectRoot/../../rtc_base/java/src",
                "$newProjectRoot/../../modules/audio_device/android/java/src",
                "$newProjectRoot/webrtc/src/main/java",
        ]
  1. androidCompileSdkVersion = 30
    
  2. 配置本地native调试目录:

# the absolute path of WebRTC Android checkout, please use exactly the same commit as this repo.
webrtc_repo=/Users/qianpianpian/git/demo/webrtc/webrtc_android/src
# the relative path of where generated source file is put, relative to `webrtc_repo`.
webrtc_build_dir=out/android_studio

# the relative path of Android sdk jar, relative to `webrtc_repo`.
android_jar=third_party/android_sdk/public/platforms/android-30/android.jar

# the absolute path of Python 2.x executable
py2=/usr/bin/python
# the absolute path of protoc executable, see README about how to create it.
protoc=/Users/qianpianpian/git/demo/webrtc/webrtcOut/protoc

参考

https://webrtc.googlesource.com/src/+/refs/heads/master/docs/native-code/android/index.md

Ubuntu18.04 从头开始编译 Android Native WebRTC

https://github.com/mail2chromium/Compile_WebRTC_Library_For_Android