Building libwebrtc for Android

488 views
Skip to first unread message

pps

unread,
Feb 4, 2021, 7:56:30 AM2/4/21
to discuss-webrtc
Hi,

I use libwebrtc in a large app. We don't use build that comes with libwebrtc, but maintain our own cmake based build.
Now, my current task is to make it work on androids. I use libwebrtc as a purely native lib. When I try to use it, native code tries to load some classes in modules\utility\source\jvm_android.cc. That is, I need to also compile some java files to be able to use libwebrtc on Android.
As I understand, there are two parts of of java files: those that are required by c++ part for native operation, and then, there is java version of webrtc itself that actually makes it possible to create peer connections directly from java. My question is: what java files are actually required for purely native libwebrtc operation? I don't want to compile that java version of webrtc, as all my use of the lib happens directly from c++ native code.

When I was trying to include java files that c++ side tried to locate, these files required some other java files, that required others ... and at the end all java files are getting pulled in. So, it looks like there is no clear separation of what's required for purely native libwebrtc, and what part provides separate java interface for libwebrtc.

Sergey V

unread,
Apr 15, 2022, 10:06:04 AM4/15/22
to discuss-webrtc
I've been trying to accomplish the same build you describe. I changed src/tools_webrtc/android/build_aar.py to TARGETS = [ 'webrtc' ], so that the libwebrtc.a is generated from running this script. Also had to change 'rtc_include_tests' : True in build_aar.py, and change use_custom_libcxx=false in src/build/config/c++/c++.gni. Also changed the c++ version to cflags_cc += [ "-std=${standard_prefix}++17" ] in src/build/config/compiler/BUILD.gn.

but the resulting libwebrtc.a is 137MB instead of the 300MB libwebrtc.a we usually get in other system builds. And when i link it to my NDK project in CMake/Android studio native build, the application either fails to compile with errors like ...undefined reference to `std::__cxx11::basic_string... this happens when use_custom_libcxx is set to true, but when it's set to false, the app builds, but crashes with a segmentation fault during load and the crash traces to some issue with same basic string and stdc++ lib implementation. Basically it appears that on android, the lib is built with a custom c++ from //buildtools/third_party/libc++... but it's not statically built into libwebrtc.a so it causes undefined symbol errors. 

I also tried linking the libpeerjingle_so.so output library that usually is build with build_aar.py, but it doesn't contain the entire library. I followed some previous posts about changing rtc_library(...) to rtc_static_library() and complete_static_lib=true, but wasn't able to set those in the proper places either.

If anyone has any idea how to generate a static libwebrtc.a for android (clang+NDK toolchain), that i can link statically to my own NDK project, please share.

TIA
Reply all
Reply to author
Forward
0 new messages