DEV Community

Cover image for WebRTC For Beginners - Part 5.5: Building the WebRTC Android Library
Ethan
Ethan

Posted on • Updated on • Originally published at ethan-dev.com

WebRTC For Beginners - Part 5.5: Building the WebRTC Android Library

Contents:

  1. Part 1: Introduction to WebRTC and creating the signaling server Link
  2. Part 2: Understanding the MediaDevices API and getting access to the user’s media devices Link
  3. Part 3: Creating the peers and sending/receiving media Link
  4. Part 4: Sharing and sending the user’s display and changing tracks Link
  5. Part 5: Data Channels basics Link
  6. Part 5.5: Building the WebRTC Android Library Link
  7. Part 6: Android native peer
  8. Part 7: iOS native peer
  9. Part 8: Where to go from here

Hello Again, sorry for the wait! Just thought I'd seperate the Android tutorial and the WebRTC Android build tutorial.

I tried using the prebuilt libraries from:
https://webrtc.github.io/webrtc-org/native-code/android/

But that didn't work so I decided to build it from scratch.
After trying for hours to build it on Arch Linux and failing I then found out you can only build Android on the following OS's:

ERROR: The only supported distros are
    Ubuntu 14.04 LTS (trusty with EoL April 2022)
    Ubuntu 16.04 LTS (xenial with EoL April 2024)
    Ubuntu 18.04 LTS (bionic with EoL April 2028)
    Ubuntu 20.04 LTS (focal with Eol April 2030)
    Ubuntu 20.10 (groovy)
    Debian 10 (buster) or later
Enter fullscreen mode Exit fullscreen mode

Hopefully you don't make the same mistake I did. Hopefully the future me won't make the same mistake either! 😅

Here I will show you how to build the Android library from scratch, I will show how to implement it into your own project next part.

Well then let's build the native Android WebRTC Library! Don't forget to check the OS your building on! 🤧


Setting up depot_tools

First we need to get the tools needed to build the library, this can be done via the following:

mkdir webrtc && cd webrtc

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=/path/to/depot_tools:$PATH
Enter fullscreen mode Exit fullscreen mode

Here we get the tools required to build the android library(and ios) and set the path.


Obtaining the WebRTC Android source

Next we need to get the WebRTC Android source and sync.

fetch --nohooks webrtc_android
gclient sync
Enter fullscreen mode Exit fullscreen mode

Once we have the source we can update to the latest source via the following:

cd src
git checkout main
git pull origin main
gclient sync
Enter fullscreen mode Exit fullscreen mode

As far as I'm aware sync must be done after and source updates.

Next we need to install the dependencies needed to build the libarary.

./build/install-build-deps.sh
Enter fullscreen mode Exit fullscreen mode

Finally build the WebRTC Android library.
This part may take some time to complete so grab your favorite beverage and relax. 🍸

./tools_webrtc/android/build_aar.py 
Enter fullscreen mode Exit fullscreen mode

Once done you should see the "libwebrtc.aar" file in the src directory.


TLDR

You can get the WebRTC Android library here:
https://github.com/ethand91/android_libwebrtc

Feel free to use it. 😎

That concludes this small part, hopefully this is helpful to you.


Like me work? I post about a variety of topics, if you would like to see more please like and follow me.
Also I love coffee. 😊

“Buy Me A Coffee”

Top comments (6)

Collapse
 
shyzam1 profile image
Shyam Maisuria

Hey Ethan. Thanks for this wonderful tutorial. I was hoping if there is Part6: Android native peer and Part7: iOS native peer tutorials?

Collapse
 
ethand91 profile image
Ethan

Yes Part 6 is still in the works! :)
Would love to do Part 7, but my mac broke recently.

Collapse
 
shyzam1 profile image
Shyam Maisuria

Btw if you could just guild me to some materials that I can use to compile libwebrtc for iOS. That would be really helpful.

Thread Thread
 
ethand91 profile image
Ethan
Thread Thread
 
shyzam1 profile image
Shyam Maisuria

Thank you :)

Collapse
 
ethand91 profile image
Ethan

Bookmarking my own post, so future me doesn't forget!