-
Notifications
You must be signed in to change notification settings - Fork 111
How to build webrtc library for Android in OSX host
Once again I found myself spending a lot of time getting the Webrtc library build to work. Let me record my experience here in hopes of helping the Webrtc community.
Since Android build requires a GNU/Linux host I used Vagrant to make setup as easy and reusable as possible and be able to share the actual repo with ease between host and guest. First off a big thanks to the pristineio folks and their build scripts I've borrowed a lot of know-how from that but I present here a more low-level approach using directly Google's toolbox.
For reference I'm building revision #13972. Here goes:
- Install vagrant to OSX
- Create a vagrant VM:
$ vagrant init hashicorp/precise64
- Edit the Vagrant file. Mine looks like this (notice the important part in the end where the base dependencies are installed; this is executed right after the VM is bootstrapped):
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "hashicorp/precise64"
config.ssh.forward_agent = TRUE
config.vm.provider "virtualbox" do |vb|
vb.memory = 4096
vb.cpus = 2
end
config.vm.network "private_network", ip: "192.168.50.5"
config.vm.synced_folder ".", "/vagrant", type: :nfs
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision "shell", inline: <<-SHELL
sudo apt-get update
sudo apt-get -y install wget git gnupg flex bison gperf build-essential zip curl subversion pkg-config libglib2.0-dev libgtk2.0-dev libxtst-dev libxss-dev libpci-dev libdbus-1-dev libgconf2-dev libgnome-keyring-dev libnss3-dev
# Download the latest script to install the android dependencies for ubuntu
curl -o install-build-deps-android.sh https://src.chromium.org/svn/trunk/src/build/install-build-deps-android.sh
# Use bash (not dash which is default) to run the script
sudo /bin/bash ./install-build-deps-android.sh
# Delete the file we just downloaded... not needed anymore
rm install-build-deps-android.sh
SHELL
end
- Bring up the virtual machine (this will take some time as dependencies are also installed) and connect to it:
$ vagrant up
$ vagrant ssh
- Now that you are logged in to the VM, download more prerequisites for the build (remember that since vagrant is setup to mount a directory in the host system, the webrtc repository will be accessible in both host and guest, which is very handy for re-use, etc):
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=`pwd`/depot_tools:"$PATH"
- Download the webrtc checkout:
$ mkdir webrtc-checkout
$ cd webrtc-checkout
$ export GYP_DEFINES="OS=android include_tests=0"
$ fetch --nohooks webrtc_android
$ gclient sync
GYP_DEFINES
define the kind of build, in our case meant for android, also we are including include_tests=0
to avoid including tests that we don't need and which makes the whole process faster. fetch
takes into account the GYP_DEFINES, generates a .gclient file and fetches the webrtc sources (without dependencies, which is what --nohooks does if I'm not mistaken) and can only be ran once; the first time. gclient sync
seems to fetch the chromium sources along with all webrtc/chromium dependencies, which is why it takes so long.
There's a chance that during the sync above a license needs to be accepted by entering input in the command line. If you miss that then the sync will break because license wasn't accepted and hence google play services that are needed weren't installed. If that happens try:
$ src/build/android/play_services/update.py download
And then again:
$ gclient sync
Now that everything is synced you can start the build (notice that gyp
is getting replaced with gn
at the time of this writting):
$ cd src/
$ gn gen out/Default --args='target_os="android" target_cpu="arm"'
$ ninja -C out/Default
Once the build finishes, the libraries (remember that for Android there are two libraries: the native library libjingle_peerconnection_so.so
and the java wrapper libjingle_peerconnection_java.jar
which you both need) should be placed at:
- out/Default/lib.unstripped/libjingle_peerconnection_so.so
which is the DEBUG native build (around ~130 Mb) and
out/default/libjingle_peerconnection_so.so` which is the stripped build (around ~6 Mb) - out/Default/lib.java/webrtc/api/libjingle_peerconnection_java/libjingle_peerconnection_java.jar`
$ cd webrtc-checkout/src
$ export GYP_DEFINES="OS=android include_tests=0"
$ git pull
$ gclient sync
$ gn gen out/Default --args='target_os="android" target_cpu="arm"'
$ ninja -C out/Default
For a nice description of the build system steps used above you can refer to @agouaillard's post at http://webrtcbydralex.com/index.php/2015/07/18/the-chromium-webrtc-build-system/
Also, you can find the Android build guide at https://webrtc.org/native-code/android/