[英]What makes "FBAudienceNetwork" link took 20 seconds?
Recently I found out that the reason of taking ~20secs to link the project is because of "FBAudienceNetwork" SDK install by CocoaPods, as this image shows:最近我发现需要~20secs来链接项目的原因是因为CocoaPods安装了“FBAudienceNetwork”SDK,如下图所示:
You can clone the demo project here:您可以在此处克隆演示项目:
git@github.com:JohnnyTseng/FBDemoProject.git
This is a clean project that only contains "FBAudienceNetwork" installed by CocoaPods, and it'll take ~20secs to link the project.这是一个干净的项目,只包含 CocoaPods 安装的“FBAudienceNetwork”,链接项目需要大约 20 秒。
Steps to reproduce:重现步骤:
The interesting thing is, if you install even 10+ libraries with CocoaPods, the linking time is still very fast, once you installed "FBAudienceNetwork", it took ~20secs for each incremental build.有趣的是,如果你用 CocoaPods 安装 10+ 个库,链接时间仍然非常快,一旦你安装了“FBAudienceNetwork”,每次增量构建需要大约 20 秒。
Does anyone know how this happens?有谁知道这是怎么发生的? I'm very curious but have not enough knowledge to dig into this issue
我很好奇,但没有足够的知识来深入研究这个问题
Thank you!谢谢!
I have this problem too for quite some time and it is very annoying.我也有这个问题有一段时间了,很烦人。 I don't know a way to fix the linking time issue (maybe use the dynamic version of the framework, not static, but this means managing this dependency manually, which is a no-go for me), I think it is up to the FB team to fix.
我不知道解决链接时间问题的方法(也许使用框架的动态版本,而不是静态版本,但这意味着手动管理此依赖项,这对我来说是行不通的),我认为这取决于FB团队来修复。
But there is a workaround - avoid linking FBAudienceNetwork at all.但是有一个解决方法 - 完全避免链接 FBAudienceNetwork。
This reduces the issue to only the development related to FB ads, which is luckily not that often.这将问题减少到仅与 FB 广告相关的开发,幸运的是这种情况并不常见。
Some details:一些细节:
Suppose your fb-free target is FBDemoProject-no-fb
.假设您的无 fb 目标是
FBDemoProject-no-fb
。 Then in Podfile
:然后在
Podfile
:
target 'FBDemoProject' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for FBDemoProject
pod 'FBAudienceNetwork'
# any other libs
end
target 'FBDemoProject-no-fb' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# any other libs
end
for usage in swift: Other swift flags -> -D NO_FB_AD
用于 swift:其他 swift 标志 ->
-D NO_FB_AD
for usage in obj-c or header files: Preprocessor macros -> NO_FB_AD=1
用于 obj-c 或头文件:预处理器宏 ->
NO_FB_AD=1
protocol FbAd {
func tryLoad()
func isLoaded() -> Bool
func tryShow(_ from: UIViewController?)
}
class FbAdFactory {
static func create(
_ placementId: String,
_ didLoad: @escaping () -> (), //to be used in `FBInterstitialAdDelegate` methods - just to get an idea
_ didClose: @escaping () -> (),
_ onError: @escaping () -> ()
) -> NvFbAd {
#if !NO_FB_AD
return FbAdHelper(
placementId,
didLoad,
didClose,
onError)
#else
return FbAdDummy() //dummy implementation
#endif
}
}
Use conditional import in FbAdHelper
:在
FbAdHelper
使用条件导入:
//to avoid compiler errors
#if canImport(FBAudienceNetwork)
import FBAudienceNetwork
#endif
#if !NO_FB_AD
class FbAdHelper: NSObject, FbAd, FBInterstitialAdDelegate {
//here go encapsulated logic and delegate methods
}
#endif
var fbAdHelper: NvFbAd!
//...
self.fbAdHelper = FbAdFactory.create("placementId",
{ },
{ },
{ }
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.