flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[📚] Appcheck debug build

Open cedvdb opened this issue 2 years ago • 3 comments

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()
    )
  }
}

cedvdb avatar Apr 07 '22 20:04 cedvdb

I got this problem too on Android emulator. There is no a useful documentation from Firebase nor FlutterFire

gOzaru avatar Jul 08 '22 08:07 gOzaru

AppCheck documentation is the worse Google has ever written. The team behind it needs to be fired Thank you so much for your help

iamsethsamuel avatar Jul 21 '22 13:07 iamsethsamuel

don't forget to 👍 for visibility

cedvdb avatar Jul 21 '22 15:07 cedvdb

Using a MethodChannel, you can control that the method channel gets invoked only in kDebugMode from Flutter: https://stackoverflow.com/a/73330541/5066615

rohan20 avatar Aug 12 '22 07:08 rohan20

If you wish to follow steps for setting up app check debug, please follow instruction here for android & iOS.

russellwheatley avatar Aug 24 '22 10:08 russellwheatley