WebRTC on Android (Part 1 — Building)

Silvestr Predko
3 min readJun 14, 2017

--

Hello, fellas!) I want to start the cycle of posts about WebRTC on Android because for now, we have a lack information about the usage of this technology.

First of all, we need to build .so and .jar libraries. In official documentation is fully described how to download and build sources, but only for Linux. If you are using Linux just skip step — 1.

Step — 1 : Setup VirtualBox and Vagrant

You need to start from downloading VirtualBox and setup Vagrant. Here is a complete tutorial how to do that. Attention! You need to set 6 GB of RAM and at least 32 GB of disk space for your VirtualBox. Also for the box, better is using Ubuntu.

Step — 2 : Install required software

You need the latest version of git client and python. Also you need JDK.

Step — 3 : Install depot_tools and download sources of WebRTC

Here is tutorial how to install depot_tools(choose for Linux or Mac). Then create directory and enter it. Type the next commandsfetch --nohooks webrtc_android.

Then type gclient sync

After downloading sources you need to install required software for building libraries(.so and .jar). Enter to src directory and execute next script ./build/install-build-deps.sh

Step — 4: Compiling

In this step we compile proper .so library. Enter to src directory(src directory located in directory that you recently created for sync) and type

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

This is tells for build system that we want .so library for arm architecture.Then type ninja -C out/Debug and wait...

Also you can specify a directory of your own choice instead of out/Debug, to enable managing multiple configurations in parallel.

  • To build for ARM64: use target_cpu="arm64"
  • To build for 32-bit x86: use target_cpu="x86"
  • To build for 64-bit x64: use target_cpu="x64"

After successful compilation enter to out/Debug. You will see a lot of stuff, but we need only this things:

libjingle_peerconnection_so.so lib.java/webrtc/sdk/android/libjingle_peerconnection_java.jar
lib.java/webrtc/modules/audio_device/audio_device_java.jar

Step — 5: Add libraries to project

In your project in app folder create a folder and name it “jniLibs” then inside create a folder with name “armeabi-v7a”, put inside libjingle_peerconnection_so.so. Also you need to do some modifications to gradle file.

android {
...
sourceSets {
main {
// let gradle pack the shared library into apk
jniLibs.srcDirs = ['jniLibs']
}
}
}

Also you need to add lib.java/webrtc/sdk/android/libjingle_peerconnection_java.jar and lib.java/webrtc/modules/audio_device/audio_device_java.jar to your project.

In the next part I explain theory of WebRTC.

Thanks))).

--

--