TOP(About this memo)) > 一覧(Flutter) > FlutterFire
なお、firebaseのコンソールの「Flutterアプリ追加」を開くと手順が書いてある。以下は初めて実行するときにM1 Macでエラーになった内容も含めて記載している。
(未インストールの場合)firebase をインストール
npm install -g firebase-tools
flutterfire_cliをインストール
dart pub global activate flutterfire_cli
$HOME/.pub-cache/bin
を追加。確認
dart pub global list
アップデート(インストールと同じコマンド)
dart pub global activate flutterfire_cli
flutterfire --version
firebaseプロジェクトをflutterへconfigureする。(以下はiOSのみの場合)
firebase login
flutterfire configure --project=プロジェクトID --platforms=ios --ios-bundle-id=バンドルID
sudo gem install xcodeproj
を実行〜〜
kernel_require.rb:54:in `require': cannot load such file -- xcodeproj (LoadError) `require': cannot load such file -- xcodeproj
〜
上記によって下記のファイルが生成される。
上記によって下記のファイルが更新される
アプリケーションコードでは下記のように読み込みを行う。
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,// 上記で作成した「firebase_options.dart」を参照
);
上記のoptionsをつけていない状態でコード中でFirebaseの機能を実行しようとするとエラーが発生する。(Firebaseプロジェクトに紐付いていないため。)
flutter: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
which flutterfire
~/.pub-cache/bin/flutterfirecat ~/.pub-cache/bin/flutterfire
#!/usr/bin/env sh
# This file was created by pub v3.5.3.
# Package: flutterfire_cli
# Version: 1.0.0
# Executable: flutterfire
# Script: flutterfire
if [ -f ~/.pub-cache/global_packages/flutterfire_cli/bin/flutterfire.dart-3.5.3.snapshot ]; then
dart "~/.pub-cache/global_packages/flutterfire_cli/bin/flutterfire.dart-3.5.3.snapshot" "$@"
# The VM exits with code 253 if the snapshot version is out-of-date.
# If it is, we need to delete it and run "pub global" manually.
exit_code=$?
if [ $exit_code != 253 ]; then
exit $exit_code
fi
dart pub -v global run flutterfire_cli:flutterfire "$@"
else
dart pub global run flutterfire_cli:flutterfire "$@"
fi
このコードは、flutterfire コマンドラインツールを実行するためのBashスクリプトです。
主に、特定のスナップショット(.snapshot)ファイルの有無と状態を確認し、適切にツールを実行する役割を果たしています。
このファイル((.snapshot)ファイル)は、flutterfire CLI の Dart スナップショット版(高速に実行するために事前コンパイルされた形式)です。
スナップショットファイルが存在する場合、それを Dart VM で実行します。
"$@" はスクリプトに渡された全ての引数をそのまま Dart コマンドに渡します。
スナップショットのバージョンが古い場合、Dart VM は終了コード 253 で終了します。
古いスナップショットが見つかった場合、スナップショットを再生成せずに、dart pub 経由で直接 flutterfire コマンドを実行します。
flutterfire configure 〜
を実行する。flutterfire configure 〜
を実行する前に上記のファイルをすべて削除するしておくと良い。(シェルファイル等で削除してから実行するようにすると良いかもしれない)firebase_core: 〜〜 :path: ".symlinks/plugins/firebase_core/ios"
の記述が指すフォルダ内にあるfirebase_sdk_version.rb
が示すバージョンpod update Firebase/CoreOnly
を実行する事で Firebase/CoreOnlyをアップデートする。Analyzing dependencies
firebase_auth: Using Firebase SDK version '10.7.0' defined in 'firebase_core'
firebase_core: Using Firebase SDK version '10.7.0' defined in 'firebase_core'
firebase_messaging: Using Firebase SDK version '10.7.0' defined in 'firebase_core'
[!] CocoaPods could not find compatible versions for pod "Firebase/CoreOnly":
In snapshot (Podfile.lock):
Firebase/CoreOnly (= 10.3.0)
In Podfile:
firebase_core (from `.symlinks/plugins/firebase_core/ios`) was resolved to 2.10.0, which depends on
Firebase/CoreOnly (= 10.7.0)
You have either:
* changed the constraints of dependency `Firebase/CoreOnly` inside your development pod `firebase_core`.
You should run `pod update Firebase/CoreOnly` to apply changes you've made.