(Android-RTC-2) It took me so many days to download and compile the source code for Android-WebRTC!

As an introduction, the project directory   can be found at https://github.com/MrZhaozhirong/AppWebRTC . The engineering environment is Gradle4.0.x+Androidx. The entire WebRTCdemo is manually re-forked. The official source code is here .

1. Source code download

There are many tutorials on downloading and compiling the source code of Android-WebRTC. There are two relevant points to note: the Linux system must be used, and the source code site needs to have the correct Internet access, or find a domestic mirror instead; record the process of downloading and compiling the source code here according to the actual situation, so that students in need can solve problems.

If you have any questions, you can send a private message. The following is a no-brainer tutorial for this article:

1. Environment preparation

Correct, scientific and rigorous method of surfing the Internet, it is recommended to proxy all networks of the system.

2. Install basic software dependencies

Check for updated dependent libraries: $ sudo apt-get update
Install vim: $ sudo apt-get install vim
Install git: $ sudo apt-get install git

3. Install google tools and scripts
git clone  https://chromium.googlesource.com/chromium/tools/depot_tools.git

Under normal circumstances, the download of this depot_tools is relatively smooth. If the network is not smooth and the download times out, you can configure the following proxy for git

git config --global http.proxy= (usually 127.0.0.1):port

git config --global https.proxy= (usually 127.0.0.1):port

Be more professional,

export HTTPS_PROXY=http://proxy_ip:proxy_port #Scientific Internet access method setting parameters
export HTTP_PROXY=http://proxy_ip:proxy_port #Scientific Internet access method setting parameters
env GIT_SSL_NO_VERIFY=true #If the fetch code encounters an SSL error, please set this environment variables

vim ~/.boto

Add the .boto proxy export file with the following content:

 [vote]

proxy=ip

proxy_port=port

export NO_AUTH_BOTO_CONFIG=~/.boto #Set the path based on your own situation

4. After the download is completed, configure environment variables

$ vim ~/.bashrc
Append the following content at the bottom of the file:
export DEPOT_TOOLS_PATH=~/depot_tools (you can also write the full absolute path yourself)
export PATH=${PATH}:${DEPOT_TOOLS_PATH}
Save and exit vim to make the environment variables take effect :$ source ~/.bashrc

5. Start pulling Android webrtc source code

$ mkdir webrtc
$ cd webrtc
$ fetch --nohooks webrtc_android
$ gclient sync //If you encounter a problem and interrupt, you can execute it a few more times

Wait... This process will take a long time. The size of my download is about 18.7G.

You can use the command: du -h --max-depth=0 to view the size of the current root folder webertc/src.

Internet experts all recommend switching to a stable branch to pull files. The method is to use some git operations:

git branch -r // View all remote branches
git checkout m79 // Select a corresponding stable version and switch to the stable version m79
gclient sync

// .... .... wait for synchronization to complete

git checkout master
git pull origin master

// If there are conflicts, merge them

git merge master

6. Exception handling during downloading

During the download process, most of the problems are that the source address access fails. For example, an invalid error message appears when downloading the last src/third_party/libunwindstack. Find the corresponding git path from the log displayed in the terminal. After accessing it, there is indeed no source code file, and it is redirected here: https://chromium.googlesource.com/chromium/src/third_party/libunwindstack/+/refs /heads/master , then you can manually download it and put it in the folder of the corresponding path. There are two ideas: if the failure is caused by network principles, confirm that the network is smooth and try again; if the source address is invalid, manually find a new source address, download it and put it in the corresponding location of the source code directory. ]

Pay more attention to the console download error log, and continue gclient sync if there is an unexpected interruption (Unexpected terminal). If you see a sub-item frequently trying later, check the _bad_scm directory that exists in the same directory as webrtc/src, which contains sub-projects that have not been downloaded or have timed out. If _bad_scm is empty or the directory does not exist, it means that the project download has been completed. If the download process stays at a certain progress and nothing changes, you can also try to manually delete all the contents in _bad_scm and try again.

RPC failed transiently. Will retry in 1s. {"error":"failed to send request: .....} Then you can try setting export DEPOT_TOOLS_UPDATE=0

(Give me more patience, give me more patience, give me more patience.)

PS: When you feel that the download is complete, before you want to try to compile, you can make a compressed package of the entire webrtc folder so that you can start over again (don’t ask me how many times I have to start over).

2. Compile Android-Webrtc

1. Install dependencies before compiling

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

When executing the above instructions, I encountered several pitfalls:

Insert image description here

1.1 As shown in the figure above, execute ./build/install-build-deps.sh. The main reason is that the same dependency may have been installed on the local machine, but it was not installed successfully and is cached on the local machine. Ubuntu18.04 update source failed, "The source cannot be safely used for updates, so the source is disabled by default" solution_maxg1206's Blog-CSDN Blog_The source cannot be safely used for updates, so the source is disabled by default. Refer to  this Method 2 from my buddy, delete all files in the etc/apt/sources.list.d directory.

1.2 After eliminating the above problems, still execute ./build/install-build-deps.sh, and the above 2 pictures will appear. However, this problem is easy to solve. People have already given hints. Add --no-chromeos after the command. -fonts means not installing chrome system fonts.

1.3 No problem was encountered when executing the second instruction. When it came to the third instruction, it prompted ERROR: envsetup must be sourced. The direct translation is "envsetup must be sourced", and understanding its meaning should be related to environment variables. But in fact, .sh is a shell script, and you can directly open it with the text editor vim to read the source code. As shown in the 3 pictures above, the opening comment states that this step is to configure the Android SDK tools to the environment variable PATH, Use like: source build/android/envsetup.sh. Re-execute the command, and then enter $PATH to check the environment variables to see if android_sdk is set in place.

2. After the compilation dependencies are ready, you can start compilation.

2.1 Before compiling, install gn first

https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest and put it in the /webrtc/src/buildtools/linux64 path.

//First execute the following command

gn gen out/debug/arm64-v8a --args='tartget_os="android" target_cpu="arm64" is_debug=true' // Pay attention to single quotes and double quotes

// After there is no problem feedback on the console, execute the following command

ninja -C out/debug/arm64-v8a

Among them, --args is followed by configuration parameters, target_cpu represents the Android CPU architecture, and compiling other CPU architectures is as follows:

ARM: target_cpu="arm"
ARM64: target_cpu="arm64"
32-bit x86: target_cpu="x86"
64-bit x64: target_cpu=“x64"

You can also use another more convenient way. The compilation script is the webrtc/src/tools_webrtc/android/build_aar.py file. The compilation command line is as follows:

It needs to be executed in the src directory (I choose this compilation method myself)

./tools_webrtc/android/build_aar.py --build-dir out --arch "armeabi-v7a" "arm64-v8a"


2.2 You may encounter the following error collection during compilation and execution:

  • LASTCHANGE.committime , FileNotFoundError, as shown in the figure below:

Solution: Go to the src directory and execute the following instructions

./build/util/lastchange.py  build/util/LASTCHANGE

PS: Many FileNotFoundErrors may appear. It is necessary to distinguish whether the download is incomplete or you need to manually execute some pre-scripts.

  • build_install-sysroot is as shown in the figure below:

The console has given a solution:

Go to the src directory and execute the following command

./build/linux/sysroot_scripts/install-sysroot.py  --arch=arm64

PS: This similar error may occur multiple times. The solution is to execute this command, but the parameters of --arch may be different! Be sure to observe carefully.

  • treat_warnings_as_errors is as shown below:

This problem is mainly due to the use of some outdated APIs when compiling java files, and waning is also reported as an error level, and the control gives a prompt for modification. "You can overseas set treat_warnings_as_errors=false", but how to set treat_warnings_as_errors=false? Without going into details, the solution is as follows:

Go to the webrtc/src/build/config/compiler/ directory to open compiler.gni, find treat_warnings_as_errors and modify the value to false.

3. After the compilation is successful, what are the things that are really useful to us?

At this step, congratulations, you have successfully completed the entire download and compilation. Pay attention to the console output. After the build is completed, we can find the products of armeabi-v7a and arm64-v8a under src/out.

out/arm64-v8a/lib.java/sdk/android/libwebrtc.jar is a jar file that can be used on Android.

out/arm64-v8a/libjingle_peerconnection_so.so is an so file that can be used on Android.

But in fact, these products do not require us to go to great lengths to download the source code and compile it ourselves. In the previous article, we can download all available resources in gradle.dependencies{ implementation 'org.webrtc:google-webrtc:1.0.32006' } Dependent library files.

What do we really need?

If we deeply understand and read the source code, some header files are introduced into some files in the sdk/android directory, but you cannot find these header files in the source code directory. For example, sdk/android/generated_peerconnection_jni/PeerConnectionFactory_jni.h, similar to many generated_***_jni files, is said to be generated by executing the py script on the Internet. In fact, these are intermediate files generated during the compilation process.

These are what we really need. In-depth analysis of the Android version of webrtc source code will allow us to better understand the entire code process.

These header files are generated in the directory out/arn64-v8a/gen/sdk/android. Here you will see many hierarchical directories with generated open headers. Here is the relative path of the header files introduced by the source code.

If there is anything you don’t understand or encounter difficulties, please accept private messages, study together, and expand to error collection.

(Attached is the source code I compiled myself this time: pan.baidu.com/s/1vrVdY8BDirY0uY7w15XSSg extraction code: rzhd)

Reference materials: (There are also many help posts from predecessors on the Internet, so I won’t post them one by one.)

https://webrtc.googlesource.com/src/+/refs/heads/master

https://chromium.googlesource.com/chromium/src/third_party/+/refs/heads/main

Android webrtc learning 1 (source code download and compilation) - Zhihu

WebRTC Compilation Guide - Zhihu

Guess you like

Origin blog.csdn.net/a360940265a/article/details/116048337