必须先配置默认的 FirebaseApp 实例,然后才能初始化 defaultFirebaseApp 实例
The default FirebaseApp instance must be configured before the defaultFirebaseApp instance can be initialized
我正在尝试使用 FirebaseApp.configure()
配置 Firebase,但遇到以下崩溃:
*** Terminating app due to uncaught exception 'com.firebase.installations', reason: 'The default FirebaseApp instance must be configured before the defaultFirebaseApp instance can be initialized. One way to ensure that is to call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).'
*** First throw call stack:
(0x195b7180c 0x195899fa4 0x195a66f84 0x1081413dc 0x107c59bc0 0x107c59aec 0x10274daa0 0x10274d5c0 0x10274c8ec 0x10274c310 0x10274c25c 0x10244b52c 0x10244b434 0x10244b5c4 0x199bda698 0x102451ad4 0x195974360)
libc++abi.dylib: terminating with uncaught exception of type NSException
我尝试从 didFinishLaunchingWithOptions
内部和 AppDelegate
的 init
内部调用 FirebaseApp.configure()
:
override init() {
super.init()
// Setting up the firebase instance
setupFirebase()
}
private func setupFirebase() {
FirebaseApp.configure()
Messaging.messaging().delegate = self
}
此时正在崩溃 -
我在 AppDelegate
中使用 import FirebaseCore
& import FirebaseMessaging
Podfile.lock
看起来像这样
Firebase/Core (6.20.0):
- Firebase/CoreOnly
- FirebaseAnalytics (= 6.3.1)
- Firebase/CoreOnly (6.20.0):
- FirebaseCore (= 6.6.4)
- Firebase/Database (6.20.0):
- Firebase/CoreOnly
- FirebaseDatabase (~> 6.1.4)
- Firebase/Firestore (6.20.0):
- Firebase/CoreOnly
- FirebaseFirestore (~> 1.11.2)
- Firebase/Messaging (6.20.0):
- Firebase/CoreOnly
- FirebaseMessaging (~> 4.3.0)
- FirebaseAnalytics (6.3.1):
- FirebaseCore (~> 6.6)
- FirebaseInstallations (~> 1.1)
- GoogleAppMeasurement (= 6.3.1)
- GoogleUtilities/AppDelegateSwizzler (~> 6.0)
- GoogleUtilities/MethodSwizzler (~> 6.0)
- GoogleUtilities/Network (~> 6.0)
- "GoogleUtilities/NSData+zlib (~> 6.0)"
- nanopb (= 0.3.9011)
- FirebaseAnalyticsInterop (1.5.0)
- FirebaseAuthInterop (1.1.0)
- FirebaseCore (6.6.4):
- FirebaseCoreDiagnostics (~> 1.2)
- FirebaseCoreDiagnosticsInterop (~> 1.2)
- GoogleUtilities/Environment (~> 6.5)
- GoogleUtilities/Logger (~> 6.5)
- FirebaseCoreDiagnostics (1.2.2):
- FirebaseCoreDiagnosticsInterop (~> 1.2)
- GoogleDataTransportCCTSupport (~> 2.0)
- GoogleUtilities/Environment (~> 6.5)
- GoogleUtilities/Logger (~> 6.5)
- nanopb (~> 0.3.901)
- FirebaseCoreDiagnosticsInterop (1.2.0)
- FirebaseDatabase (6.1.4):
- FirebaseAuthInterop (~> 1.0)
- FirebaseCore (~> 6.0)
- leveldb-library (~> 1.22)
- FirebaseFirestore (1.11.2):
- abseil/algorithm (= 0.20190808)
- abseil/base (= 0.20190808)
- abseil/memory (= 0.20190808)
- abseil/meta (= 0.20190808)
- abseil/strings/strings (= 0.20190808)
- abseil/time (= 0.20190808)
- abseil/types (= 0.20190808)
- FirebaseAuthInterop (~> 1.0)
- FirebaseCore (~> 6.2)
- "gRPC-C++ (= 0.0.9)"
- leveldb-library (~> 1.22)
- nanopb (~> 0.3.901)
- FirebaseInstallations (1.1.0):
- FirebaseCore (~> 6.6)
- GoogleUtilities/UserDefaults (~> 6.5)
- PromisesObjC (~> 1.2)
- FirebaseInstanceID (4.3.2):
- FirebaseCore (~> 6.6)
- FirebaseInstallations (~> 1.0)
- GoogleUtilities/Environment (~> 6.5)
- GoogleUtilities/UserDefaults (~> 6.5)
- FirebaseMessaging (4.3.0):
- FirebaseAnalyticsInterop (~> 1.5)
- FirebaseCore (~> 6.6)
- FirebaseInstanceID (~> 4.3)
- GoogleUtilities/AppDelegateSwizzler (~> 6.5)
- GoogleUtilities/Environment (~> 6.5)
- GoogleUtilities/Reachability (~> 6.5)
- GoogleUtilities/UserDefaults (~> 6.5)
- Protobuf (>= 3.9.2, ~> 3.9)
堆栈跟踪如下所示:
thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x0000000195969ec4 libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x0000000195885774 libsystem_pthread.dylib`pthread_kill$VARIANT$mp + 112
frame #2: 0x00000001957d9844 libsystem_c.dylib`abort + 100
frame #3: 0x00000001959327d4 libc++abi.dylib`abort_message + 128
frame #4: 0x00000001959329c4 libc++abi.dylib`demangling_terminate_handler() + 296
frame #5: 0x000000019589a258 libobjc.A.dylib`_objc_terminate() + 124
frame #6: 0x000000019593f304 libc++abi.dylib`std::__terminate(void (*)()) + 16
frame #7: 0x000000019593ec58 libc++abi.dylib`__cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 32
frame #8: 0x000000019593ec18 libc++abi.dylib`__cxa_throw + 124
frame #9: 0x000000019589a0d0 libobjc.A.dylib`objc_exception_throw + 356
frame #10: 0x0000000195a66f84 CoreFoundation`+[NSException raise:format:] + 108
* frame #11: 0x0000000107f993dc LocationTrackingFW`+[FIRInstallations installations](self=FIRInstallations, _cmd="installations") at FIRInstallations.m:159:5
frame #12: 0x0000000107ab1bc0 LocationTrackingFW`+[FIRAnalytics updateFirebaseInstallationID] + 32
frame #13: 0x0000000107ab1aec LocationTrackingFW`+[FIRAnalytics startWithConfiguration:options:] + 564
frame #14: 0x00000001025cdac0 Field Service`-[FIRApp configureCore](self=0x0000000280a1b510, _cmd="configureCore") at FIRApp.m:364:9
frame #15: 0x00000001025cd5e0 Field Service`+[FIRApp addAppToAppDictionary:](self=0x00000001035a2f20, _cmd="addAppToAppDictionary:", app=0x0000000280a1b510) at FIRApp.m:317:7
frame #16: 0x00000001025cc90c Field Service`+[FIRApp configureWithName:options:](self=0x00000001035a2f20, _cmd="configureWithName:options:", name=@"__FIRAPP_DEFAULT", options=0x0000000280a1b750) at FIRApp.m:202:5
frame #17: 0x00000001025cc330 Field Service`+[FIRApp configureWithOptions:](self=0x00000001035a2f20, _cmd="configureWithOptions:", options=0x0000000280a1b750) at FIRApp.m:145:3
frame #18: 0x00000001025cc27c Field Service`+[FIRApp configure](self=0x00000001035a2f20, _cmd="configure") at FIRApp.m:131:3
frame #19: 0x00000001022cb54c Field Service`AppDelegate.setupFirebase(self=0x0000000109f08a00) at AppDelegate.swift:272:21
frame #20: 0x00000001022cb454 Field Service`AppDelegate.init() at AppDelegate.swift:42:9
frame #21: 0x00000001022cb5e4 Field Service`@objc AppDelegate.init() at <compiler-generated>:0
frame #22: 0x0000000199bda698 UIKitCore`UIApplicationMain + 1728
frame #23: 0x00000001022d1af4 Field Service`main at AppDelegate.swift:21:7
frame #24: 0x0000000195974360 libdyld.dylib`start + 4
几个小时以来一直停留在这个问题上。谁能帮帮我
你不需要初始化它。
根据 Firebase 文档 check here
设置只需要在 didFinishLaunchingWithOptions
中添加 GoogleService-Info.plist
文件和 FirebaseApp.configure()
,仅此而已。
另外,检查这个
这里是 Firebase 团队成员。大多数 运行 陷入此错误的人不小心将 Firebase 的两个副本 link 复制到他们的应用程序中,通常一个在应用程序目标中,一个在动态框架依赖项目标中。您可以通过检查运行时日志中是否有重复的 class 定义警告来检查您的应用中是否有两个 Firebase link 副本。如果您看到类似
的警告
objc[40943]: Class FIRApp is implemented in both
~/Library/Developer/Xcode/DerivedData/FrameworkTest-apqjxlyrxvkbhhafhaypsbdquref/Build/Products/Debug-iphonesimulator/DynamicFramework.framework/DynamicFramework
(0x10b2a87f8) and
~/Library/Developer/CoreSimulator/Devices/4821F959-24A6-4D78-A102-4C5703103D99/data/Containers/Bundle/Application/F017D210-113A-4DAF-9E17-BDE455E71E06/FrameworkTest.app/FrameworkTest
(0x10ad2d348). One of the two will be used. Which one is undefined.
那么这意味着您的应用运行时中有两个 Firebase 副本。以前这不会使您的应用程序崩溃,但可能会导致其他未定义的行为,例如丢弃的 Analytics 事件。我们最近对 FirebaseInstallations 进行了更改,导致它在启动时崩溃。如果您降级 Firebase 版本依赖项,即使您的应用程序在启动时没有崩溃,您仍然会有未定义的行为。
不幸的是,您要么必须放弃动态框架方法,link 所有依赖项直接进入您的应用程序,要么必须将动态框架更改为静态框架。将来,我们将探索将 Firebase 作为动态依赖项进行分发,以便用户可以 link 将其放入动态框架中,而不必担心在运行时复制 class 定义。
有关详细信息,请参阅 this doc on the Firebase iOS SDK GitHub。
编辑:您现在可以选择通过 CocoaPods 静态或动态地 link Firebase。有关详细信息,请参阅此文档:https://firebase.google.com/docs/ios/link-firebase-static-dynamic
对于我的用例,我只想在我的主项目中使用 Firebase(而不是在我的动态模块中)。
我的解决方案是从动态模块目标中删除 Firebase 依赖项。
我现在像这样分离了我的依赖项。
def base
pod 'RxSwift', '~> 5'
pod 'RxCocoa', '~> 5'
#//Add all your base pods here
end
def fbase
pod 'Firebase/Auth'
pod 'FirebaseFirestoreSwift'
pod 'Firebase/Functions'
#//Add all your Firebase dependencies here
end
然后我对每个目标都有以下内容
target 'My Main App Target' do
base
fbase
end
target 'My Dynamic module' do
project './dynamic_module_path/dynamic_module.xcodeproj'
base
end
对于我的案例 [Flutter],
当我手动上传 firebase 文件而不是使用 flutterfire cli 时,问题已解决。
所以不是:
final FirebaseApp app = await Firebase.initializeApp(
options: options,
);
使用:
final FirebaseApp app = await Firebase.initializeApp();
并手动添加文件。
我正在尝试使用 FirebaseApp.configure()
配置 Firebase,但遇到以下崩溃:
*** Terminating app due to uncaught exception 'com.firebase.installations', reason: 'The default FirebaseApp instance must be configured before the defaultFirebaseApp instance can be initialized. One way to ensure that is to call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).'
*** First throw call stack:
(0x195b7180c 0x195899fa4 0x195a66f84 0x1081413dc 0x107c59bc0 0x107c59aec 0x10274daa0 0x10274d5c0 0x10274c8ec 0x10274c310 0x10274c25c 0x10244b52c 0x10244b434 0x10244b5c4 0x199bda698 0x102451ad4 0x195974360)
libc++abi.dylib: terminating with uncaught exception of type NSException
我尝试从 didFinishLaunchingWithOptions
内部和 AppDelegate
的 init
内部调用 FirebaseApp.configure()
:
override init() {
super.init()
// Setting up the firebase instance
setupFirebase()
}
private func setupFirebase() {
FirebaseApp.configure()
Messaging.messaging().delegate = self
}
此时正在崩溃 -
我在 AppDelegate
import FirebaseCore
& import FirebaseMessaging
Podfile.lock
看起来像这样
Firebase/Core (6.20.0):
- Firebase/CoreOnly
- FirebaseAnalytics (= 6.3.1)
- Firebase/CoreOnly (6.20.0):
- FirebaseCore (= 6.6.4)
- Firebase/Database (6.20.0):
- Firebase/CoreOnly
- FirebaseDatabase (~> 6.1.4)
- Firebase/Firestore (6.20.0):
- Firebase/CoreOnly
- FirebaseFirestore (~> 1.11.2)
- Firebase/Messaging (6.20.0):
- Firebase/CoreOnly
- FirebaseMessaging (~> 4.3.0)
- FirebaseAnalytics (6.3.1):
- FirebaseCore (~> 6.6)
- FirebaseInstallations (~> 1.1)
- GoogleAppMeasurement (= 6.3.1)
- GoogleUtilities/AppDelegateSwizzler (~> 6.0)
- GoogleUtilities/MethodSwizzler (~> 6.0)
- GoogleUtilities/Network (~> 6.0)
- "GoogleUtilities/NSData+zlib (~> 6.0)"
- nanopb (= 0.3.9011)
- FirebaseAnalyticsInterop (1.5.0)
- FirebaseAuthInterop (1.1.0)
- FirebaseCore (6.6.4):
- FirebaseCoreDiagnostics (~> 1.2)
- FirebaseCoreDiagnosticsInterop (~> 1.2)
- GoogleUtilities/Environment (~> 6.5)
- GoogleUtilities/Logger (~> 6.5)
- FirebaseCoreDiagnostics (1.2.2):
- FirebaseCoreDiagnosticsInterop (~> 1.2)
- GoogleDataTransportCCTSupport (~> 2.0)
- GoogleUtilities/Environment (~> 6.5)
- GoogleUtilities/Logger (~> 6.5)
- nanopb (~> 0.3.901)
- FirebaseCoreDiagnosticsInterop (1.2.0)
- FirebaseDatabase (6.1.4):
- FirebaseAuthInterop (~> 1.0)
- FirebaseCore (~> 6.0)
- leveldb-library (~> 1.22)
- FirebaseFirestore (1.11.2):
- abseil/algorithm (= 0.20190808)
- abseil/base (= 0.20190808)
- abseil/memory (= 0.20190808)
- abseil/meta (= 0.20190808)
- abseil/strings/strings (= 0.20190808)
- abseil/time (= 0.20190808)
- abseil/types (= 0.20190808)
- FirebaseAuthInterop (~> 1.0)
- FirebaseCore (~> 6.2)
- "gRPC-C++ (= 0.0.9)"
- leveldb-library (~> 1.22)
- nanopb (~> 0.3.901)
- FirebaseInstallations (1.1.0):
- FirebaseCore (~> 6.6)
- GoogleUtilities/UserDefaults (~> 6.5)
- PromisesObjC (~> 1.2)
- FirebaseInstanceID (4.3.2):
- FirebaseCore (~> 6.6)
- FirebaseInstallations (~> 1.0)
- GoogleUtilities/Environment (~> 6.5)
- GoogleUtilities/UserDefaults (~> 6.5)
- FirebaseMessaging (4.3.0):
- FirebaseAnalyticsInterop (~> 1.5)
- FirebaseCore (~> 6.6)
- FirebaseInstanceID (~> 4.3)
- GoogleUtilities/AppDelegateSwizzler (~> 6.5)
- GoogleUtilities/Environment (~> 6.5)
- GoogleUtilities/Reachability (~> 6.5)
- GoogleUtilities/UserDefaults (~> 6.5)
- Protobuf (>= 3.9.2, ~> 3.9)
堆栈跟踪如下所示:
thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x0000000195969ec4 libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x0000000195885774 libsystem_pthread.dylib`pthread_kill$VARIANT$mp + 112
frame #2: 0x00000001957d9844 libsystem_c.dylib`abort + 100
frame #3: 0x00000001959327d4 libc++abi.dylib`abort_message + 128
frame #4: 0x00000001959329c4 libc++abi.dylib`demangling_terminate_handler() + 296
frame #5: 0x000000019589a258 libobjc.A.dylib`_objc_terminate() + 124
frame #6: 0x000000019593f304 libc++abi.dylib`std::__terminate(void (*)()) + 16
frame #7: 0x000000019593ec58 libc++abi.dylib`__cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 32
frame #8: 0x000000019593ec18 libc++abi.dylib`__cxa_throw + 124
frame #9: 0x000000019589a0d0 libobjc.A.dylib`objc_exception_throw + 356
frame #10: 0x0000000195a66f84 CoreFoundation`+[NSException raise:format:] + 108
* frame #11: 0x0000000107f993dc LocationTrackingFW`+[FIRInstallations installations](self=FIRInstallations, _cmd="installations") at FIRInstallations.m:159:5
frame #12: 0x0000000107ab1bc0 LocationTrackingFW`+[FIRAnalytics updateFirebaseInstallationID] + 32
frame #13: 0x0000000107ab1aec LocationTrackingFW`+[FIRAnalytics startWithConfiguration:options:] + 564
frame #14: 0x00000001025cdac0 Field Service`-[FIRApp configureCore](self=0x0000000280a1b510, _cmd="configureCore") at FIRApp.m:364:9
frame #15: 0x00000001025cd5e0 Field Service`+[FIRApp addAppToAppDictionary:](self=0x00000001035a2f20, _cmd="addAppToAppDictionary:", app=0x0000000280a1b510) at FIRApp.m:317:7
frame #16: 0x00000001025cc90c Field Service`+[FIRApp configureWithName:options:](self=0x00000001035a2f20, _cmd="configureWithName:options:", name=@"__FIRAPP_DEFAULT", options=0x0000000280a1b750) at FIRApp.m:202:5
frame #17: 0x00000001025cc330 Field Service`+[FIRApp configureWithOptions:](self=0x00000001035a2f20, _cmd="configureWithOptions:", options=0x0000000280a1b750) at FIRApp.m:145:3
frame #18: 0x00000001025cc27c Field Service`+[FIRApp configure](self=0x00000001035a2f20, _cmd="configure") at FIRApp.m:131:3
frame #19: 0x00000001022cb54c Field Service`AppDelegate.setupFirebase(self=0x0000000109f08a00) at AppDelegate.swift:272:21
frame #20: 0x00000001022cb454 Field Service`AppDelegate.init() at AppDelegate.swift:42:9
frame #21: 0x00000001022cb5e4 Field Service`@objc AppDelegate.init() at <compiler-generated>:0
frame #22: 0x0000000199bda698 UIKitCore`UIApplicationMain + 1728
frame #23: 0x00000001022d1af4 Field Service`main at AppDelegate.swift:21:7
frame #24: 0x0000000195974360 libdyld.dylib`start + 4
几个小时以来一直停留在这个问题上。谁能帮帮我
你不需要初始化它。 根据 Firebase 文档 check here
设置只需要在 didFinishLaunchingWithOptions
中添加 GoogleService-Info.plist
文件和 FirebaseApp.configure()
,仅此而已。
另外,检查这个
这里是 Firebase 团队成员。大多数 运行 陷入此错误的人不小心将 Firebase 的两个副本 link 复制到他们的应用程序中,通常一个在应用程序目标中,一个在动态框架依赖项目标中。您可以通过检查运行时日志中是否有重复的 class 定义警告来检查您的应用中是否有两个 Firebase link 副本。如果您看到类似
的警告objc[40943]: Class FIRApp is implemented in both
~/Library/Developer/Xcode/DerivedData/FrameworkTest-apqjxlyrxvkbhhafhaypsbdquref/Build/Products/Debug-iphonesimulator/DynamicFramework.framework/DynamicFramework
(0x10b2a87f8) and
~/Library/Developer/CoreSimulator/Devices/4821F959-24A6-4D78-A102-4C5703103D99/data/Containers/Bundle/Application/F017D210-113A-4DAF-9E17-BDE455E71E06/FrameworkTest.app/FrameworkTest
(0x10ad2d348). One of the two will be used. Which one is undefined.
那么这意味着您的应用运行时中有两个 Firebase 副本。以前这不会使您的应用程序崩溃,但可能会导致其他未定义的行为,例如丢弃的 Analytics 事件。我们最近对 FirebaseInstallations 进行了更改,导致它在启动时崩溃。如果您降级 Firebase 版本依赖项,即使您的应用程序在启动时没有崩溃,您仍然会有未定义的行为。
不幸的是,您要么必须放弃动态框架方法,link 所有依赖项直接进入您的应用程序,要么必须将动态框架更改为静态框架。将来,我们将探索将 Firebase 作为动态依赖项进行分发,以便用户可以 link 将其放入动态框架中,而不必担心在运行时复制 class 定义。
有关详细信息,请参阅 this doc on the Firebase iOS SDK GitHub。
编辑:您现在可以选择通过 CocoaPods 静态或动态地 link Firebase。有关详细信息,请参阅此文档:https://firebase.google.com/docs/ios/link-firebase-static-dynamic
对于我的用例,我只想在我的主项目中使用 Firebase(而不是在我的动态模块中)。
我的解决方案是从动态模块目标中删除 Firebase 依赖项。
我现在像这样分离了我的依赖项。
def base
pod 'RxSwift', '~> 5'
pod 'RxCocoa', '~> 5'
#//Add all your base pods here
end
def fbase
pod 'Firebase/Auth'
pod 'FirebaseFirestoreSwift'
pod 'Firebase/Functions'
#//Add all your Firebase dependencies here
end
然后我对每个目标都有以下内容
target 'My Main App Target' do
base
fbase
end
target 'My Dynamic module' do
project './dynamic_module_path/dynamic_module.xcodeproj'
base
end
对于我的案例 [Flutter],
当我手动上传 firebase 文件而不是使用 flutterfire cli 时,问题已解决。
所以不是:
final FirebaseApp app = await Firebase.initializeApp(
options: options,
);
使用:
final FirebaseApp app = await Firebase.initializeApp();
并手动添加文件。