I'm trying to use App Check from Firebase in a Flutter project for my Android app, but as usual I've problems with Google.
It is said on the documentation to add this code to our Android code:
// kotlin code
FirebaseApp.initializeApp(/*context=*/this)
val firebaseAppCheck = FirebaseAppCheck.getInstance()
firebaseAppCheck.installAppCheckProviderFactory(
DebugAppCheckProviderFactory.getInstance()
)
So naturally, I edit my /android/app/src/main/kotlin/com/example/my_app/MainActivity.kt
file like so:
package fr.my_app.app
import io.flutter.embedding.android.FlutterActivity
import android.os.Bundle
import com.google.firebase.FirebaseApp
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
FirebaseApp.initializeApp(/*context=*/this)
val firebaseAppCheck = FirebaseAppCheck.getInstance()
firebaseAppCheck.installAppCheckProviderFactory(
DebugAppCheckProviderFactory.getInstance()
)
super.onCreate(savedInstanceState)
}
}
According to the FlutterFire documentation, we have to add a package:
import com.google.firebase.appcheck.FirebaseAppCheck
And there the problems begin:
- Android Studio, nor VSC nor IntelliJ IDEA, detect this package. They highlight the word
appcheck
in red and sayUnresolved reference: appcheck
. I understand that this package doesn't exist. - As a consequence, I have a failure when trying to build the app with
flutter run
:
blablabla\MainActivity.kt: Unresolved reference: DebugAppCheckProviderFactory
My goal
Accessing Firebase features with App Check in debug mode (Android only)
Notes
- I followed the whole official documentation
- I have my
build.gradle
up to date - I have my
pubspec.yaml
up to date - I have all my softwares up to date
What did I do wrong?
EDITS
All right I have found the correct packages here
Now another problem! It should print in the console the debug token for me to add it in the Firebase Console, but nothing happens. I mean that no debug token is given in the console, only an error when trying to access Firebase features:
E/StorageException(12120): { "error": { "code": 401, "message": "Firebase App Check token is invalid." }}
E/StorageException(12120): java.io.IOException: { "error": { "code": 401, "message": "Firebase App Check token is invalid." }}
E/StorageException(12120): at com.google.firebase.storage.network.NetworkRequest.parseResponse(NetworkRequest.java:445)
E/StorageException(12120): at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(NetworkRequest.java:462)
E/StorageException(12120): at com.google.firebase.storage.network.NetworkRequest.processResponseStream(NetworkRequest.java:453)
E/StorageException(12120): at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:272)
E/StorageException(12120): at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:289)
E/StorageException(12120): at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:76)
E/StorageException(12120): at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:68)
E/StorageException(12120): at com.google.firebase.storage.ListTask.run(ListTask.java:65)
E/StorageException(12120): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/StorageException(12120): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/StorageException(12120): at java.lang.Thread.run(Thread.java:923)
Am I the only one having trouble with Firebase like all the time? All the questions I asked on StackOverflow are about this thing.