6

Is it okay to install both app check provider factory? Or should I use only one for debug and other one for release? If yes then how to do it?

Code snippet I'm referring to:

package pl.matematykagryzie.app

import android.os.Bundle
import android.util.Log

import io.flutter.embedding.android.FlutterActivity

import com.google.firebase.FirebaseApp
import com.google.firebase.appcheck.FirebaseAppCheck
import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory
import com.google.firebase.appcheck.safetynet.SafetyNetAppCheckProviderFactory

import com.google.firebase.functions.FirebaseFunctions

class MainActivity: FlutterActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)

        // Initialize firebae app
        FirebaseApp.initializeApp(/*context=*/this)

        val firebaseAppCheck = FirebaseAppCheck.getInstance()
        firebaseAppCheck.installAppCheckProviderFactory(
            DebugAppCheckProviderFactory.getInstance())

        // Activate app check
        firebaseAppCheck.installAppCheckProviderFactory(
            SafetyNetAppCheckProviderFactory.getInstance())


        val data = hashMapOf(
            "isKotlin" to true
        )

        // Call a function
        FirebaseFunctions
            .getInstance("europe-central2")
            .getHttpsCallable("validateAppCheck")
            .call(data)
            .addOnFailureListener {
                Log.wtf("onCreate", "failure") 
            }
            .addOnSuccessListener {
                Log.wtf("onCreate", "success") 
            }
    }
}

Please note that I'm not kotlin nor android developer.

I'm developing a flutter app and recently added firebase app check which causes a lot of troubles to me and I'm pushing really hard to resolve them.

I'm trying to narrow down the scope of the issue I have.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Maciej Caputa
  • 1,831
  • 12
  • 20

2 Answers2

1

You should only install one factory, not both, as the last one you install overrides any previous factories.

There are a few options you have to install a different factory based on the build variant:

  • Use if(BuildConfig.DEBUG) installOne() else installAnother()
  • Place installation logic in different source sets i.e. src/release/java/AppCheckInitialization.kt and src/debug/java/AppCheckInitialization.kt both of which could have a fun initializeAppCheck() that can be called from your activity. Depending on what variant you build, the app will use the corresponding version of initializeAppCheck().
vkryachko
  • 406
  • 3
  • 6
0
    package com.example.app
    import android.os.Bundle
    import io.flutter.embedding.android.FlutterFragmentActivity
    import com.google.firebase.appcheck.FirebaseAppCheck;
    import com.google.firebase.FirebaseApp
    import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory
    import 

com.google.firebase.appcheck.playintegrity.PlayIntegrityAppCheckProviderFactory

    class MainActivity: FlutterFragmentActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            FirebaseApp.initializeApp(/*context=*/this)
            val firebaseAppCheck = FirebaseAppCheck.getInstance()
            firebaseAppCheck.installAppCheckProviderFactory(
                DebugAppCheckProviderFactory.getInstance()
            )
            firebaseAppCheck.installAppCheckProviderFactory(
                PlayIntegrityAppCheckProviderFactory.getInstance()
            )
            }
    }
Seth Samuel
  • 245
  • 1
  • 3