flutterfire
flutterfire copied to clipboard
[📚] Appcheck debug build
Firebase official documentation says the following :
In your debug build, configure App Check to use the debug provider factory: [code snippet]
Flutter fire documentation says the following
Install the debug provider using the following snippet, e.g. in your MainActivity.java onCreate method:
import com.google.firebase.appcheck.FirebaseAppCheck;
FirebaseApp.initializeApp(/*context=*/ this);
FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance();
firebaseAppCheck.installAppCheckProviderFactory(
DebugAppCheckProviderFactory.getInstance());
The documentation is specifically unclear about debug build
. I assume that the above snippet should not be added to the main/MainActivity.kt but to a debug variant. So I tried to create `debug/com/cedvdb/x/MainActivity.kt but this throws the error:
e: Redeclaration: MainActivity
It seems like the debug variant cannot be redeclared like this, but then how ?
It would be nice if the appcheck documentation was updated to cover that debug build point, taking into account that some are not familiar with kotlin.
My final snippet that compiles is:
import io.flutter.embedding.android.FlutterActivity
import android.os.Bundle
import com.google.firebase.FirebaseApp
import com.google.firebase.appcheck.FirebaseAppCheck
import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
FirebaseApp.initializeApp(/*context=*/this)
val firebaseAppCheck = FirebaseAppCheck.getInstance()
firebaseAppCheck.installAppCheckProviderFactory(
DebugAppCheckProviderFactory.getInstance()
)
}
}
I got this problem too on Android emulator. There is no a useful documentation from Firebase nor FlutterFire
AppCheck documentation is the worse Google has ever written. The team behind it needs to be fired Thank you so much for your help
don't forget to 👍 for visibility
Using a MethodChannel
, you can control that the method channel gets invoked only in kDebugMode
from Flutter: https://stackoverflow.com/a/73330541/5066615