webrct

WebRTC name comes from the abbreviation of Web Real-Time Communication, an API that supports real-time voice or video conversations in the browser. it was open-sourced on June 1, 2011 and included in the W3C standards with support from Google, Mozilla, Opera.

In this tutorial, I assume you are using Linux and understand webrtc and android development. android webrtc source code compilation is only supported under Linux. This includes how to install Chromium depot_tools development tool, check out Android webrtc source code using gclient, build webrtc .aar library, import .aar library into Android app project, and compile Android webrtc library manually.

Install Chromium depot_tools developer tools

First, we need to install the necessary tools, which include git, ninja build tools, gclient, gn, fetch, and other Google tools for developing Chromium. Installing these tools is a very simple process that requires only the following steps.

First we use the mkdir command to create the myfreax directory at home, then we switch to it using the cd command, and everything starts from there.

1
2
➜  myfreax mkdir ~/myfreax
➜  myfreax cd ~/myfreax

Next, we use the git command to clone the google chromium development tool and import the tool’s commands into the PATH environment variable.

1
2
➜  myfreax git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
➜  myfreax export PATH=$PATH:$HOME/myfreax/depot_tools

Now google chromium development tools are available in the current terminal.

Clone and check out Android webrtc source code

Before getting webrtc source code please use mkdir command to create a directory to store webrtc source code, we recommend to put this in a partition with 16GB free space. Because the source code contains Android SDK+NDK image. Next, use the fetch command included in google chromium development tools to clone the Android webRTC source code to local.

1
2
➜  myfreax fetch --nohooks webrtc_android
➜  myfreax gclient sync

This process can take a long time as it requires the android build chain tool, which is about 16GB

Then use the cd command to switch to the webrtc_android/src/ directory and install the build source dependencies with the following command.

1
➜  myfreax ./build/install-build-deps.sh

It is worth noting here that you need to make sure you have openjdk installed and configured on your computer.

Before compiling the source code, we recommend creating your own local branch to ensure that you do not modify the code on the master branch, and that you can continue to check out the source code on the master branch if there are incorrect changes.

1
2
➜  myfreax git checkout main 
➜  myfreax git new-branch your-branch-name

Compile Android WebRTC source code

There are two ways to compile Android webrtc source code here, manually and with python build_aar.py script. Let’s start with the easy way, here thanks to webRTC developers for contributing python scripts.

Compile with AAR build tool

First use cd command to switch to Android webrtc source directory, next execute python build script tools_webrtc/android/build_aar.py for aar library.

1
➜  myfreax tools_webrtc/android/build_aar.py

It will compile the source code and support all CPU types, including arm64-v8a, armeabi-v7a, x86, x86_64 architectures, and package the native dynamic libraries libjingle_peerconnection_so.so and .jar libraries into the libwebrtc.aar file.

The compiled libwebrtc.aar file is usually stored in the current working directory or src/ directory. If you are following every step of our tutorial, theoretically you will find the libwebrtc.aar file in the src/ directory.

Finally you can add the aar library to the project or publish it to the maven repository.

Manual compilation

Manual compilation allows you to specify the CPU architecture type, which may be faster by using the AAR build tool, but requires you to package the .jar library and the native dynamic libraries into .aar files yourself. First generate the project using the gn command.

for debug

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

for release

1
➜  myfreax gn gen out/Release --args='is_debug=false is_component_build=false rtc_include_tests=false target_os="android" target_cpu="arm"'

The output directory of this command is out/Debug or out/Release, and the target CPU architecture is arm64. Next, use the ninja command to start compiling the source code.

1
➜  myfreax ninja -C out/Debug

The compilation time may be very long, depending on your computer’s performance. The compiled result is output to the out/Debug or out/Release directory, the native .so file can be found in the lib.unstripped/ directory and the java .jar library file is located in the lib.java/ directory, you will need to manually package both files into the .aar library yourself.

Conclusion

You have known how to install Chromium depot_tools developer tool, check out Android webrtc source code, build webrtc .aar library, import .aar library into Android app project, and compile Android webrtc library manually. If you need more detailed information please refer to official documentation.