Proper way to build WebRTC for Android as a static library

1,162 views
Skip to first unread message

Jose Antonio Olivera Ortega

unread,
Jan 17, 2017, 5:34:25 AM1/17/17
to discuss-webrtc
Hi there!

I'd like to know what's the proper way to build WebRTC for Android as a static
library. I know I could use the `AppRTCMobile` target or other ones but what's the
proper one. For iOS I see there is even a script in the tree ([1]) and a target
`rtc_sdk_objc` for this. Is there something similar for Android?

Cheers,
jaoo.

[1] https://chromium.googlesource.com/external/webrtc/+/master/webrtc/build/ios/build_ios_libs.sh

Jose Antonio Olivera Ortega

unread,
Jan 17, 2017, 5:55:45 AM1/17/17
to discuss-webrtc
Hi there!

Found there is already a thread for this at https://groups.google.com/forum/#!topic/discuss-webrtc/W5P7Glao2fs. Sorry I did not find out this thread before posting.

Cheers,
jaoo

Jose Antonio Olivera Ortega

unread,
Jan 30, 2017, 11:25:02 AM1/30/17
to discuss-webrtc, kjell...@google.com
Hi there!

I am trying to build WebRTC statically and using it to build sort of Android
Java Library with no luck so far.

Actually I am able to build WebRTC successfully using different targets such
as `AppRTCMobile`, `libjingle_peerconnection{,_jni,_so,_java}`. I am not sure how
to create a libwebrtc.a static library properly though.

I have tried everything but when I build the JNI interface I hit a ton of link
errors because undefined references. Clearly I do not know how to create a valid
libwebrtc.a static library.

The way I create the libwebrtc.a static library is kind of tricky. Let's say
I use the `libjingle_peerconnection_jni` build target, then I create the graph
of the target by using ninja tool
(|ninja -C <OUT_DIR> libjingle_peerconnection_jni -t graph) and parse the output.
By parsing the output I have a list of the static libraries the target 'depends
on'. Then I use the ar tool to create my libwebrtc.a library.

So, my questions are the following ones:

i) Which would be the build target to build WebRTC in order to create a static
library later?
ii) What is the proper way to create this static library?

Cheers,
jaoo

PS. Adding +Henrik Kjellander

Jose Antonio Olivera Ortega

unread,
Jan 30, 2017, 3:13:54 PM1/30/17
to discuss-webrtc, kjell...@google.com
Hi there!


On Monday, 30 January 2017 17:25:02 UTC+1, Jose Antonio Olivera Ortega wrote:
Hi there!

I am trying to build WebRTC statically and using it to build sort of Android
Java Library with no luck so far.

Actually I am able to build WebRTC successfully using different targets such
as `AppRTCMobile`, `libjingle_peerconnection{,_jni,_so,_java}`. I am not sure how
to create a libwebrtc.a static library properly though.

I have tried everything but when I build the JNI interface I hit a ton of link
errors because undefined references. Clearly I do not know how to create a valid
libwebrtc.a static library.

I meant above that when I use the libwertc.a to build a JNI interface I am building I hit a ton of link
errors because undefined references


Henrik Kjellander

unread,
Jan 31, 2017, 8:28:05 AM1/31/17
to Jose Antonio Olivera Ortega, discuss-webrtc, sa...@webrtc.org
+sakal

On Mon, Jan 30, 2017 at 9:13 PM, Jose Antonio Olivera Ortega <josea....@gmail.com> wrote:
Hi there!

On Monday, 30 January 2017 17:25:02 UTC+1, Jose Antonio Olivera Ortega wrote:
Hi there!

I am trying to build WebRTC statically and using it to build sort of Android
Java Library with no luck so far.

If you're targeting Android, maybe this script to build an .aar archive is useful for you: https://chromium.googlesource.com/external/webrtc/+/master/tools-webrtc/android/build_aar.py
We're about to setup a bot that builds using that and archves each build (+ later on also publishes it as an official build).
 
Actually I am able to build WebRTC successfully using different targets such
as `AppRTCMobile`, `libjingle_peerconnection{,_jni,_so,_java}`. I am not sure how
to create a libwebrtc.a static library properly though.

I have tried everything but when I build the JNI interface I hit a ton of link
errors because undefined references. Clearly I do not know how to create a valid
libwebrtc.a static library.

I meant above that when I use the libwertc.a to build a JNI interface I am building I hit a ton of link
errors because undefined references 


The way I create the libwebrtc.a static library is kind of tricky. Let's say
I use the `libjingle_peerconnection_jni` build target, then I create the graph
of the target by using ninja tool
(|ninja -C <OUT_DIR> libjingle_peerconnection_jni -t graph) and parse the output.
By parsing the output I have a list of the static libraries the target 'depends
on'. Then I use the ar tool to create my libwebrtc.a library.

So, my questions are the following ones:

i) Which would be the build target to build WebRTC in order to create a static
library later?
ii) What is the proper way to create this static library?

I hope Sami can provide useful answers to these questions.

Sami Kalliomäki

unread,
Jan 31, 2017, 8:50:49 AM1/31/17
to Henrik Kjellander, Jose Antonio Olivera Ortega, discuss-webrtc
I have never built whole WebRTC to be statically linked. Here are my ideas though. First of all, I believe you have to set "is_component_build = false" GN argument for everything to get compiled properly into the static libraries.

I think you want to combine libjingle_peerconnection_jni, libjingle_peerconnection_metrics_default_jni and libjingle_peerconnection. Additionally, you probably need to call necessary initializers at runtime similar to here: https://cs.chromium.org/chromium/src/third_party/webrtc/sdk/android/src/jni/jni_onload.cc The proper way to do this would be to create a new rtc_static_library target with the necessary dependencies. You could start with copying libjingle_peerconnection_so, changing the target type and working from there.
Reply all
Reply to author
Forward
0 new messages