Compile WebRTC under Mac (Mac and iOS version)

created at 12-25-2021 views: 73


With the impact of the Covid-19, the demand for audio and video has exploded in the past two years. In the field of audio and video, WebRTC can be said to be an inevitable treasure house, including the entire process of audio and video acquisition, encoding and decoding, transmission, and rendering. This article mainly records the entire process of compiling WebRTC Mac and iOS versions on the Mac platform.

Install the depot_tools tool

git clone to get depot_tools

git clone

Configure the path of depot_tools to environment variables

export PATH=$PWD/depot_tools:$PATH

Download webrtc source code

mkdir webrtc
cd webrtc
fetch --nohooks webrtc_ios
gclient sync

The latest source code is downloaded by default. If you want to switch to the specified branch, you can use the following command:

# View available version branches
git branch -r
# Switch to m79 branch
git checkout branch-heads/m79
gclient sync
# Or forcibly switch to the specified commit (b484ec0082948ae086c2ba4142b4d2bf8bc4dd4b is the last commit id submitted by m79)
gclient sync -r b484ec0082948ae086c2ba4142b4d2bf8bc4dd4b --force


Mac version

gn gen out/mac-release --args='target_os="mac" target_cpu="x64" is_debug=false use_rtti=true is_component_build=false rtc_use_h264=false rtc_include_tests=false' --ide=xcode
ninja -C out/mac-release

After the compilation is successful,.

iOS version

# Compile version without certificate
gn gen out/ios-release --args='target_os="ios" target_cpu="arm64" is_debug=false use_rtti=true is_component_build=false ios_enable_code_signing=false proprietary_codecs=false rtc_use_h264=false rtc_include_tests=false' --ide=xcode
ninja -C out/ios-release

# Get the certificate name
security find-identity -v -p codesigning

# Compile the certificate version
gn gen out/ios-release-sign --args='target_os="ios" target_cpu="arm64" is_debug=false use_rtti=true is_component_build=false ios_code_signing_identity="The string of numbers obtained by the above command" proprietary_codecs=false rtc_use_h264= false rtc_include_tests=false' --ide=xcode
ninja -C out/ios-release-sign

After successful compilation, the file all.xcworkspace will be generated under src\out\xxxx\. Open it to build and debug webrtc projects. Among them, APPRTCMobile is a sample demo provided by Google, which can be packaged and run on a real machine. The WebRTC.framework library file is also generated in src\out\xxxx\, and its audio and video capabilities can be used by quoting this library file in an external project.

The WebRTC.framework library file can also be generated separately by ninja command or python script.

# Generate WebRTC.framework library file separately by ninja command
ninja -C out/ios-release-sign framework_objc

# Generate WebRTC.framework library file through script
python tools_webrtc/ios/ --bitcode

The library files generated by the python script (the earlier version of webrtc, the latest version of xcframework) are in the src/out_ios_lib directory. There will be 5 folders in this directory, among which WebRTC.framework is a dynamic library that supports the four architectures of `arm`, arm64, x64, and x86. In addition, arm_libs, arm64_libs, x64_libs, and x86_libs folders contain dynamic libraries that support these four architectures separately. You can use the lipo -info or file command to view the supported architectures.

Apple's new library type of xcframework later supports its unified multi-platform and multi-architecture. The earlier version of webrtc does not support the generation of xcframework. For this reason, the following script can be used to convert `framework` to xcframework.


mkdir iphoneos iphonesimulator

cp -R WebRTC.framework  iphoneos
cp -R WebRTC.framework  iphonesimulator

lipo -remove i386 -remove x86_64 iphoneos/WebRTC.framework/WebRTC -o iphoneos/WebRTC.framework/WebRTC
lipo -remove armv7 -remove arm64 iphonesimulator/WebRTC.framework/WebRTC -o iphonesimulator/WebRTC.framework/WebRTC

xcodebuild -create-xcframework \
-framework iphoneos/WebRTC.framework \
-framework iphonesimulator/WebRTC.framework \
-output "WebRTC.xcframework"


compilation errors

May encounter compilation errors

Fatal error:'libavutil/avconfig.h' file not found


Create the avconfig.h file in src/third_party/ffmpeg/libavutil/ with the following content:

/* Generated by ffconf */
\#endif /* AVUTIL_AVCONFIG_H */

compiling error of certificate version

Error encountered in compiling the version with certificate

Error: no mobile provisioning profile found for "".


Open the all.xcworkspace project, modify the Signing in the project to be your own, and recompile the project.

another problem

There is an unresolved issue in the version I compiled

fatal error: /Applications/ file list file: obj/third_party/ffmpeg/libffmpeg_internal.a.rsp is empty.

Only set rtc_use_h264=false first,  not use h264.

created at:12-25-2021
edited at: 12-25-2021: