问题描述
在我们的项目中,我们使用了多个目标,并且为appDelegate类的两个目标启用了Target成员资格。在多个目标中运行以下Podfile时,我遇到崩溃问题:
target ‘SampleApp’ do
use_frameworks!
pod 'FirebaseCrashlytics','4.5.0'
pod 'FirebaseAnalytics','6.8.0'
pod 'FirebaseCore','6.10.1'
pod 'FirebaseMessaging','4.6.2'
end
target ‘SampleAppSDK’ do
use_frameworks!
pod 'FirebaseCrashlytics','4.6.2'
end
我能够在AppDelegate类中导入 FirebaseCrashlytics ,并且在 didFinishLaunchingWithOptions 函数中添加了“ FirebaseApp.configure()”。在运行应用程序时崩溃,并在控制台中显示以下错误。
由于未捕获的异常而终止应用程序 “ com.firebase.installations”,原因:“默认的FirebaseApp 必须先配置实例,然后才能配置defaultFirebaseApp实例 被初始化。确保该状态的一种方法是在应用程序中调用
[FIRApp configure];
(在Swift中为FirebaseApp.configure()
) 代表的application:didFinishLaunchingWithOptions:
(在Swift中为application(_:didFinishLaunchingWithOptions:)
)。
注意:如果我将上述依赖项添加到一个目标中,则能够运行该项目,但是我们无法在firebase控制台中看到崩溃,因此我们需要添加firebase依赖项支持多个目标:
有人知道这个问题吗?
解决方法
我们还有多个目标,我们的Podfile使用以下结构。
abstract_target 'AllPods' do
target 'AppIOS' do
pod 'Firebase/Crashlytics'
pod 'Firebase/Analytics'
end
target 'AppTVOS' do
pod 'Firebase/Crashlytics'
pod 'Firebase/Analytics'
end
target 'AppWatch' do
end
end
这只是一个概述,缺少大量细节,但等同于我们最初尝试的方法。