webrtc源码编译 iOS
1、环境配置
ninja下载
- 下载编译
git clone git://github.com/martine/ninja.git
cd ninja/
./bootstrap.py
- 安装到系统目录(也可配置坏境变量)
sudo cp ninja /usr/local/bin/
sudo chmod a+rx /usr/local/bin/ninja
2、脚本编译
- 源码提供的编译脚本:
./webrtc/src/tools_webrtc/iOS/build_ios_libs.sh
- 编译后的生成目录:
src/out_ios_libs
这种方式是全量编译,编译生成文件如下:
total 0
drwxr-xr-x 3 mac staff 96 6 30 18:27 WebRTC.dSYM
drwxr-xr-x 7 mac staff 224 6 30 18:27 WebRTC.framework
drwx------ 15 mac staff 480 6 30 17:30 arm64_libs
drwx------ 15 mac staff 480 6 30 17:45 arm_libs
drwx------ 15 mac staff 480 6 30 18:05 x64_libs
drwx------ 15 mac staff 480 6 30 18:27 x86_libs
3、AppRTCMobile编译
- 配置depot_tools路径
export PATH=$PATH:/Users/mac/Desktop/webrtc/depot_tools
- 配置编译参数
gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64"'
上面的命令失败,使用下面这条:
gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64" is_component_build=false ios_enable_code_signing=false' --ide=xcode
- 编译真机测试Demo
ninja -C out/ios_64 AppRTCMobile
这种方式非全量编译,编译生成文件如下:
drwxr-xr-x 25 mac staff 800 6 30 18:46 AppRTCMobile.app
drwxr-xr-x 6 mac staff 192 6 30 18:46 WebRTC.framework
drwx------ 3 mac staff 96 6 30 16:54 all.xcworkspace
-rw-r--r-- 1 mac staff 98 6 30 18:32 args.gn
-rw-r--r-- 1 mac staff 310702 6 30 18:32 build.ninja
-rw-r--r-- 1 mac staff 7376 6 30 18:32 build.ninja.d
drwx------ 5 mac staff 160 6 30 18:44 clang_x64
drwxr-xr-x 6 mac staff 192 6 30 18:44 gen
-rw-r--r-- 1 mac staff 192 6 30 16:54 low_bandwidth_audio_perf_test.runtime_deps
drwx------ 39 mac staff 1248 6 30 18:32 obj
drwx------ 3 mac staff 96 6 30 16:54 products.xcodeproj
drwxr-xr-x 4 mac staff 128 6 30 18:44 pyproto
-rw-r--r-- 1 mac staff 468932 6 30 18:32 toolchain.ninja
- 配置总工程
gn gen out/ios --args='target_os="ios" target_cpu="arm64"' --ide=xcode
open -a Xcode.app out/ios/all.xcworkspace
4、踩的坑
1、问题描述
/bin/sh: ../../third_party/llvm-build/Release+Asserts/bin/clang: cannot execute binary file
问题原因:
这个是因为下载了错误的文件clang,因为我是在linux服务器上下载iOS代码,然后拷贝到Mac机上编译。
- 找到clang目录。命令行执行 :
whereis clang
- 查看clang的目标架构。
执行 file clang_path(clang_path是第一步中找到的),在mac上的执行结果应当是
/usr/bin/clang: Mach-O 64-bit executable x86_64
- 查看third_party/llvm-build/Release+Asserts/bin/clang的目标架构,如果是如下的结果说明是Linux环境:
clang: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, stripped
- 用Mac的环境的替换现有的clang
rm webrtc/src/third_party/llvm* //删除 llvm-build 和 llvm目录
gclient sync //同步mac上对应的目录
或者从别处拷贝一份进行替换也可。