├── LICENSE ├── README.md ├── webrtc_android_module_build.sh └── webrtc_iOS_module_build.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 DanziChen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebRTC_Hack 2 | 3 | WebRTC Native 的源码有 12G,完整编译很慢,直接使用也要解决繁琐的依赖。本项目用于单独编译 WebRTC 中的模块为静态库,方便后续升级和使用。 4 | 5 | ## 准备工作 6 | 7 | 参考 [WebRTC 官网教程](https://webrtc.org/native-code/development/),先安装好 [Chromium depot tools](http://dev.chromium.org/developers/how-tos/install-depot-tools) 和下载好源码。 8 | 9 | * iOS:MacOS + Xcode 10 | * Android:Linux 11 | 12 | ## 编译单独模块 13 | 14 | ### iOS 15 | 16 | 1. 修改需要编译的模块文件夹下的 `BUILD.gn` 文件,例如 `modules/audio_processing/BUILD.gn` 17 | 18 | ``` 19 | rtc_static_library("audio_processing") { 20 | // 增加下面这一句,这样才会将依赖也编译进去 21 | complete_static_lib = true 22 | // ... 23 | } 24 | ``` 25 | 26 | 2. 拷贝 webrtc_iOS_module_build.sh 到 WebRTC 的源码目录中 27 | 28 | 3. `cd` 到源码目录下 29 | 30 | 4. `sh webrtc_iOS_module_build.sh <模块路径> <静态库输出路径> <可选项>` 选项如下: 31 | 32 | * -d:表示以 Debug 模式编译,默认为 Release 33 | * -b:表示开启 Bitcode,默认不开启 34 | * -h:表示拷贝完整头文件,默认不拷贝 35 | * -f:表示生成合并多个架构的静态库,默认不合成 36 | 37 | #### Example 38 | 39 | ```shell 40 | sh webrtc_iOS_module_build.sh ./common_audio ~/Desktop/output -b -f 41 | ``` 42 | 43 | #### 文章 44 | 45 | [WebRTC Native 模块单独编译静态库(iOS)](https://nemocdz.github.io/post/webrtc-native-%E6%A8%A1%E5%9D%97%E5%8D%95%E7%8B%AC%E7%BC%96%E8%AF%91%E9%9D%99%E6%80%81%E5%BA%93ios/) 46 | 47 | ### Android 48 | 49 | 1. 修改需要编译的模块文件夹下的 `BUILD.gn` 文件,例如 `modules/audio_processing/BUILD.gn` 50 | 51 | ``` 52 | rtc_static_library("audio_processing") { 53 | // 增加下面这一句,这样才会将依赖也编译进去 54 | complete_static_lib = true 55 | // ... 56 | } 57 | ``` 58 | 59 | 2. 拷贝 webrtc_android_module_build.sh 到 WebRTC 的源码目录中 60 | 61 | 3. `cd` 到源码目录下 62 | 63 | 4. `sh webrtc_android_module_build.sh <模块路径> <静态库输出路径> <可选项>` 选项如下: 64 | 65 | * -d:表示以 Debug 模式编译,默认为 Release 66 | * -h:表示拷贝完整头文件,默认不拷贝 67 | 68 | #### Example 69 | 70 | ```shell 71 | sh webrtc_android_module_build.sh ./common_audio ~/Desktop/output -d -h 72 | ``` 73 | 74 | -------------------------------------------------------------------------------- /webrtc_android_module_build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | is_debug=false 4 | is_copy_header=false 5 | 6 | options=${@:3} 7 | 8 | while getopts ":dh" option ${options}; do 9 | case "$option" in 10 | d) 11 | is_debug=true 12 | ;; 13 | h) 14 | is_copy_header=true 15 | ;; 16 | ?) 17 | echo "Usage:[-d isDebug] [-h copyHeaders]" 18 | exit -1 19 | ;; 20 | esac 21 | done 22 | 23 | # 检查输入的模块路径 24 | if [ ! -n ${1} ]; then 25 | echo "unknown lib path" 26 | exit 1 27 | fi 28 | 29 | # 检查输入的输出路径 30 | if [ ! -n ${2} ]; then 31 | echo "unknown output path" 32 | exit 1 33 | # 不允许输出在源码内 34 | elif [[ ${2} == ./* ]]; then 35 | echo "can't use current path" 36 | exit 1 37 | fi 38 | 39 | lib_path=${1} 40 | output_root_path=${2} 41 | 42 | # 获取模块名字,为路径最后一部分 43 | lib_name=$(echo "$lib_path" | awk -F "/" '{print $(NF)}') 44 | 45 | arm_build_path="./out/android_32" 46 | arm64_build_path="./out/android_64" 47 | 48 | mkdir -p ${arm_build_path} 49 | mkdir -p ${arm64_build_path} 50 | 51 | # 编译真机模块 52 | gn gen "$arm_build_path" --args="target_os=\"android\" target_cpu=\"arm\" is_debug=${is_debug} use_custom_libcxx=false" 53 | gn gen "$arm64_build_path" --args="target_os=\"android\" target_cpu=\"arm64\" is_debug=${is_debug} use_custom_libcxx=false" 54 | 55 | ninja -C ${arm_build_path} ${lib_name} 56 | ninja -C ${arm64_build_path} ${lib_name} 57 | 58 | output_lib_path="${output_root_path}/lib" 59 | 60 | mkdir -p ${output_lib_path} 61 | 62 | output_lib_arm_path="${output_root_path}/lib/${lib_name}-arm.a" 63 | output_lib_arm64_path="${output_root_path}/lib/${lib_name}-arm64.a" 64 | 65 | # 拷贝编译产物 66 | cp "${arm_build_path}/obj/${lib_path:1}/lib${lib_name}.a" ${output_lib_arm_path} 67 | cp "${arm64_build_path}/obj/${lib_path:1}/lib${lib_name}.a" ${output_lib_arm64_path} 68 | 69 | # 抽取头文件 70 | if [[ ${is_copy_header} == true ]]; then 71 | echo "copy webrtc headers" 72 | output_header_path="${output_root_path}/include" 73 | mkdir -p ${output_header_path} 74 | find . -name "*.h" -type | xargs -I {} cp --parents {} ${output_header_path} 75 | fi 76 | -------------------------------------------------------------------------------- /webrtc_iOS_module_build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | is_debug=false 4 | is_bitcode=false 5 | is_copy_header=false 6 | is_fat=false 7 | 8 | options=${@:3} 9 | 10 | while getopts ":dbhf" option ${options}; do 11 | case "$option" in 12 | d) 13 | is_debug=true 14 | ;; 15 | b) 16 | is_bitcode=true 17 | ;; 18 | h) 19 | is_copy_header=true 20 | ;; 21 | f) 22 | is_fat=true 23 | ;; 24 | ?) 25 | echo "Usage:[-d isDebug] [-b enableBitcode] [-h copyHeaders] [-f buildFat]" 26 | exit -1 27 | ;; 28 | esac 29 | done 30 | 31 | # 检查输入的模块路径 32 | if [ ! -n ${1} ]; then 33 | echo "unknown lib path" 34 | exit 1 35 | fi 36 | 37 | # 检查输入的输出路径 38 | if [ ! -n ${2} ]; then 39 | echo "unknown output path" 40 | exit 1 41 | # 不允许输出在源码内 42 | elif [[ ${2} == ./* ]]; then 43 | echo "can't use current path" 44 | exit 1 45 | fi 46 | 47 | lib_path=${1} 48 | output_root_path=${2} 49 | 50 | # 获取模块名字,为路径最后一部分 51 | lib_name=$(echo "$lib_path" | awk -F "/" '{print $(NF)}') 52 | 53 | arm_build_path="./out/iOS_32" 54 | arm64_build_path="./out/iOS_64" 55 | simulator_build_path="./out/iOS_simulator" 56 | 57 | mkdir -p ${arm_build_path} 58 | mkdir -p ${arm64_build_path} 59 | mkdir -p ${simulator_build_path} 60 | 61 | # 分别编译模拟器和真机模块 62 | gn gen "$arm_build_path" --args="target_os=\"ios\" target_cpu=\"arm\" enable_ios_bitcode=${is_bitcode} is_debug=${is_debug} use_xcode_clang=true" 63 | gn gen "$arm64_build_path" --args="target_os=\"ios\" target_cpu=\"arm64\" enable_ios_bitcode=${is_bitcode} is_debug=${is_debug} use_xcode_clang=true" 64 | gn gen "$simulator_build_path" --args="target_os=\"ios\" target_cpu=\"x64\" enable_ios_bitcode=${is_bitcode} is_debug=${is_debug} use_xcode_clang=true" 65 | 66 | ninja -C ${arm_build_path} ${lib_name} 67 | ninja -C ${arm64_build_path} ${lib_name} 68 | ninja -C ${simulator_build_path} ${lib_name} 69 | 70 | output_lib_path="${output_root_path}/lib" 71 | 72 | mkdir -p ${output_lib_path} 73 | 74 | output_lib_arm_path="${output_root_path}/lib/${lib_name}-arm.a" 75 | output_lib_arm64_path="${output_root_path}/lib/${lib_name}-arm64.a" 76 | output_lib_simulator_path="${output_root_path}/lib/${lib_name}-simulator.a" 77 | 78 | # 拷贝编译产物 79 | cp "${arm_build_path}/obj/${lib_path:1}/lib${lib_name}.a" ${output_lib_arm_path} 80 | cp "${arm64_build_path}/obj/${lib_path:1}/lib${lib_name}.a" ${output_lib_arm64_path} 81 | cp "${simulator_build_path}/obj/${lib_path:1}/lib${lib_name}.a" ${output_lib_simulator_path} 82 | 83 | # 合并架构 84 | if [[ ${is_fat} == true ]]; then 85 | echo "create fat lib" 86 | lipo -create ${output_lib_arm_path} ${output_lib_arm64_path} ${output_lib_simulator_path} -output "${output_root_path}/lib/${lib_name}-fat.a" 87 | fi 88 | 89 | # 抽取头文件 90 | if [[ ${is_copy_header} == true ]]; then 91 | echo "copy webrtc headers" 92 | output_header_path="${output_root_path}/include" 93 | mkdir -p ${output_header_path} 94 | headers=`find . -name '*.h'` 95 | for header in $headers 96 | do 97 | echo "copy header path: ${header}" 98 | ditto ${header} "${output_header_path}/${header:1}" 99 | done 100 | fi 101 | 102 | open ${output_root_path} 103 | 104 | 105 | --------------------------------------------------------------------------------