8

I'm trying to implement App Check in my Flutter app for Android and have followed the flutterfire documentation. I have already complete the installation part outlined here: https://firebase.flutter.dev/docs/app-check/overview Now I am following this documentation for usage: https://firebase.flutter.dev/docs/app-check/usage

So I have added the await FirebaseAppCheck.instance.activate(webRecaptchaSiteKey: 'recaptcha-v3-site-key'); to my Main method, right after the call to initialize firebase.

Now I need to enable debugging with the App Check and the documentation says I should add this dependency to my app/build.gradle file: implementation 'com.google.firebase:firebase-appcheck-debug:16.0.0-beta01' and add the following code snippet to my MainActivity.java onCreate method:

import com.google.firebase.appcheck.FirebaseAppCheck;

FirebaseApp.initializeApp(/*context=*/ this);
FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance();
firebaseAppCheck.installAppCheckProviderFactory(DebugAppCheckProviderFactory.getInstance());

Which I have tried to do by creating the MainActivity.java with the following command in my project root folder: flutter create -a java .

So my MainActivity.java looks like this:

import io.flutter.embedding.android.FlutterActivity;
import com.google.firebase.appcheck.FirebaseAppCheck;

public class MainActivity extends FlutterActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            FirebaseApp.initializeApp(/*context=*/ this);
            FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance();
            firebaseAppCheck.installAppCheckProviderFactory(
            DebugAppCheckProviderFactory.getInstance());
      }
}

When trying to run the app in debug mode I get the this error: Execution failed for task ':app:compileDebugJavaWithJavac'.

What am I missing? Have seen other posts with the same problem but no solution.

Tobias Svendsen
  • 115
  • 1
  • 8

1 Answers1

-2

This should be your main.dart

import 'package:firebase_app_check/firebase_app_check.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await FirebaseAppCheck.instance.activate();
}

Note: await FirebaseAppCheck.instance.activate(); does not have webRecaptchaSiteKey: 'recaptcha-v3-site-key' for Android/iOS App

This should be your MainActivity.kt

package com.example.app // your package

import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import com.google.firebase.FirebaseApp
import com.google.firebase.appcheck.FirebaseAppCheck
import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory

class MainActivity: FlutterActivity() {
    private val CHANNEL = "samples.flutter.dev/example"

    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
            call, result ->
            FirebaseApp.initializeApp(/*context=*/this)
            val firebaseAppCheck = FirebaseAppCheck.getInstance()
            firebaseAppCheck.installAppCheckProviderFactory(
                    DebugAppCheckProviderFactory.getInstance()
            )
        }
    }
}
Hrvoje Čukman
  • 421
  • 4
  • 12