LoginSignup
8
5

More than 3 years have passed since last update.

flutter runで「Configured the default Firebase app __FIRAPP_DEFAULT.」エラーが起きた際の対処法

Posted at

はじめに

FlutterとFirebaseを使ったアプリ作成中に、flutter runすると以下のようなエラーが起きる場面に遭遇した。

Launching lib/main.dart on iPhone Xʀ in debug mode...
Running pod install...                                              3.3s
Running Xcode build...                                                  

 ├─Assembling Flutter resources...                           8.0s
 └─Compiling, linking and signing...                         6.3s
Xcode build done.                                           19.1s
Configuring the default Firebase app...
Configured the default Firebase app __FIRAPP_DEFAULT.
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000105a016fb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x0000000104fa5ac5 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000105a01555 +[NSException raise:format:] + 197
    3   Runner                              0x0000000101d4f3b6 +[FIRApp configureWithName:options:] + 326
    4   Runner                              0x0000000101d4f12f +[FIRApp configureWithOptions:] + 143
    5   Runner                              0x0000000101d4f085 +[FIRApp configure] + 165
    6   Runner                              0x0000000101cf4f2c $s6Runner11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtF + 204
    7   Runner                              0x0000000101cf5254 $s6Runner11AppDelegateC11application_29didFinishLaunchingWithOptions<…>

対処法

ios/Runner/AppDelegate.swiftに配置してある、


FirebaseApp.configure()

を以下のように条件式を追加する形で修正する。

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    if FirebaseApp.app() == nil {
        FirebaseApp.configure()
    }
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

FirebaseApp.configure()を2回以上呼んで、FirebaseAppのオブジェクトを複数生成しようとすることでエラーが起きているので、それを確認する過程を入れることでエラーを防ぐことができる。

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5