Building WebRTC libraries for Android

January 25, 2015

WebRTC (Web Real-Time Communication) is a JavaScript API to support Audio/Video/Data communication between web application clients – e.t. making each browser into Skype-like video conferencing endpoint. At this time (January 2015) it still not yet fully standardized and supported mostly by Chrome (Google) and  Firefox (Mozilla) but not by IE (Microsoft) or Opera (Apple) .

Support for mobile browsers on Android had been introduced just recently and still not available on Android 4.x which run majority of devices in use. Fortunately,  WebRTC offers a way to build a native WebRTC application on Android ( as well as on iOS). Indeed, WebRTC core is written in C and includes a binding layer for JavaScript. Similar binding had been written for  Android Java and few code examples are offered as part of WebRTC open source code.

Get ARM-ready libraries.

Unfortunately, WebRTC build process is quite tedious and require special building tools on Linux host. So I decided to pre-build WebRTC libraries to share with those who have no patience to build themself (see details of building process below).

You can get  WebRTCDemo and AppRTCDemo source code and its ARM-build binary libraries from GitHub now. Those projects are ready to be modified and recompiled in any environment with appropriate Android SDK set up ( compilation required platform >21 , e.t. Android 5.0 LOLLIPOP, but application can run on Android 4.x as well). I’ll try to keep up with WebRTC development and try re-build those projects at least once a month.

 WebRTC native code building process.

This is useful for you only if you decide to rebuild WebRTC native libraries for Android. The process based on excellent blogs by Simon & Orcaman, with some additions found in the recent code.

First of all you need Ubuntu host – I setup a naked distribution of Ubuntu 14.04 LTS on top of VirtualBox.  Installation process itself is straight forward one, but install, don’t forget to instal VirtualBox additions (see good instructions) – makes your life much simpler.

And then execute:

# assuming we are starting from "virgin" Ubuntu installation
sudo apt-get install git
sudo apt-get install g++
sudo apt-get install subversion
sudo apt-get install git-svn
sudo apt-get install openjdk-7-jdk
sudo apt-get install ant
sudo apt-get install lib32stdc++6 lib32z1
#
# get google build tools
#
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"
#
# we'll need Java
#
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
#
# now we are setting our target for compilation
#
export GYP_DEFINES="OS=android"
#
# New home for WebCRT
#
mkdir WebCRT
cd WebCRT
#
# Time to pull sources ( including all dependencies derived from chromium project)
# will take quite a time
#
fetch webrtc_android
#
# Now time to build
#
cd src
#
# setup Android cross compiler build environment
#
. build/android/envsetup.sh
export GYP_DEFINES="build_with_chromium=0  $GYP_DEFINES"
export GYP_DEFINES="build_with_libjingle=1 $GYP_DEFINES"
export GYP_DEFINES="libjingle_java=1 $GYP_DEFINES"
# send WEBRTC_LOGGING to Android's logcat
export GYP_DEFINES="enable_tracing=1 $GYP_DEFINES"
#
# Generate .ninja files
#
gclient runhooks
#
# and now is an actual build....
#

#
# Build AppRTCDemo application – demonstrates interoperability of native Android
# client and Chrome JavaScript client.
# source code / project root : src/talk/examples/android/
# resulting APK : src/out/Debug/AppRTCDemo-debug.apk
#
ninja -C out/Debug AppRTCDemo

#
# Build WebRTCDemo application – exchange video+audio between two
# android clients.
# source code / project root : src/webrtc/examples/android/media_demo/
# resulting APK : src/out/Debug/WebRTCDemo-debug.apk
#
ninja -C out/Debug WebRTCDemo

References:

  1. Official WebRTC Android page
  2. AppRTCDemo application build and run instructions 
  3. WebRTCDemo application build and run instructions
  4. Source code of WebRTC Java wrapper
  5. WebRTC Build Scripts

Leave a Reply

Your email address will not be published. Required fields are marked *


*