IOS compiles and generates Framwork

1. Modify the CPU architecture of the webrtc/ SRC /tools_webrtc/ios/ build_iOS_libs. py file

DEFAULT_ARCHS = ENABLED_ARCHS = ['arm64'.'arm'.'x64'.'x86']
Copy the code
  • X64 is an emulator, a MAC CPU
  • Arm64 is a 64-bit CPU
  • Arm is a 32-bit CPU
  • X86 corresponds to i386

2. Run the command –bitcode directly to enable the bitcode function. If this function is enabled, the generated Freamwork will be very large. So generally do not add, switch to the directory webrtc/ SRC /tools_webrtc/ios

python build_ios_libs.py
Copy the code

3. The webrtc. framework output is in the WebRTC/SRC/out_iOS_libs directory.

If only part of the CPU architecture can be deleted by itself. Note: If your freamwork only has armV7 and ARM64 architecture, but you need x86_64 or i386 before uploading to App Store or Pod Trunk can be ignored by adding /bin/sh to the project configuration in Build Phase. There is a line in build_iOS_libs. py that removes x86 architecture. I recommend commenting it out here, otherwise i386 architecture is not supported.

# 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' inarchitectures and args.build_type ! ='static_only':
    architectures.remove('x86')
Copy the code
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
Copy the code

IOS side compile simulator and real machine test demo

1. Use the GN configuration to generate a configuration file that supports Ninja compilation. (Document address for the GN) You need to configure the following variables for the GN:

  • Target_os: Target systems are: Android, ios, MAC, Linux, ChromeOS, for example: ios set to target_OS =”ios”

  • Target_cpu: The target CPU architecture has:

    1. Ios cpus are arm, ARM64, X64, and x86
    2. Android CPU: ARM64, x86(32-bit), X64 (64-bit)
    3. For chromeos: mips64el
    4. Linux: x86, X64
  • Is_debug: Indicates whether the mode is debug. The default value is true

  • To find the sign

security find-identity -p codesigning
Copy the code
# debug build for 64-bit iOS
gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64" ios_code_signing_identity="827D1FA91405C2F887E5B7B127BD849B5D4B7B4F"'

# Build real machine test Demo
ninja -C out/ios_64 AppRTCMobile

Configure the general project
gn gen out/ios --args='target_os="ios" target_cpu="arm64" ios_code_signing_identity="827D1FA91405C2F887E5B7B127BD849B5D4B7B4F"' --ide=xcode
open -a Xcode.app out/ios/all.xcworkspace
Copy the code

Android compilation

Switch to the code directorycd/ SRC/execute the script. The build/android/envsetup. Sh set compiler configuration is designed.the gn gen out/out_android_armeabi - v7a - args ='is_debug=false target_os="android" target_cpu="arm" rtc_use_h264=true ffmpeg_branding="Chrome"'Ninja -C out/ out_android_armeabi-v8A/AppRTCMobileCopy the code