Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] java.lang.IllegalStateException UnityPlayerGameActivity FirebaseApp was deleted #1156

Open
UnwindGamesDeveloper opened this issue Nov 30, 2024 · 9 comments
Labels
api: core needs-attention Need Googler's attention

Comments

@UnwindGamesDeveloper
Copy link

UnwindGamesDeveloper commented Nov 30, 2024

Description

Game Crashes at Launch some times.

Reproducing the issue

  • Add the Firebase Unity SDK.
  • Instantiate Firebase via FirebaseApp.Create instead of default instance.
  • Remove FirebaseInitProvider from manifest --- provider android:name="com.google.firebase.provider.FirebaseInitProvider" android:authorities="xyz.firebaseinitprovider" tools:node="remove"

Firebase Unity SDK Version

12.4.1

Unity editor version

6000.0.27f1

Installation Method

.unitypackage

Problematic Firebase Component(s)

No response

Other Firebase Component(s) in use

No response

Additional SDKs you are using

No response

Targeted Platform(s)

Android

Unity editor platform

Mac

Scripting Runtime

IL2CPP

Release Distribution Type

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

Relevant Log Output

java.lang.IllegalStateException: FirebaseApp was deleted
        at com.google.android.gms.common.internal.Preconditions.checkState(com.google.android.gms:play-services-basement@@18.3.0:2)
        at com.google.firebase.FirebaseApp.checkNotDeleted(FirebaseApp.java:462)
        at com.google.firebase.FirebaseApp.getApplicationContext(FirebaseApp.java:122)
        at com.google.firebase.installations.FirebaseInstallations.getPrefsWithGeneratedIdMultiProcessSafe(FirebaseInstallations.java:475)
        at com.google.firebase.installations.FirebaseInstallations.doRegistrationOrRefresh(FirebaseInstallations.java:361)
        at com.google.firebase.installations.FirebaseInstallations.lambda$getToken$2$com-google-firebase-installations-FirebaseInstallations(FirebaseInstallations.java:261)
        at com.google.firebase.installations.FirebaseInstallations$$ExternalSyntheticLambda4.run(D8$$SyntheticClass)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at com.google.firebase.concurrent.CustomThreadFactory.lambda$newThread$0$com-google-firebase-concurrent-CustomThreadFactory(CustomThreadFactory.java:47)
        at com.google.firebase.concurrent.CustomThreadFactory$$ExternalSyntheticLambda0.run(D8$$SyntheticClass)
        at java.lang.Thread.run(Thread.java:923)

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

Expand Podfile.lock snippet
👀 Replace this line with the contents of your Podfile.lock!
@google-oss-bot
Copy link

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

@argzdev
Copy link

argzdev commented Jan 21, 2025

Hey @UnwindGamesDeveloper, sorry for the delayed response here. Could you share with me what Firebase products are you using? Also is there any chance you could share steps to reproduce the behavior or a minimal reproducible example? It'll help speed up our investigation. Thanks!

@argzdev argzdev added the needs-info Need information for the developer label Jan 21, 2025
@UnwindGamesDeveloper
Copy link
Author

UnwindGamesDeveloper commented Jan 21, 2025

HI @argzdev , It's been a while , so haven't updated firebase sdk since (still on 12.4.1).
We are using only Analytics and Crashlytics.

What we want is to control the initialization of firebase (in our unity game )from C# side. Hence, wanted to remove node from manifest like this:

<provider android:name="com.google.firebase.provider.FirebaseInitProvider" android:authorities="${applicationId}.firebaseinitprovider" tools:node="remove" />

And on unity side , somthing like this:

            `if (dependencyStatus == DependencyStatus.Available)
            {

#if SOME_PREPROCESSOR
AppOptions options = null;

                options = new AppOptions
                {
                    ApiKey = "OurKey"
                    AppId = "123456789",
                    ProjectId = "project-id"
                };


                firebaseApp = FirebaseApp.Create(options);
                
                Crashlytics.ReportUncaughtExceptionsAsFatal = true;

#endif

            }`

When doing this at runtime we were getting this exception :

java.lang.IllegalStateException: FirebaseApp was deleted
at com.google.android.gms.common.internal.Preconditions.checkState(com.google.android.gms:play-services-basement@@18.3.0:2)
at com.google.firebase.FirebaseApp.checkNotDeleted(FirebaseApp.java:462)
at com.google.firebase.FirebaseApp.getApplicationContext(FirebaseApp.java:122)
at com.google.firebase.installations.FirebaseInstallations.getPrefsWithGeneratedIdMultiProcessSafe(FirebaseInstallations.java:475)
at com.google.firebase.installations.FirebaseInstallations.doRegistrationOrRefresh(FirebaseInstallations.java:361)
at com.google.firebase.installations.FirebaseInstallations.lambda$getToken$2$com-google-firebase-installations-FirebaseInstallations(FirebaseInstallations.java:261)
at com.google.firebase.installations.FirebaseInstallations$$ExternalSyntheticLambda4.run(D8$$SyntheticClass)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.firebase.concurrent.CustomThreadFactory.lambda$newThread$0$com-google-firebase-concurrent-CustomThreadFactory(CustomThreadFactory.java:47)
at com.google.firebase.concurrent.CustomThreadFactory$$ExternalSyntheticLambda0.run(D8$$SyntheticClass)
at java.lang.Thread.run(Thread.java:923)

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Jan 21, 2025
@argzdev
Copy link

argzdev commented Jan 27, 2025

Thanks for providing code snippets, @UnwindGamesDeveloper. So far, I'm unable to reproduce the same behavior. I used our Firebase quickstart Unity for Crashlytics and added the similar code snippet with your setup. The Firebase Console was able to display the crashes being sent from the app. I don't see any runtime issue of java.lang.IllegalStateException: FirebaseApp was deleted.

Code snippet I have is fairly similar to yours:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
  <application>
    <provider android:name="com.google.firebase.provider.FirebaseInitProvider" android:authorities="com.google.firebase.unity.crashlytics.testapp.firebaseinitprovider" android:exported="false" tools:node="remove" />
    <!--Used when Application Entry is set to Activity, otherwise remove this activity block-->
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
    <!--Used when Application Entry is set to GameActivity, otherwise remove this activity block-->
    <activity android:name="com.unity3d.player.UnityPlayerGameActivity" android:theme="@style/UnityThemeSelector">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
      <meta-data android:name="android.app.lib_name" android:value="game" />
    </activity>
  </application>
</manifest>
   public virtual void Start() {
      FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
        dependencyStatus = task.Result;
        if (dependencyStatus == DependencyStatus.Available) {
          InitializeFirebase();
        } else {
          Debug.LogError(
            "Could not resolve all Firebase dependencies: " + dependencyStatus);
        }
      });
    }

    void InitializeFirebase() {
      Firebase.AppOptions appOptions = new Firebase.AppOptions
      {
        ApiKey = "AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxZQ",
        AppId = "1:700000000000000:android:0000000000000002",
        ProjectId = "xxxxx-xxxxxxx-xxxxxxx"
      };

      var app = Firebase.FirebaseApp.Create(appOptions);
      firebaseInitialized = true;
    }

I'm currently using the latest version of Firebase 12.5.0 and Unity Editor 6000.0.34f1, not sure if that makes any difference. Am I missing anything?

@argzdev argzdev added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Jan 27, 2025
@UnwindGamesDeveloper
Copy link
Author

@argzdev Yes , this exact same setup was leading to the issues mentioned earlier. Although i was on 12.4.1. I'll update to 12.5.0 and confirm on it again.

Will update this in a while.

@argzdev
Copy link

argzdev commented Jan 30, 2025

In that case, there could be a different configuration that is causing this issue. If you're still encountering the issue, please provide us an MCVE so we can investigate this further. Thanks!

@UnwindGamesDeveloper
Copy link
Author

Also additional info , which i forgot to add initially (My bad! ) is that this execption "java.lang.IllegalStateException: FirebaseApp was deleted." was never caught by crashlytics itself. We also have integrated Bugsnag as a secodary soruce for tracking exceptions . It was bugsnag which was catching this exception.

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Jan 31, 2025
@argzdev
Copy link

argzdev commented Jan 31, 2025

Thanks for the additional info. That said, we still need an MCVE to investigate this further since we're unable to reproduce this behavior on our side.

From my understanding, the error "java.lang.IllegalStateException: FirebaseApp was deleted" means that the default Firebase app instance already exist and is being replaced which causes to throw this issue. You could be running an instantiation code more than once.

FYI, Firebase Analytics cannot function by manual instantiation. This is still an open feature request in our Firebase Android SDK repo. There are a couple of suggestion by other developers as alternative solution, however we don't have any official guide for that as of the moment.

@argzdev argzdev added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Jan 31, 2025
@UnwindGamesDeveloper
Copy link
Author

"From my understanding, the error "java.lang.IllegalStateException: FirebaseApp was deleted" means that the default Firebase app instance already exist and is being replaced which causes to throw this issue. You could be running an instantiation code more than once."

Yeah from my end , will double check on this part as well.

Also would give a thorough MCVE if i still encounter it.

Thanks for quick responses @argzdev !

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: core needs-attention Need Googler's attention
Projects
None yet
Development

No branches or pull requests

3 participants