Search code examples
androidfirebaseflutterfirebase-app-check

How can I set up App Check for my Android App in Flutter?


I'm trying to set up my App Check for my Android App with this guide: https://firebase.flutter.dev/docs/app-check/usage/

Somehow I can't add the DebugMode because the Mainactivity instruction is too unclear for me. I created an "onCreate" function into this MainActivity.java . The App could not even start. This is the file before I added all the lines like in the instruction:

package com.company.appname;

import io.flutter.embedding.android.FlutterActivity;

public class MainActivity extends FlutterActivity {
}

Anyway, so I decided to go for the normal way:

  1. pub add firebase_app_check / pub get
  2. I added this lines before my runApp():
await FirebaseAppCheck.instance.activate(),
await FirebaseAppCheck.instance.setTokenAutoRefreshEnabled(true),
FirebaseAppCheck.instance.onTokenChange.listen((token) {
        print(token);
      }),
  1. Took my SHA256 Key (debug) from my gradle signingreport and set it to my App Check in Firebase

Now I call a function from my App and get these results:

From my App:

W/FirebaseContextProvider(17912): Error getting App Check token. Error: com.google.firebase.FirebaseException: Too many attempts.

And from the firebase functions console:

Callable request verification passed {"verifications":{"auth":"VALID","app":"MISSING"}}

At this point I don't even know what to do next. Even if I can set up the DebugMode. When the app goes for production I will have the same errors right?


Solution

  • Had the problem again...

    It has to be on a physical phone. But this time a flutter clean helped.