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

Initialize modules individually #2

Open
chi-anykraft opened this issue Nov 26, 2024 · 7 comments
Open

Initialize modules individually #2

chi-anykraft opened this issue Nov 26, 2024 · 7 comments

Comments

@chi-anykraft
Copy link

Hi,

I have a Unity project using Firebase Auth, Analytics, Crashlytics along with Messaging. As far as I know Auth, Analytics, Crashlytics work without Google Play Services while it is required for Messaging. My app's core work without Messaging but requires Auth at the very least. I found a case where a device does not have Google Play Services and causing Firebase.FirebaseApp.CheckAndFixDependenciesAsync() to fail due to Messaging, and it actually disables other Firebase modules as well.

Is there a way to initialize modules individually, so that the app can still operate without Messaging?

Thanks in advance,
Chi

@aprius
Copy link
Member

aprius commented Dec 10, 2024

I think you could handle your thread to initialize firebase completely so that there is only one initialization thread instead of multiple CheckAndFixDependenciesAsync for each module in parallel

 public bool IsInitCompleted { get; private set; }


Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available) {
// Create and hold a reference to your FirebaseApp,
// where app is a Firebase.FirebaseApp property of your application class.
app = Firebase.FirebaseApp.DefaultInstance;
IsInitCompleted = true; // you can use IsInitCompleted to determine if firebase initialization is complete in other modules
} 
});

@chi-anykraft
Copy link
Author

Hi, thanks for getting back to me.

This is not about multiple parallel initialization. There was a case where the device does not have Google Play Services, so the Firebase Messaging does not work; failing the initialization. Authentication and Analytics should works when I do not use Firebase Messaging, but when I do, it actually fails the entire FirebaseApp and causes Authentication and Analytics to fail as well. I was wondering if there is a way to gracefully handle Firebase Messaging dependency failure, and still be able to use Authentication and Analytics.

@aprius
Copy link
Member

aprius commented Dec 10, 2024

Well, if that's the case then there's no way, because Google Play services is a system app and you can't manipulate it from another app.

@aprius
Copy link
Member

aprius commented Dec 10, 2024

Normally it will always be on unless turned off by the user.

@chi-anykraft
Copy link
Author

Some Android distros are without Play services apparently, like Kindle Fire.

what I cannot understand here is that why can't I individually control what module to enable/initialize. If is is possible to do the dependency check/initialize each module individually, I should be able to use Authentication and Analytics even if Messaging is having dependency issue.

@aprius
Copy link
Member

aprius commented Dec 10, 2024

FCM uses device tokens to uniquely identify devices for messaging, Google Play services manage these tokens, handling updates and synchronizations automatically. Besides Google Play services help authenticate devices and ensure secure communication between the Firebase backend and the app. Since it is based on the existing google play service system so what you want to modularize is not possible. In case of devices where google play service is not available you can try another 3rd party solution

@chi-anykraft
Copy link
Author

Hey thanks for answering long thread. I just wanted to make it clear, I have tested that it works with no problem when I only include Auth and Analytics packages. When I include Messaging, it fails the entire FirebaseApp. I want to be able to still use Auth and Analytics even if Messaging fails. Messaging is optional in terms of core business logic. So I wanted a way to pick which modules to check dependency/initialize. I want to avoid using FCM when there is no Google Play services installed on the device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants