Android compilation of WebRTC

foreword

In the previous study notes about WebRTC, the author recorded mostly theoretical knowledge, such as various protocols. Although there are suspicions of talking on paper and attics in the air, the author thinks that it is more about sharpening knives and not cutting vegetables by mistake. With some theoretical support, we can go further in practice later. Let's do some practical practice today, let's try to compile the Android version of WebRTC...

The content of this article is mainly from the official website WebRTC Android Native compilation tutorial https://webrtc.github.io/webrtc-org/native-code/ android/

Compiler Environment

In order to compile successfully at one time, the author chose an Ubuntu cloud host that is closer to the environment of the official website tutorial.

Note that compiling requires accessible internet for well known reasons, you know...

The official website tutorial says that the Android version only supports compiling on Linux, but the author also noticed that there is information on the Internet that introduces compiling the Android version on Mac OS, but I have not tried it, so I am not sure whether it can be compiled successfully on Mac OS. But the author thinks that if you cross-compile and play 6, it is probably not a problem.

Let's build the relevant tools needed for compilation:

1. Installationdepot_tools
 

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

# 配置环境变量 HOME一般是自带的环境变量,注意要用depot_tools的绝对路径
export PATH=$PATH:${HOME}/depot_tools

2. Whether the detection tool is installed successfully

fetch --help

When I used fetch --helpthe detection command, I found that there was no response for a long time, and there was no output on the console. I wondered whether there was a problem with the environment I configured, and then I found out that it was successful after waiting for a long time. If there is no output or no error message when fetch --helprunning Believe in yourself, don't underestimate yourself...

If the following content is displayed, depot_toolsthe configuration is successful:
 

Compilation steps

1. Download the source code

# 新建目录
mkdir WebRTC
# 进入目录
cd WebRTC
# 下载webRTC android源码
fetch --nohooks webrtc_android
# 同步
gclient sync

Because the project is huge, it may take a long time, so I can make a cup of coffee temporarily...

2. Installation dependencies

cd src
./build/install-build-deps.sh
./build/install-build-deps-android.sh

3. Compile

gn gen out/Debug --args='target_os="android" target_cpu="arm"'

ninja -C out/Debug

It takes a long time to compile, and I can go to make a cup of coffee again...

compiled product

After the compilation is complete, we enter out/Debugthe directory and see a lot of files and folders. My God, with so many outputs, which one is the library I want?

Next, let's analyze in reverse, which library file we really need to use:

We saw in the tutorial on the official website that Google has compiled a library for us, and we can directly import it in Android Studio: 1. The implementation 'org.webrtc:google-webrtc:1.0.+'


target so library is located. We create a new Android Studio project, and then import this library. Don't do it, pack it into an APK, drag this APK into Android Studio and see what's in the lib directory? That's right libjingle_peerconnection_so.so, this is it. We out/Debugcan find this so library in the directory, and it can be found, so libjingle_peerconnection_so.soit is one of the target libraries we need to use.
 

2. Locating the target jar package We can check the API classes in the left External Librariesdirectory of Android Studio, and then we analyze the related jar packages in the directory to see if the related classes in the jar package are consistent with the classes in the package. If it is consistent, the jar package is the product we need.org.webrtc:google-webrtc:1.0.+out/Debugorg.webrtc:google-webrtc:1.0.+
 

After analysis, we found that the jar package we need is in out/Debug/lib.java/sdk/android/libwebrtc.jarthe directory.

expand

There are many apks in the directory of the compiled product out/Debug, and many of the functions of the apk can be roughly seen through the name, such as audio_codec_speed_tests_apk, webrtc_perf_tests_apketc. If you are interested in communication, you can try to install these apks on your mobile phone to see what these apks have. Such function.

Since there are apk estimates and related sample code examples, we know that WrbRTC is a very large project, which contains many sub-modules, such as audio and video acquisition, audio noise reduction and so on. If we don't need all the functions of WebRTC in actual development, but just want to use one of its functional modules, we should be able to refer to this example to find clues... Of course, this is just the author's guess

. . . not yet practiced

problems encountered

I encountered an error when compiling gn command not found. This is mainly because exportthe environment variables set by the command are temporary. When the console window is closed, you need to reset it, that is, just run it. Of course, $ export PATH="$PATH:${HOME}/depot_tools"pay attention to the depot_toolsone you downloaded. path.

Author: Thought Awakening
Original  WebRTC Android Compilation- Nuggets

 

★The business card at the end of the article can receive audio and video development learning materials for free, including (FFmpeg, webRTC, rtmp, hls, rtsp, ffplay, srs) and audio and video learning roadmaps, etc.

see below!

 

Guess you like

Origin blog.csdn.net/yinshipin007/article/details/132380273