webrtc源碼編譯 iOS

1、環境配置

ninja下載

  1. 下載編譯
git clone git://github.com/martine/ninja.git
cd ninja/
./bootstrap.py
  1. 安裝到系統目錄(也可配置壞境變量)
sudo cp ninja /usr/local/bin/
sudo chmod a+rx /usr/local/bin/ninja

2、腳本編譯

  1. 源碼提供的編譯腳本:
./webrtc/src/tools_webrtc/iOS/build_ios_libs.sh
  1. 編譯後的生成目錄:
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編譯

  1. 配置depot_tools路徑
export PATH=$PATH:/Users/mac/Desktop/webrtc/depot_tools
  1. 配置編譯參數
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 
  1. 編譯真機測試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
  1. 配置總工程
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機上編譯。

  1. 找到clang目錄。命令行執行 :
whereis clang
  1. 查看clang的目標架構。
    執行 file clang_path(clang_path是第一步中找到的),在mac上的執行結果應當是
/usr/bin/clang: Mach-O 64-bit executable x86_64
  1. 查看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
  1. 用Mac的環境的替換現有的clang
rm  webrtc/src/third_party/llvm* //刪除 llvm-build  和 llvm目錄
gclient sync //同步mac上對應的目錄

或者從別處拷貝一份進行替換也可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章