-
Notifications
You must be signed in to change notification settings - Fork 109
How to build webrtc library for Android in OSX host
Since Android build requires a GNU/Linux host, but I needed to use my OSX machine, I decided to use 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 #16765. Here goes:
- Install vagrant to OSX
- Create a vagrant VM:
# Didn't work on this vm, used "bento/ubuntu-18.04" instead
$ 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
# This didn't work for me, the link is not working I used this:
# Download the latest script to install the android dependencies for ubuntu
# curl https://chromium.googlesource.com/chromium/src/+/master/build/install-build-deps-android.sh?format=TEXT | base64 -d > install-build-deps-android.sh
# curl https://chromium.googlesource.com/chromium/src/+/master/build/install-build-deps.sh?format=TEXT | base64 -d > install-build-deps.sh
# chmod u+x ./install-build-deps.sh
#use bash (not dash which is default) to run the script
sudo /bin/bash ./install-build-deps-android.sh
# 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
$ fetch --nohooks webrtc_android
$ gclient sync
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 all sources and dependencies are downloaded you can: generate ninja files with GN, do the build and create the webrtc library in .aar format all in one step using a pretty nifty script Google folks have developed:
$ cd src
$ tools-webrtc/android/build_aar.py
Once this finishes you will find libwebrtc.aar in the working directory. Notice that by default this .aar contains native libraries both for arm7 and x86, so you should be able to deploy on both device and emulator.
P.S. You can find the official Android build guide at https://webrtc.org/native-code/android/