在 xcode 下使用 COCOAPODS 去裝 GoogleWebRTC,可以在把整個專案編譯到手機上,但是在虛擬機上面就會出錯,這裡紀錄處理方案。
原因 & 計畫
ref issue:
gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64" target_environment="device"'
ERROR at //webrtc.gni:548:32: Assignment had no effect.
xctest_module_target = "//test:google_test_runner_objc"
^-------------------------------
You set the variable "xctest_module_target" here and it was unused before it went
out of scope.
Via these template invocations:
rtc_test("rtc_unittests") //BUILD.gn:628
test("rtc_unittests") //webrtc.gni:494
mixed_test("rtc_unittests") //testing/test.gni:990
ios_app_bundle("rtc_unittests") //testing/test.gni:172
executable("rtc_unittests_executable") //build/config/ios/rules.gni:288
See //build/config/ios/rules.gni:288:3: whence it was called.
executable(_executable_target) {
^-------------------------------
See //testing/test.gni:172:5: whence it was called.
target(invoker.target_type, target_name) {
^-----------------------------------------
See //testing/test.gni:990:5: whence it was called.
mixed_test(_test_target) {
^-------------------------
See //webrtc.gni:494:3: whence it was called.
test(target_name) {
^------------------
See //BUILD.gn:628:3: whence it was called.
rtc_test("rtc_unittests") {
^--------------------------
接著就繼續下一步驟:
cd src
# 這個 target_environment="simulator" 是給模擬器的,手機要指定為 device
gn gen out/ios --args='target_os="ios" target_cpu="arm64" target_environment="simulator" is_debug=false is_component_build=false rtc_include_tests=false rtc_enable_objc_symbol_export=true enable_dsyms=false enable_stripping=true'
# 這裡要以 framework_objc 方式處理,不能用 AppRTCMobile,他可能會把不使用的程式碼移除掉,導致引用失敗
ninja -C out/ios framework_objc
完成後,把 out/WebRTC.framework 直接拖拉進去專案,在專案設定的 Frameworks, Libraries, and Embedded Content 要記得打開至少 Embed Without Signing
如果要同時支持手機和 simulator,要編譯兩次,然後用工具把它們合併,像是:
gn gen out/ios_simulator --args='target_os="ios" target_cpu="arm64" target_environment="simulator" is_debug=false is_component_build=false rtc_include_tests=false rtc_enable_objc_symbol_export=true enable_dsyms=false enable_stripping=true'
ninja -C out/ios_simulator framework_objc
gn gen out/ios_device --args='target_os="ios" target_cpu="arm64" target_environment="device" is_debug=false is_component_build=false rtc_include_tests=false rtc_enable_objc_symbol_export=true enable_dsyms=false enable_stripping=true'
ninja -C out/ios_device framework_objc
回到整個專案的根目錄:
xcodebuild -create-xcframework -framework build/webrtc_ios/src/out/ios_device/WebRTC.framework -framework build/webrtc_ios/src/out/ios_simulator/WebRTC.framework -output build/WebRTC.xcframework
Reference:
[1] https://webrtc.github.io/webrtc-org/native-code/ios/
[2] https://gn.googlesource.com/gn/
[3] https://github.com/CocoaPods/CocoaPods/issues/6578
[4] https://stackoverflow.com/questions/63607158/xcode-building-for-ios-simulator-but-linking-in-an-object-file-built-for-ios-f
[5] https://groups.google.com/g/discuss-webrtc/c/wdZKCx6yMvE
[6] https://stackoverflow.com/questions/29865899/ld-framework-not-found-pods/57167318
[7] https://stackoverflow.com/questions/33085505/error-building-webrtc-library-for-ios
[8] https://github.com/pristineio/webrtc-build-scripts/tree/master
沒有留言:
張貼留言