Closed12

Flutterで環境ごとにFirebase Projectを切り替える方法

bozzbozz

全て同じワークアラウンドかわからないので、上記の記事を見て最小公倍数的なやり方を取りたい

bozzbozz

環境の整理

ビルドモードとFlavorは別。
自分の場合は以下のような感じかな。

用途 ビルドモード Flavor Configuraton名 Product Bundle Identifier
ローカル用 Debug local Debug-local xxx.yyy.zzz.local
開発用 Debug dev Debug-dev xxx.yyy.zzz.dev
本番用 Release prod Release-prod xxx.yyy.zzz

Configuration名は何に使うんだろう?

bozzbozz

Schemeの追加

Xcode Menu > Product > Scheme > Manage Schemes
から環境に必要なFlavorを作成

  • Target: Runner
  • Name: Development
bozzbozz

Configuration の追加

Runner > PROJECT > Runner のConfigurationを以下の様に変更

変更前

  • Debug
  • Release
  • Profile

変更後

  • Debug
  • Release
  • Profile
  • Debug-dev
  • Debug-local
  • Release-prod
bozzbozz

xcconfigの追加

Runner > Flutter 配下にて、ファイル一覧から New File > Configuration Settings Fileとして、xcconfigファイルの作成

  • Debug.xcconfig
  • Release.xcconfig
  • Profile.xcconfig
  • Debug-v.xcconfig
  • Debug-local.xcconfig
  • Release-prod.xcconfig
bozzbozz

Info.plistの対応だけで済むかと思ったけど、調べていくと、flutterのfirebaseのライブラリの初期化時に必要なので、結局FlutterFireのコードも使うことになりそう

Firebase.initializeApp() で以下の様な例外を吐く

FirebaseException ([core/not-initialized] Firebase has not been correctly initialized.

Usually this means you've attempted to use a Firebase service before calling `Firebase.initializeApp`.

View the documentation for more information: https://firebase.flutter.dev/docs/overview#initialization
    )
このスクラップは2024/08/16にクローズされました