I’m having a look at the Flutter framework as I’ve been playing with an iOS app for several years – I’ve been through Objective C and a few incarnations of Swift. However, I’m sure I could be far more productive if I could code in Java (before you tell me to write an Android app instead, then I’m confident I could knock that out really quick – I want to take on the bigger challenge of iOS first). And its a big win if I can write my code once for both iOS and Android! I’m not too worries about “web” for now, but I’m more than happy to pick up a front-end framework that I can use for other uses.

Flutter uses the Dart language which looks like a good option for me: I have considerable experience with Java (predated with C), and Dart is a descendant of Algol so I feel right at home. I TDD my code so a good testing framework is essential – happily mockito is available for Dart (I prefer this to rolling my own stubs).

My first objective is to try out a PoC to see if I can achieve the more challenging bits of my app. Before I can go far, I need to sign-in to Firebase – that’s my back-end. I’ve written a few articles already on integrating Firebase-UI with iOS, but for the time being I just need to ensure that I can achieve this – I don’t need all the different implementations (Twitter, Facebook etc) yet.

I’ve installed Flutter and I’m using IntelliJ (Ultimate) for my IDE. I’ve been through the “Getting Started” example, and things are looking promising (with the exception that debug and hot-reload don’t work for my iOS simulator – thats a known issue at the moment – but the android simulator does the job fine, and that’s good enough for now).

This firebase article gives a good example on setting things up, and includes some instructions on using the FlutterFire range of Firebase plugins for Flutter. This github project is a demo on authentication using Flutter and Firebase, so this seemed a perfect app to build. I took the code from main.dart and tried it out.

I was quickly up, but not quite running. I’m not sure if I missed something somewhere, but when I ran my app, I got an error:

E/FirebaseInstanceId("6066"): Token retrieval failed: AUTHENTICATION_FAILED

The 6066 is the process id (I think) rather than an error code, so you could have any number in there.

I had downloaded my google-service.json file and it was in the correct place. My Firebase console showed that Google was enabled as a sign-in provider (another culprit for this error).

It turns out that to enable Google Sign-in, you also need to enable a service from within your Google Cloud account:

  1. Navigate to your Google Cloud Dashboard: https://console.developers.google.com/apis/dashboard
  2. From there, its over to “APIs and Services”, and you need to enable the “People API”.

Another thing you can’t afford to miss out is the certificate fingerprint. IntelliJ (I think!) automatically created a keystore holding a certificate, stored in ~/.android/debug.keystore. The following command will show you the necessary bit:

keytool -exportcert -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore | grep SHA1

Unless you’ve changed things yourself, there will be no password on the keystore, so if primpted for it, press Enter. You need to copy the SHA1 fingerprint and paste it into the Firebase console for your app (Project Overview : Project Settings). Once you’ve found you app, then you need to press “Add fingerprint” and paste it in.

With this enabled, the example Google sign-in app worked!

However, shortly afterwards, it stopped working again. I spent a lot of time trying to get it going, and eventually found that deleting the app and user from the Android device (using the Settings app on the device simulator), followed by Wiping the data and a cold boot (from the AVD Manager in IntelliJ) would allow the app to work. However, even this wasn’t 100% reliable.

After some digging, I believe that this is a known issue (at time of writing), and there is a pull request waiting on the codebase for the Firebase plugin. Once this is merged, I expect this issue to disappear!