firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
236 stars 39 forks source link

[Bug] Android AppCheck "No AppCheckProvider installed" #1158

Closed BigTeaTime closed 3 weeks ago

BigTeaTime commented 1 month ago

Description

Android FirebaseAppCheck.GetAppCheckTokenAsync will return as faulted with the error "No AppCheckProvider installed" if FirebaseAnalytics.GetAnalyticsInstanceIdAsync has been called prior. If FirebaseAnalytics.GetAnalyticsInstanceIdAsync has not been called, FirebaseAppCheck.GetAppCheckTokenAsync completes without error.

Reproducing the issue

  1. Invoke FirebaseAnalytics.GetAnalyticsInstanceIdAsync
  2. Invoke FirebaseAppCheck.SetAppCheckProviderFactory(PlayIntegrityProviderFactory.Instance);
  3. Invoke FirebaseAppCheck.DefaultInstance.GetAppCheckTokenAsync()
  4. Observe the GetAppCheckTokenAsync() task exception message "No AppCheckProvider installed"

Firebase Unity SDK Version

12.4.1

Unity editor version

2022.3.49f1

Installation Method

.unitypackage

Problematic Firebase Component(s)

App Check

Other Firebase Component(s) in use

Analytics

Additional SDKs you are using

No response

Targeted Platform(s)

Android

Unity editor platform

Windows

Scripting Runtime

IL2CPP

Release Distribution Type

Pre-built SDK from https://firebase.google.com/download/unity

Relevant Log Output

No response

If using CocoaPods for Apple platforms, the project's Podfile.lock

Expand Podfile.lock snippet
```yml 👀 Replace this line with the contents of your Podfile.lock! ```
google-oss-bot commented 1 month ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

BigTeaTime commented 1 month ago

AppCheckFailLogs.txt

argzdev commented 1 month ago

Hey @BigTeaTime, thanks for reaching out. This is working as intended. According to the docs, you need to instantiate the FirebaseAppCheck before any firebase calls, including instantiation of Firebase.

Add the following initialization code (AppCheck code) to your app so that it runs before you use any Firebase services including any creation of Firebase Apps

Here's an sample implementation with DebugAppCheckProvider:

public virtual void Start() {
      // Add AppCheck here
      DebugAppCheckProviderFactory.Instance.SetDebugToken(".......................");
      FirebaseAppCheck.SetAppCheckProviderFactory(DebugAppCheckProviderFactory.Instance);

      // Initialize Firebase
      FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
        dependencyStatus = task.Result;
        if (dependencyStatus == DependencyStatus.Available) {
          InitializeFirebase();
        } else {
          Debug.LogError(
            "Could not resolve all Firebase dependencies: " + dependencyStatus);
        }
      });
    }

Let me know if this works. Thanks!

OleksiiSB commented 1 month ago

@argzdev we have very similar situation and we set AppCheckProviderFactory before doing any other calls to Firebase SDK. What I noticed while checking logs - right after application starts there is initialization of Crashlytics happening (this happens way before the first scene is initialized) and it logs initialization of FirebaseApp. Also wanted to mention that we have the same code (with exception of using another provider) for iOS and there AppCheck works as expected. On Android we get the same error message about no provider initialized.

Here is part of the log that I see moments after starting application on device:

2024-12-10 16:47:38.932 26560-26560 SessionsDependencies    *****          D  Dependency to CRASHLYTICS added.
2024-12-10 16:47:38.943 26560-26560 FirebaseApp             *****          I  Device unlocked: initializing all Firebase APIs for app [DEFAULT]
2024-12-10 16:47:39.019 26560-26560 FirebaseSessions        *****          D  Initializing Firebase Sessions SDK.
2024-12-10 16:47:39.031 26560-26560 FirebaseCrashlytics     *****          I  Initializing Firebase Crashlytics 19.2.1 for games.starberry.idlevillage
2024-12-10 16:47:39.070 26560-26560 SessionsDependencies    *****          D  Subscriber CRASHLYTICS registered.
2024-12-10 16:47:39.078 26560-26591 DynamiteModule          *****          I  Considering local module com.google.android.gms.measurement.dynamite:127 and remote module com.google.android.gms.measurement.dynamite:130
2024-12-10 16:47:39.078 26560-26591 DynamiteModule          *****          I  Selected remote version of com.google.android.gms.measurement.dynamite, version >= 130
2024-12-10 16:47:39.078 26560-26591 DynamiteModule          *****          V  Dynamite loader version >= 2, using loadModule2NoCrashUtils
2024-12-10 16:47:39.104 26560-26603 NetworkSecurityConfig   *****          D  No Network Security Config specified, using platform default
2024-12-10 16:47:39.148 26560-26592 FirebaseCrashlytics     *****          I  No version control information found
2024-12-10 16:47:39.152 26560-26560 FirebaseInitProvider    *****          I  FirebaseApp initialization successful

Log that I added for testing from the default scene awake is happening way later:

2024-12-10 16:47:43.853 26560-26692 Unity                   *****          W  [TEST] StartSceneView.Awake()
google-oss-bot commented 1 month ago

Hey @BigTeaTime. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

OleksiiSB commented 1 month ago

Issue is still present. @argzdev do you have any updates?

google-oss-bot commented 1 month ago

Hey @BigTeaTime. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 3 weeks ago

Since there haven't been any recent updates here, I am going to close this issue.

@BigTeaTime if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.