如何在Flutter应用程序上加快云端Firestore Xcode的构建速度

212 阅读1分钟

Cloud Firestore的一个长期问题是Flutter的Xcode构建需要很长的时间,特别是在CI环境下。这是因为Firestore的iOS依赖于50万行的大部分C++代码,这些代码作为Xcode构建的一部分要从头开始编译。

幸运的是,现在有一个解决方案,并记录在这里。

为了加快构建时间,你可以使用invertase/firestore-ios-sdk-frameworks,它包含了从Firebase iOS SDK版本下载中提取的预编译的Firestore iOS SDKs。

要利用这个优势,请遵循以下两个步骤。

1.找到正在使用的Firestore iOS SDK的哪个版本

你可以通过打开ios/Podfile.lock ,搜索cloud_firestore

你应该找到类似这样的东西。

  - cloud_firestore (3.1.4):
    - Firebase/Firestore (= 8.9.0)
    - firebase_core
    - Flutter

记下Firebase/Firestore 的版本(本例中为8.9.0 )。

2.使用预编译的Firestore iOS SDK

打开ios 文件夹内的Podfile ,然后在你的target 'Runner' do 块内添加这一行。

target 'Runner' do
  pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '8.9.0'

# ...
end

注意:在你第一次尝试的时候,你可能会得到这个错误日志。

[!] CocoaPods could not find compatible versions for pod "FirebaseFirestore":
  In snapshot (Podfile.lock):
    FirebaseFirestore (= 8.9.1, ~> 8.9.0)
  In Podfile:
    FirebaseFirestore (from `https://github.com/invertase/firestore-ios-sdk-frameworks.git`, tag `8.9.0`)
None of your spec sources contain a spec satisfying the dependencies: `FirebaseFirestore (from `https://github.com/invertase/firestore-ios-sdk-frameworks.git`, tag `8.9.0`), FirebaseFirestore (= 8.9.1, ~> 8.9.0)`.
You have either:
 * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
 * mistyped the name or version.
 * not added the source repo that hosts the Podspec to your Podfile.

这可以通过删除ios/Podfile.lock ,然后重新构建来解决。

不客气!😎