preface

In the previous study notes on WebRTC, the author recorded mostly theoretical knowledge, such as various protocols and so on. Although there is the suspicion of being an armchair strategist and attic in the air, the author thinks it is more about sharpening knives and not cutting vegetables. Only with the support of part of the theory can we go further in the later practice. Today we will try to build WebRTC for Android.

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

Compile environment

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

Note that compilation requires a barrier-free Internet for well-known reasons, you know…

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

Let’s build the tools needed for compilation:

1. Install depot_tools

Git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git # configure the environment variable HOME generally is built-in environment variables, Export PATH=$PATH:${HOME}/depot_tools is the absolute PATH of depot_toolsCopy the code

2. Check whether the tool is installed successfully

fetch --help
Copy the code

When I used fetch –help to detect the command, I found that there was no response for a long time, and there was no output from the console. I suspected that there was something wrong with the environment configured by myself, and then I found it was successful after waiting for a long time. If there is no output or no error message after running fetch –help temporarily, I should trust myself. Don’t underestimate yourself….

If the following information is displayeddepot_toolsConfiguration successful:

Compilation step

1. Download the source code

Fetch --nohooks webrtc_android # sync gClient syncCopy the code

Since the project is huge and may take a long time, I can make a cup of coffee for the time being.

2. Install dependencies

cd src
./build/install-build-deps.sh
./build/install-build-deps-android.sh
Copy the code

3, compile,

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

ninja -C out/Debug
Copy the code

It takes a long time to compile, so you can go make a cup of coffee again…

Compile the product

After compiling, we go to the out/Debug directory and see a bunch of files and folders. Oh my God, that’s the library I want.

Let’s reverse engineer which library file we really need to use:

Implementation ‘org.webrtc: Google-webrtc :1.0.+’

Let’s create a new Android Studio project, import the library, do nothing, package it into an APK, drag the APK into Android Studio and see what’s in the lib directory. Yeah, that’s it.libjingle_peerconnection_so.so, we are inout/DebugCheck the directory to see if there is this so library, and there is, solibjingle_peerconnection_so.soThat’s one of the target libraries that we need to use.

2. The target JAR package is positioned on the left through Android StudioExternal LibrariesTake a look in the directoryOrg. Webrtc: Google - webrtc: 1.0 +Have those API classes, and let’s analyze themout/DebugJar package directory to see if the jar package and related classesOrg. Webrtc: Google - webrtc: 1.0 +The classes in the package are consistent, and if they are, that JAR package is the product we need.

After analysis we found that we need the jars in the out/Debug/lib. Java/SDK/android/libwebrtc. The jar directory.

expand

There are many other apKs in the out/Debug directory of the compiled product, and many of them can be seen by name, such as audio_codec_speed_tests_apk,webrtc_perf_tests_apk, etc. If you are interested in communication, try installing these APKs on your phone to see what they can do.

Since there is apK estimation and related sample code examples, we know that WrbRTC is a huge project, which contains many sub-modules, such as audio and video capture, audio noise reduction and so on. If we don’t need all of WebRTC’s features in actual development, but just want to use one of its functional modules, this example should be a clue…

Of course, this is just my guess… It hasn’t been done yet

Problems encountered

Gn Command not found error during compilation. This is mainly because the environment variable set by export command is temporary and needs to be reset after the console window is closed. $export PATH=”$PATH:${HOME}/depot_tools” $export PATH:${HOME}/depot_tools

Poking fun at the

In order to compile WebRTC this thing, specially made a Cloud host in Hong Kong, it seems not cheap, many cloud providers are for new users to have concessions… The baby is not happy…

Pay attention to me, progress together, life is more than coding!!