webrtc iOS端編譯

編譯生成Framwork

1.修改路徑webrtc/src/tools_webrtc/ios/build_ios_libs.py文件的cpu架構python

DEFAULT_ARCHS = ENABLED_ARCHS = ['arm64','arm','x64','x86']
複製代碼
  • x64是模擬器,是mac電腦cpu
  • arm64是64位cpu
  • arm是32位cpu
  • x86是對應i386

2.直接運行命令--bitcode是開啓bitcode功能,若是開啓會致使生成的freamwork很是的大。因此通常不增長,切換到目錄webrtc/src/tools_webrtc/ioslinux

python build_ios_libs.py
複製代碼

3.最後輸出的WebRTC.frameworkwebrtc/src/out_ios_libs目錄下.android

若是遇到只要部分cpu架構能夠本身進行刪除控制。
Note: 若是你的freamwork只有armv7 和 arm64架構,可是在你上傳到App Store或者pod trunk 須要x86_64或i386 能夠在工程配置Build Phase中的/bin/sh增長以如下腳本進行忽略。
遇到一個比較坑的問題在build_ios_libs.py有一行將x86架構移除,建議此處將它註釋掉,不然一直編譯不經過支持i386架構。ios

# Ignoring x86 except for static libraries for now because of a GN build issue
  # where the generated dynamic framework has the wrong architectures.
  if 'x86' in architectures and args.build_type != 'static_only':
    architectures.remove('x86')
複製代碼
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
    FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
    FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
    echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"

    EXTRACTED_ARCHS=()

    for ARCH in $ARCHS
    do
        echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
        lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
        EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
    done

    echo "Merging extracted architectures: ${ARCHS}"
    lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
    rm "${EXTRACTED_ARCHS[@]}"

    echo "Replacing original executable with thinned version"
    rm "$FRAMEWORK_EXECUTABLE_PATH"
    mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"

done
複製代碼

編譯模擬器和真機測試demo

1.使用gn配置生成支持 Ninja編譯的配置文件。(gn相關文檔地址
gn須要配置的的主要變量有如下:web

  • target_os: 目標系統有:android, ios, mac,linux,chromeos,如:iOS設置爲 target_os="ios"
  • target_cpu: 目標cpu架構有:
    1. ios對應cpu有:arm,arm64,x64,x86
    2. android對應cpu有:arm64,x86(32位),x64(64位)
    3. chromeos對應有:mips64el
    4. linux對應:x86,x64
  • is_debug:是不是debug模式,默認是true
# debug build for 64-bit iOS
gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64" ios_code_signing_identity="E37AE8646D7CFE04723F31BEFC03E89918C847D0"'

# 編譯真機測試Demo
ninja -C out/ios_64 AppRTCMobile

# 配置總工程
gn gen out/ios --args='target_os="ios" target_cpu="arm64" ios_code_signing_identity="E37AE8646D7CFE04723F31BEFC03E89918C847D0"' --ide=xcode
open -a Xcode.app out/ios/all.xcworkspace
複製代碼
相關文章
相關標籤/搜索