- Flutterで開発しているAndroidアプリにFirebaseを導入したい
- Firebaseプロジェクトの作成方法が知りたい
「FirebaseをAndroidアプリに導入するにはどうするの?」
今回はFirebaseでAndroidアプリをセットアップするための方法を解説していきます。
FirebaseをAndroidアプリでセットアップ
それではFirebaseをAndroidアプリでセットアップする方法を解説していきます。
Firebaseプロジェクトを作成
まずはFirebaseコンソールでFirebaseプロジェクトを作成します。
» Firebaseの新規プロジェクト作成方法はこちら

FirebaseとAndroidアプリを連携させる
Firebaseプロジェクトを作成したら管理画面を開き、Androidアプリのアイコンをクリックします。

すると次のような画面が開くのでアプリの登録を行なっていきます。
①のAndroidパッケージ名はFlutterプロジェクトのbuild.gradle
ファイルに書かれているapplicationId
を入力します。
②と③は省略可能です。

applicationId
が書かれているbuild.gradle
はFlutterプロジェクト
>android
>app
に格納されています。applicationId
を入力したら「アプリを登録」をクリックします。

次にgoogle-services.json
ファイルをダウンロードしてFlutterプロジェクトの所定の位置に追加し「次へ」をクリックします。

google-services.json
ファイルはFlutterプロジェクト
>android
>app
に追加します。

次にFirebase SDKを追加していく作業ですが、Flutterでは追加するコードが異なるためFlutterFireのドキュメントを参考に追加していきます。

FlutterFireの「Installing your Firebase configuration file」に記載されてある①と②コードを順に追加していきます。

①のコードはFlutterプロジェクト
>android
>build.gradle
ファイルのdependencies
にコピペします。

②のコードはFlutterプロジェクト
>android
>app
>build.gradle
ファイルのandroid{..}
の上にコピペします。

①と②のコードを追加したらFlutter SDKの追加は完了なので次のステップに進み「コンソールに進む」をクリックします。

Androidアプリの追加が完了すると次のようにFirebaseプロジェクトに表示されます。

参考サイト
- https://www.udemy.com/course/flutter-bootcamp-with-dart/learn/lecture/14486538#overview
- https://firebase.flutter.dev/docs/manual-installation/android