This article is on the public account audio and video advanced road, about 5 minutes to read.

directory

  • preface
  • Important branch description
  • The preparatory work
  • validation
  • Other
  • Q&A
  • reference


preface

Webrtc was compiled on the Linux server before, and now it needs to be recompiled to port some functions to the Client. This article will introduce how to compile the Client Webrtc, which pitfalls encountered during the compilation process, and the preparation before compilation.

At first, the author compiled virtual Docker on MAC. Due to the performance of the machine, I found a New Windows version, reinstalled dual system, and finally compiled on Ubuntu.

WebRTC version changes frequently, and there is a big difference in the compilation of each version. In this paper, the author based on the M84 branch, and in the end, the author also gives the problems in the compilation of other branches.

Important branch description

  • Key versions correspond to branches
    • M84 Branch-Heads /4147 (stable until June 2020)
    • M89 Branch-Heads /4389 (stable until February 2021)
    • M93 Branch-Heads /4577 (Stable until January 2022)
  • Key Versions Supported Android versions
    • m84/4147 android:minSdkVersion=”16″ android:targetSdkVersion=”23″
    • m89/4389 android:minSdkVersion=”21″ android:targetSdkVersion=”23″
    • m93/4577 android:minSdkVersion=”21″ android:targetSdkVersion=”23″

The preparatory work

Install depot_tools(use depot_tools to download webrTC source code)

  • Git command to obtain depot_tools

    git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
    Copy the code

    Configuring environment Variables

    echo "export PATH=$PWD/depot_tools:$PATH" > $HOME/.bashrc
    source $HOME/.bashrc
    Copy the code
  • Check whether the configuration is successful

    echo $PATH
    Copy the code

Download the source code

  • Creating a folder

    mkdir webrtc_android && cd webrtc_android
    Copy the code
  • Obtain source code (about 18G, need to stabilize the agent)

    fetch --nohooks webrtc_android
    Copy the code

    Fetch –nohooks webrTC_android failed to synchronize directly with gclient sync –nohooks

  • The branch switch

    cd src
    git checkout -b m84/4147 branch-heads/4147
    Copy the code
  • Synchronize the target branch code

    cd ..
    gclient sync --nohooks
    gclient runhooks
    Copy the code

    Gclient sync –nohooks, gClient runhooks which fail, re-execute which

The source code to compile

  • Install build dependencies (about 30 minutes)

    ./src/build/install-build-deps.sh
    ./src/build/install-build-deps-android.sh
    Copy the code
  • Set the compile parameters to generate the Ninja file

    cd src
    gn gen out/build --args='target_os="android" target_cpu="arm" is_debug=false'
    Copy the code

    cd src gn gen out/build –args=’target_os=”android” target_cpu=”arm” is_debug=false’

    Out /build: Directory for compiling build files, optionally specified

    Target_os: compile target platform android, ios, etc

    Target_cpu: CPU architecture platform ARM, ARM64, x86, X64, etc

    Is_debug: Release mode or Debug mode

  • Begin to compile

    Compile (1W multiple build tasks, about 2 hours to compile)

  • Full amount to compile

    ninja -C out/build
    Copy the code

    Incomplete compilation

    ninja -C out/build AppRTCMobile
    Copy the code

    Note: Out/Build is the directory where the build files are compiled. The two must be the same

  • The main files obtained

    • out/build/lib.java/sdk/android/libwebrtc.jar
    • out/build/libjingle_peerconnection_so.so
  • Generated aar

    python tools_webrtc/android/build_aar.py --output "libwebrtc.aar" --arch "armeabi-v7a" "arm64-v8a" --build-dir out/Release 
    Copy the code

    The libwebrtc.aar file will be found in the SRC directory, which contains the SDK required for Android development. The out/Release directory is a compilation directory, and the first compilation will be slow for full compilation (estimated at 30-40 minutes), followed by fast incremental compilation (estimated at 10 seconds).

validation

Verify that the AAR is available

Official Demo In the SRC /examples directory, you can import the aar generated by compilation to check whether it is available.

Other

  • Generate dynamic library. So file, so file generation will be the first full compilation, subsequent incremental compilation speed is very fast. This approach is ideal for testing if you only change the C-layer code in the future without generating Java apis

    ninja -C out/Debug sdk/android:libjingle_peerconnection_so

  • Generate static library. A files

    ninja -C out/Debug

    Generated. A file in the out/Debug/obj/libwebrtc. A

  • Configure the Android Studio project

    Open webrtc_android directly using Android Studio/SRC/examples/aarproject/edit app/build. Gradle: delete it

    Implementation 'org. Webrtc: Google - webrtc: 1.0 +'Copy the code

    Replace the libwebrtc.aar compiled by the native step

    implementation fileTree(dir: '.. /.. /.. /', include: ['libwebrtc.aar'])Copy the code

Q&A

  • When executing gclient Runhooks

    python src/build/linux/sysroot_scripts/install-sysroot.py --arch=i386 
    Copy the code

    Download failed

    Change the number of retries of range(3) from 3 in install-sysroot.py

  • M84/4147 branch compilation error

    [996/11199] ACTION //base:base_build_config_gen_... c(//build/toolchain/android:android_clang_arm64) FAILED: gen/base/base_build_config_gen/java_cpp_template/org/chromium/base/BuildConfig.java python .. /.. /.. /build/android/gyp/gcc_preprocess.py --depfile gen/base/base_build_config_gen_BuildConfig.d --include-path .. /.. /.. / --output gen/base/base_build_config_gen/java_cpp_template/org/chromium/base/BuildConfig.java --template=.. /.. /.. /base/android/java/templates/BuildConfig.template Traceback (most recent call last): File ".. /.. /.. /build/android/gyp/gcc_preprocess.py", line 54, in <module> sys.exit(main(sys.argv[1:])) File ".. /.. /.. /build/android/gyp/gcc_preprocess.py", line 47, in main DoGcc(options) File ".. /.. /.. /build/android/gyp/gcc_preprocess.py", line 31, in DoGcc build_utils.CheckOutput(gcc_cmd) File ".. /.. /WebRTC/src/build/android/gyp/util/build_utils.py", line 261, in CheckOutput sys.stderr.write(stderr) TypeError: write() argument must be str, not bytesCopy the code

Solution:

The Python version is not compatible and M84 needs to be compiled using PYTHON 2

  1. Viewing the Python version

    python --version

  2. Remove the original default Python

    sudo rm -rf /usr/bin/python

  3. Specify the new default Python

    sudo ln -s /usr/bin/python2 /usr/bin/python

  4. recompile

  • M93/4577 branch compilation error

    Command failed because it wrote to stderr
    You can often set treat_warnings_as_errors=false to not treat output as failure (useful when developing locally).
    Copy the code

    recompile

    gn gen out/m89/release --args='target_os="android" target_cpu="arm64" is_debug=false treat_warnings_as_errors=false'
    Copy the code
  • ModuleNotFoundError: No module named ‘dataclasses’

    • python2

      sudo apt install python-pip
      pip install dataclasses
      Copy the code
    • python3

      sudo apt install python3-pip
      pip3 install dataclasses
      Copy the code
  • ERROR: The installation of The Chrome OS default fonts failed.

    ERROR: The installation of the Chrome OS default fonts failed. This is expected if your repo is installed on a remote file system. It is recommended to install your repo on a local file system. You can skip the installation of the Chrome OS default founts with the command line option: --no-chromeos-fonts.
    Copy the code

    Reinstall dependencies

    ./src/build/install-build-deps.sh --no-chromeos-fonts
    Copy the code
  • M89/4389 Compiling aar failed

    Traceback (most recent call last): ... File ".. /.. /.. /.. /.. /build/android/gyp/compile_java.py", line 501, in _RunCompiler fail_on_output=options.warnings_as_errors) File ".. /.. /WebRTC/src/build/android/gyp/util/build_utils.py", line 292, in CheckOutput raise CalledProcessError(cwd, args, MSG.format(stream_string)) util.build_utils.CalledProcessError: .... You can often set treat_warnings_as_errors=false to not treat output as failure (useful when developing locally). [2415/3419] CXX obj/api/libjingle_peer... ection_api/peer_connection_interface.o ... subprocess.CalledProcessError: Command '['../../WebRTC/src/third_party/depot_tools/ninja', '-C', 'out/m89/build/aar/armeabi-v7a', 'sdk/android:libwebrtc', 'sdk/android:libjingle_peerconnection_so']' returned non-zero exit status 1Copy the code

    recompile

    python tools_webrtc/android/build_aar.py --output "libwebrtc-m89.aar" --arch "armeabi-v7a" "arm64-v8a" --build-dir out/m89/build/aar --extra-gn-args='treat_warnings_as_errors=false'
    Copy the code

reference

WebRTC official website (webrtc.org/)

Android | WebRTC (WebRTC. Making. IO/WebRTC – org…