I’ll introduce how to add Firebase to a Flutter app.
This article assumes you’ve completed Flutter app creation ~ Running on Android Emulator.
Basically, you can add Firebase to your Flutter app by simply following the instructions on the official Firebase site.
There’s one point that requires attention: the section 4. To enable Firebase services in your Android app, add the google-services plugin to your Gradle files. in the above article differs from what’s written in the Firebase Console (https://console.firebase.google.com/project/your_project_name).
Don’t use the Android app configuration displayed in the Firebase Console, but instead use the configuration from Android アプリを構成する.
The Flutter Project’s Android Emulator couldn’t connect to the network and the error E/FirebaseInstanceId( 6972): Token retrieval failed: AUTHENTICATION_FAILED occurred, so I’ll just introduce the solution.
cd /Users/yourname/Library/Android/sdk/emulator
./emulator -list-avds
./emulator -avd Pixel_3a_API_29 -dns-server 8.8.8.8
💡 Reference: Android エミュレーターでネットワークに繋がらない時 - Qiita
3-b. ダウンロードしたファイルを Flutter アプリの Runner/Runner ディレクトリに移動します。? 引用元: iOS アプリを構成する
English translation:
3-b. Move the downloaded file to the Runner/Runner directory of your Flutter app.💡 Source: Configure an iOS app
Make sure to work with the above GoogleService-Info.plist file using Xcode app.
If you don’t add GoogleService-Info.plist in Xcode, the following error will occur during Xcode build when executing flutter run:
$ flutter run
Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Running pod install... 3.3s
Running Xcode build...
├─Assembling Flutter resources... 6.7s
└─Compiling, linking and signing... 12.1s
Xcode build done. 26.1s
path: satisfied (Path is satisfied), interface: en0
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23c7127e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff513fbb20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23c710bc +[NSException raise:format:] + 188
3 Runner 0x00000001008fe52a +[FIRApp configure] + 138
4 Runner 0x00000001009d6a89 -[FLTFirebaseAnalyticsPlugin init] + 185
5 Runner 0x00000001009d695d +[FLTFirebaseAnalyticsPlugin registerWithRegistrar:] + 173
6 Runner 0x00000001008f9ce0 +[GeneratedPluginRegistrant registerWithRegistry:] + 112
7 Runner <…>
Sample code with Firebase installed in Flutter app is published in the following GitHub Pull Request, so please take a look.
💡 Install Firebase (Android and iOS are working) · Pull Request #3 · codenote-net/flutter_sandbox
That’s all about adding Firebase to Flutter app from the Gemba.
That’s all from the Gemba.