编译Webrtc的IOS Static Library
现在网上发布的Webrtc都是Embeded Framework,Delphi没法编译使用这种Framework,所以只好自己编译
1.gn gen out/Release-arm -args='target_os="ios" target_cpu="arm" is_component_build=false is_debug=false ios_enable_code_signing=false'
2.ninja -C out/Release-arm webrtc
注意生成的libwebrtc.a里面有很多的debug symbol,生成的文件很大,要strip一下
另外,要用lipo生成armv7 , arm64的fat library。
2019/4/21追记
现在最新的Webrtc ios,应该是2018年3月6号的时候, 移除了编译静态library的功能,晕死.参考下面的ticket,
https://bugs.chromium.org/p/webrtc/issues/detail?id=10008
然后EMB这傻叉不支持Embed Dynamic Framework,有人题了一个ticket给emb,但是我怀疑EMB是否有足够的资源去实现这一功能.
我们只能使用第三方的编译的静态库了,参考下面的url
https://stackoverflow.com/questions/47294844/webrtc-static-library-on-ios
2019/4/21追记
修改src/sdk/build.gn文件 添加下面的静态库编译Target,编译即可.重要的是complete_static_lib = true这句话(complete_static_lib: [boolean] Links all deps into a static library.),参考下面的文章
https://www.jianshu.com/p/994f9f6c9874, 注意我的修改是基于rev27697的,如果是其他版本,需要基于其他版本修改
rtc_static_library("rtc_sdk_objc") { complete_static_lib = true deps = [ ":rtc_sdk_peerconnection_objc", "//webrtc/system_wrappers:field_trial_default", "//webrtc/system_wrappers:metrics_default", ] libs = [ "AVFoundation.framework", "AudioToolbox.framework", "CoreGraphics.framework", "CoreMedia.framework", "GLKit.framework", "VideoToolbox.framework", ] configs += [ "..:common_objc", "//build/config/compiler:enable_arc", ] public_configs = [ ":rtc_sdk_common_objc_config" ] if (is_clang) { # Suppress warnings from the Chromium Clang plugins. # See <a href="http://code.google.com/p/webrtc/issues/detail?id=163" title="http://code.google.com/p/webrtc/issues/detail?id=163">http://code.google.com/p/webrtc/issues/detail?id=163</a> for details. #configs -= [ "//build/config/clang:find_bad_constructs" ] } }
编译命令gn gen out/Release-arm64 --args='target_os="ios" target_cpu="arm64" is_component_build=false is_debug=false ios_enable_code_signing=false'
ninja -C out/Release-arm64
会生成obj/libwebrtc.a文件
再多说两句,static和dynamic的区别就是我们可以从static生成dynamic,反过来则不行,因为dynamic多了一个link的步骤,会填写符号表的地址,并删除一些Object文件的信息,所以没法反过来生成static的library.
2020/05/02 追记
编译mac 的library,需要撤销上面对build.gn的修改,原始文件保存为src/sdk/BUILD.gn copy
然后执行下面命令
gn gen out/Mac --args='target_os="mac" target_cpu="x64" is_component_build=false is_debug=false rtc_include_tests=true'
ninja -C out/Mac
注意针对Mac,静态库的编译规则要稍微改一下
rtc_static_library("rtc_sdk_objc") { complete_static_lib = true deps = [ ":base_objc", ":default_codec_factory_objc", ":native_api", ":native_video", ":peerconnectionfactory_base_objc", ":ui_objc", ":videocapture_objc", ":videocodec_objc", ":videotoolbox_objc", "../rtc_base:rtc_base_approved", ] if (rtc_use_metal_rendering) { deps += [ ":metal_objc" ] } if (!build_with_chromium) { deps += [ ":callback_logger_objc", ":file_logger_objc", ] } libs = [ "AVFoundation.framework", "CoreGraphics.framework", "CoreMedia.framework", "OpenGL.framework", ] configs += [ "..:common_objc", # ":used_from_extension", ] public_configs = [ ":common_config_objc" ] }
并且要把rtc_sdk_objc添加到framework编译依赖里面,否则相应的library并不会被编译
if (is_mac) { mac_framework_bundle_with_umbrella_header("mac_framework_objc") { info_plist = "objc/Info.plist" output_name = "WebRTC" ... deps = [ ":base_objc", ":default_codec_factory_objc", ":rtc_sdk_objc",
编译后,将output/Mac/obj/sdk/librtc_sdk_objc.a获取就可以了
注意args.gn中药添加use_custom_libcxx=false,否则Mac上libc++部分的代码会crash
gn args out/Mac list可以得到支持的args的列表