How To Compile Native WebRTC Library from Source for Android

Aris R
4 min readApr 2, 2019



In this article I assume you use Linux and understand about webrtc, and android development, please consider reading those before continuing if you feel not comfortable.

Install Prerequisite (Chromium depot_tools)

First we need to setup all tools we need, which is depot_tools, it includes custom git binary, ninja build tools, gclient, gn, fetch etc.

It is quite easy, clone the repository from then add the local cloned repository into the PATH environment variables.

git clone

add into PATH environment variables, so the binary included in the repository would be available in the terminal (command line).

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

head over to this link for more information.

Getting The Source Code

Use fetch command to get the webrtc source code for android, before done this you may want to go over another or new directory to place the source code in.

fetch --nohooks webrtc_android


gclient sync

After that go to webrtc_android/src/ directory, which is just created by the command above.

The process may take long because it require the android build chain tools, it is around 16GB checkout.

Then you need to install all the dependency needed to build the source code.



Also make sure you have OpenJDK installed and configured properly on your machine (I used version OpenJDK 1.8)

Before compiling the code you can checkout to particular git branch to go into different available webrtc version, to list all the branch use this git command.

git branch -r

Output is something like below

output: git branch -r

Like the above result you can checkout to the latest version which is m74 by.


There is changes for the branch name after chromium m79, rather being refs/branch-heads/m$MILESTONE branches will now be refs/branch-heads/$BRANCH_NUMBER.!topic/discuss-webrtc/JR7fsoEuqw0 — chromium branches

git checkout branch-heads/m74

To check what is your current branch type in.

git branch
output: git branch


There are two ways I have tried out to compile webrtc for android, here are those two starting with the most easy way (Thanks to great developers & contributors of webrtc).

Using AAR build tools


It would compile the source code for all supported cpu type such as arm64-v8a, armeabi-v7a, x86, x86_64 and then package these native libraries and .jar library into .aar file.

output: compilation

.AAR file resides in your current working directory or src/ directory with default name libwebrtc.aar

Finally you can use the aar library in your project, or publish it into maven repository.

Manual Compilation

Manually compile the source code for each particular cpu type.

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

for release

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

the output is in the out/Debug or out/Release (directory name is arbitrary), target_cpu can be arm64, x86 or x64.

begin compiling with ninja (output directory out/Debug or out/Release as explain above).

ninja -C out/Debug

compilation may take long depending on how powerful your machine. output of compilation is in the out/Debug or out/Release directory, native .so file is in the lib.unstripped/, and the java .jar library is directory.

native .so library is unstripped you can strip to minimize file size using strip tools for particular cpu type such tool is located in webrtc_android/src/third_party/android_ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip (for x64 binary .so).

With manual compilation you also need to package all these library into .aar manually.

Manually compiling from the source code is quite challenging and tedious in my opinion and fortunately thanks to webrtc developers/contributors who made the build script for packaging into .aar library much more easier, for more information visit



Aris R

Computer Science / Android Development (Java/Kotlin) / Go / WebRTC —