On Flutter Page 7, I managed to do two things:
Demonstrate engagement with Firebase Analytics using example code
Use Firebase DebugView, which may be a useful tool for the future
Now, I will follow the Flutter/Firebase documentation, to leearn more about Firebase and Flutter.
flutter-codelabs
I created the folder flutter-codelabs
and then opened this folder in VS Code and entered the following command in VS Code bash
terminal window:
git clone https://github.com/flutter/codelabs.git flutter-codelabs
This cloned everything from github in a child flutter-codelabs
folder. It looks like I did not need to create the first flutter-codelabs folder. Now I have two of them. Never mind.
The folders in the new flutter-codelabs are all example apps:
flutter pub get failure
I cd to firebase-get-to-know-flutter/step_02
. There are many red lines in main.dart and I try flutter pub get
to install missing packages. This is what I get:
The current Dart SDK version is 2.17.6.
Because gtk_flutter requires SDK version >=2.18.0-271.7.beta <3.0.0, version solving failed.
Running "flutter pub get" in step_02... pub get failed (1;
Because gtk_flutter requires SDK version >=2.18.0-271.7.beta <3.0.0, version solving failed.)
I ran flutter upgrade
. It worked like a charm. Watch this video by Johannes Milke if you get problems when upgrading. Apparently, things may go wrong sometimes. Luckily, they did not for me and my flutter upgrade
ended with the following lines:
I restarted VS Code and ran flutter pub get
again to get the missing packages. The TODO lines were listed as problems but they refer to things to do in subsequent steps (step 3, step 4, etc) and I can ignore them.
I now run the app on Pixel 5 API 32 (android-arm64 emulator). It takes a while to build but this is what I get at the end on my emulator:
Create Firebase Project
I signed in to Firebase Console. I already had a project there: pascall-2022. I now create a new project for this codelab tutorial. I named the project Firebase Flutter Codelab. Firebase created a unique project name for this title: fir-flutter-codelab-db94c.
I disable Analytics.
I click on Build; then Authentication; and then pick e-mail and password authentication only.
I then click on Firestore Database and click on Create Database. I start in Test Mode. and Southeast Australia as my Cloud Firestore location. Click Enable and now I am ready to configure my project.
Firebase configuration
On Flutter Page 7, I used flutterfire configure
command from a VS Code terminal window to connect an app to Firebase. When running flutterfire configure
, I nominated the devices (e.g. iOS and Android). Now, following the tutorial, I will do each configuration manually using Firebase Console.
First, I add the FlutterFire libraries for the two Firebase products I am utilizing in this app - Firebase Auth and Cloud Firestore. I run the following three commands to add the depencies. I run them in VS Code terminal in folder flutter-codelabs/firebase-get-to-know-flutter/step_02:
flutter pub add firebase_core
flutter pub add firebase_auth
flutter pub add cloud_firestore
This adds the following lines to my pubspec.yaml file:
firebase_core: ^1.22.0
firebase_auth: ^3.8.0
cloud_firestore: ^3.4.7
The complete set of all plugins can be found here: firebase.google.com/docs/flutter/setup?platform=android#available-plugins.
I then run
flutter pub get
I had already done this at the beginning when I copied all the files but I do it again just in case. It does not do anything this time.
I also had to add provider
:
$ flutter pub add provider
iOs Configuration
In VS Code terminal in folder flutter-codelabs/firebase-get-to-know-flutter/step_02:
open ios/Runner.xcworkspace
This start Xcode app. Clicking on the Runner tab, I find the iOS identity:
It is com.example.gtkFlutter
. Go to Firebase Console; click on Project Overview; and then iOs configuration; enter this iOS identity; give a nickname if you please; and click ro register.
Then, in Step 2 on Firebase Console, download the configuration file into your Downloads folder and copy that file into Xcode app:
Skip the remaining steps on Firebase Console by repeatedly clicking on NEXT.
I now try to run the main.dart on iPhone SE(3rd generation) (ios simulator). But it did not work. I had the following message on the VS Code DEBUG CONSOLE output:
Do I need to update Xcode? My Xcode version is Version 13.4 (13F17a). The current version is 13.4.1. I do not think the error is caused by having an old Xcode version. Installing Xcode took a very long tikme. Therefore I am reluctant to redo it.
I did a flutter upgrade
. It did take a couple of minutes and upgraded flutter and dart. But the “pod install” problem remained.
I tried to tun it on an Android simulator and found out that flutter upgrade had reset the minSDK version in the build.gradle file. I had to set it at 21 to be able to run the app on Android emulator (see Page 7 for how this is done). After that, I am able to tun it on Android emulator but not on Apple iPhone emulator.
Pod install error
Following the advice in various places, I did
sudo arch -x86_64 gem install ffi
arch -x86_64 pod install
The first one can be sarted from any folder. The last one should be from the ios
folder for this app, i.e. flutter-codelabs/firebase-get-to-know-flutter/step_02/ios.
Nothing changed. Still the same error as above.
Ruby version !?
Tarlan Isaev thought it could have been the ruby version and suggested not upgrading ruby above the Ruby version 2.6.8xxx. My ruby version is 2,6,8p205, so it cannot be that.
$ ruby -v
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]
Update CoCoaPods
A Goodman on KindaCode claims this is related to not being able to update the CocoaPods’s specs repository and suggests two alternate solutions to fix it:
Goodman Solution 1
Delete the podfile.lock file in iOS folder of my project. I do not have this file so I will skip this step. Apparently, “Podfile.lock” is used to make sure that every team member has the same versions of pods installed on the project. It will be auto-generated with the “flutter run” command. I do not have this file probably because I have not yet been able to run this app on an iOS emulator.
Also, in the ios folder, run the following command:
$ pod install --repo-update
This did not work for me. I had many lines of output (mostly names of the files) that ended with:
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: https://www.ruby-lang.org/bugreport.html
Abort trap: 6
Let us hope the second solution is better.
Goodman Solution 2
At the root of your project, execute this command:
flutter clean
This created the following output for me:
$ flutter clean
Cleaning Xcode workspace... 2,915ms
Cleaning Xcode workspace... 2,754ms
Deleting build... 285ms
Deleting .dart_tool... 5ms
Deleting Generated.xcconfig... 0ms
Deleting flutter_export_environment.sh... 0ms
Deleting Flutter.podspec... 0ms
Deleting ephemeral... 0ms
Deleting .flutter-plugins-dependencies... 1ms
Deleting .flutter-plugins... 0ms
Go to the ios folder and delete the Pods folder and the Podfile.lock file. I have no lock file so I only deleted the Pods folder.
Go back to the root directory of your project and run:
$ flutter pub get
Running "flutter pub get" in step_02... 2,362ms
Go to your ios folder again then run:
pod install
Unfortunately, this did not work for me either. I get the same Abort trap : 6
termination as in Solution #1 above.
macOS
The same as iOS. The same errors.
chrome Web
No problem. So I have two working: Android and web (chrome) emulators.
I think I will park this issue for the moment. I will continue with the Android emulator. The app does not have to run on the iOS emulator as long as it runs on the real iOS device, which I hopefully will be in a position to test in not too distant future.