Compile WebRTC under Linux (Linux and Android version)

created at 12-25-2021 views: 8

Install depot_tools

git clone to get depot_tools

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

Configure the path of `depot_tools` to environment variables

echo "export PATH=$PWD/depot_tools:$PATH"> ~/.bashrc
source ~/.bashrc

Download webrtc source code

From here on, there is a difference between the commands of the Linux and Android versions.

Linux version

mkdir webrtc
cd webrtc
fetch --nohooks webrtc
gclient sync

Android version

mkdir webrtc
cd webrtc
fetch --nohooks webrtc_android
gclient sync

The latest source code is downloaded by default. If you want to switch to the specified branch, you can use the following command:

# View available version branches
git branch -r
# Switch to m79 branch
git checkout branch-heads/m79
gclient sync
# Or forcibly switch to the specified commit (b484ec0082948ae086c2ba4142b4d2bf8bc4dd4b is the last commit id submitted by m79)
gclient sync -r b484ec0082948ae086c2ba4142b4d2bf8bc4dd4b --force

Install and compile dependencies

After obtaining the webrtc source code, several scripts need to be executed to install the compilation dependencies.

Linux version

cd src
./build/install-build-deps.sh

Android version

cd src
./build/install-build-deps.sh
./build/install-build-deps-android.sh
source build/android/envsetup.sh

Compile

Linux version

By default, if Linux is compiled based on ninja, its compiler uses clang, and its dependent stdc standard library is built in ./buildtools/third_party/libc++, so if you want to compile based on clang If libwebrtc.a is developed, the upper layer still needs to use clang as the compiler and link with the libc++ standard library inside webrtc, otherwise various error: undefined reference to symbol … will be generated, which cannot be solved.

# clang compile x64 version
gn gen out/Release-clang --args='target_os="linux" target_cpu="x64" is_debug=false is_component_build=false rtc_include_tests=false rtc_build_examples=false'
ninja -C out/Release-clang
# gcc compile x64 version
gn gen out/Release-gcc --args='target_os="linux" target_cpu="x64" is_debug=false is_component_build=false use_sysroot=false is_clang=false use_lld=false treat_warnings_as_errors=false rtc_include_tests=false rtc_build_rttixx use_false_examples=false =true'
ninja -C out/Release-gcc
# gcc compile arm64 version (need to install compiling tools)
build/linux/sysroot_scripts/install-sysroot.py --arch=arm64
gn gen out/Release-arm64 --args='target_os="linux" target_cpu="arm64" is_debug=false is_component_build=false use_sysroot=false is_clang=false use_lld=false treat_warnings_as_errors=false rtc_include_tests=false rtc_build_rttixx use_false_examples=false =true'
ninja -C out/Release-arm64

After the compilation is successful, generate the static library-libwebrtc.a under the folder out/xxx//obj.

Android version

# Compile arm-v7 version
gn gen out/Release-arm-v7a --args='target_os="android" target_cpu="arm" is_debug=false rtc_include_tests=false rtc_build_examples=false'
ninja -C out/Release-arm-v7a
# Compile arm-v8 version
gn gen out/Release-arm-v8a --args='target_os="android" target_cpu="arm64" is_debug=false rtc_include_tests=false rtc_build_examples=false'
ninja -C out/Release-arm-v8a

After the compilation is successful, generate the jar package-libwebrtc.jar in out/xxx/lib.java/sdk/android, and generate the static library used by Android-libjingle_peerconnection_so.so in out/xxx.

You can also directly compile the aar package in Android:

./tools_webrtc/android/build_aar.py --build-dir out --arch "armeabi-v7a" "arm64-v8a"

After the compilation is successful, generate libwebrtc.aar in the /src directory, which contains the so of armeabi-v7a and arm64-v8a.

Extract all header files in the webrtc project

find . -maxdepth 1 -name "*.h" -exec cp --parents '{}' /home/xxx/workspace/webrtc/include ';' && find api audio base call common_audio common_video logging media modules p2p pc rtc_base rtc_tools sdk stats system_wrappers third_party video -name "*.h" -exec cp --parents '{}' /home/xxx/workspace/webrtc/include ';'
Please log in to leave a comment.