I did all of the below steps and now I can't connect to Firebase because of Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Invalid appcheck token. I got the same error on both the emulator and a real device. Also, now the app won't connect to Firebase at all. I checked some of my other apps without the below code and all of them connect and work fine.

All of the steps are below.

1- I followed the below debug directions

D DebugAppCheckProvider: Enter this debug secret into the allow list in the Firebase Console for your project: 123a4567-b89c-12d3-e456-789012345678

2- I went to Firebase Console > AppCheck > Apps > clicked the 3 dots on the Android App > Manage debug tokens > Add debug token > pasted in 123a4567-b89c-12d3-e456-789012345678 as the Name and for the Value I pressed Generate token.

When I ran my app I got the following in LogCat:

Enter this debug secret into the allow list in the Firebase Console for your project: XXXXXXXX-YYYY-ZZZZ-AAAA-XXXXXXXXXXXX
Detected invalid AppCheck token. Reconnecting (2 attempts remaining)
Detected invalid AppCheck token. Reconnecting (1 attempts remaining)
Detected invalid AppCheck token. Reconnecting (0 attempts remaining)
Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Invalid appcheck token

Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: No AppCheckProvider installed.

3- I then did the same thing as described above but for the Name I pasted XXXXXXXX-YYYY-ZZZZ-AAAA-XXXXXXXXXXXX and generated another token for the Value:

enter image description here

4- gradle:

implementation(platform('com.google.firebase:firebase-bom:32.3.1'))
implementation("com.google.firebase:firebase-appcheck-ktx")
implementation("com.google.firebase:firebase-appcheck-debug")
implementation("com.google.firebase:firebase-appcheck-playintegrity")

5- MainActivity:

override fun onCreate(savedInstanceState: Bundle?) {
    installSplashScreen()
    super.onCreate(savedInstanceState)

    if (BuildConfig.DEBUG) {
        Firebase.appCheck.installAppCheckProviderFactory(
            DebugAppCheckProviderFactory.getInstance(),
        )
    } else {
        Firebase.appCheck.installAppCheckProviderFactory(
            PlayIntegrityAppCheckProviderFactory.getInstance(),
        )
    }
}

6- In Google Play Console I went to The_Specific_App_Im_Using > Setup > App Signing > copied SHA-256 certificate fingerprint.

enter image description here

7- I went to Firebase Console > AppCheck > Apps > clicked the Android App > clicked Play Integrity > pasted the SHA-256 certificate fingerprint from the Play Store.

enter image description here

FYI the other two SHA-256 certificates were previously added, I forgot why, but it had something to do with RevenueCat

8- In Google Console > Credentials > Android key (auto created by Firebase) > On the accompanying screen I ticked Android apps & Don't restrict key pressed ADD and added my package name (top of any android studio file) & added my SHA-1 key for the fingerprint.

To get the SHA-1 key I ran this in terminal:

$ keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore

For the password I entered android as explained here

enter image description here

1

There are 1 answers

1
Lance Samaria On

When I added the firebase debug secret test key 123a4567-b89c-12d3-e456-789012345678 into the Value section of step 2 from my question, I got the following error:

Debug token value must be a version 4 UUID

enter image description here

This led me to adding it inside the Name section and generating a token for a value, which was accepted. Because it was accepted, I did the same thing for the key that was printed in Logcat from step 3: Enter this debug secret into the allow list in the Firebase Console for your project: XXXXXXXX-YYYY-ZZZZ-AAAA-XXXXXXXXXXXX, which was also accepted but that was also causing the problem.

What was never explained in any of the directions that I followed is that the token that is printed out in Logcat from step 3 Enter this debug secret into the allow list in the Firebase Console for your project: XXXXXXXX-YYYY-ZZZZ-AAAA-XXXXXXXXXXXX, is supposed to go in the Value section from step 2. You can add whatever name you want in the Name section. Here's an example

enter image description here

It turns out 123a4567-b89c-12d3-e456-789012345678 is an example key, it does nothing. And as I previously mentioned, no one said that the real key is supposed to go into the Value section (it might seem obvious to some, but what's Generate token for?). This whole mixup was poorly explained on Firebase's part.

VERY IMPORTANT

  1. For Android, every testing device and emulator that you use will get its own message of Enter this debug secret into the allow list in the Firebase Console for your project: XXXXXXXX-YYYY-ZZZZ-AAAA-XXXXXXXXXXXX. So you will have to go to Step-2 from my question and enter in that new key for each one. For example I use 2 emulators and 1 real device so I have 3 Name/Values pairs in there.

  2. If you're using a real Android device, you may have to wait several minutes before it syncs up. After I entered in the debug secret associated with a real device, it took about 15 minutes before I was able to connect to Firebase via Android Studio.

  3. For iOS, you have to do the same thing. Each simulator and real device that you use for testing, has to have their own individual Value for step 2 in my question. In the debugger, you will see: [Firebase/AppCheck][...] Firebase App Check debug token: XXXXXXXX-YYYY-ZZZZ-AAAA-XXXXXXXXXXXX. For example, I use 1 simulator and 1 real device, so for iOS I have 2 Name/Value pairs.