hansemannn / titanium-firebase-core

Use the Firebase Core SDK in the Titanium SDK 🚀
Other
31 stars 23 forks source link

Default FirebaseApp is not initialized #25

Closed AppWerft closed 6 years ago

AppWerft commented 6 years ago
win.addEventListener('open', function() {
    FirebaseCore.configure({
        file:'google-services.json'
    });
});

This simple code above generates:

[ERROR] :  TiBaseActivity: (main) [43,43] Error dispatching lifecycle event: Default FirebaseApp is not initialized in this process de.appwerft.firebauseauth. Make sure to call FirebaseApp.initializeApp(Context) first.
[ERROR] :  TiBaseActivity: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process de.appwerft.firebauseauth. Make sure to call FirebaseApp.initializeApp(Context) first.
[ERROR] :  TiBaseActivity:  at com.google.firebase.FirebaseApp.getInstance(Unknown Source:60)
[ERROR] :  TiBaseActivity:  at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source:0)
[ERROR] :  TiBaseActivity:  at firebase.auth.TitaniumFirebaseAuthModule.onStart(TitaniumFirebaseAuthModule.java:94)
[ERROR] :  TiBaseActivity:  at org.appcelerator.titanium.TiLifecycle.fireLifecycleEvent(TiLifecycle.java:150)
[ERROR] :  TiBaseActivity:  at org.appcelerator.titanium.TiBaseActivity.onStart(TiBaseActivity.java:1378)
m1ga commented 6 years ago

But the error is from TitaniumFirebaseAuthModule. So where in your code do you use TitaniumFirebaseAuthModule.onStart? It looks like this is initialized before win.open()

AppWerft commented 6 years ago

This is a very good thought. I will inspect. I have used the original TitaniumFirebaseAuthModule. My new code comes from a submodule. The question is, when the onStart will fired? I guess:

onAppCreate: if app is started onStart: if the JS layer calls require

hansemannn commented 6 years ago

The app needs to be configured in the open event of the root window.

AppWerft commented 6 years ago

I guess the root window will build in app.js as first window. This I did in app.js:

var $ = Ti.UI.createWindow();
$.addEventListener('open',function() {
    FirebaseCore.configure();
    FirebaseAuth.createUserWithEmail({
        email:"rainer@com",
        password:"********",
        callback : function(e) {
            FirebaseAuth.signInWithEmail({
                email:"rainer@com",
                password:"********",
                callback : function(e) {
                    console.log(e);
                }
            });
        }
    });
});

I found in manual: FirebaseApp.initializeApp() return an instance of FirebaseApp.

In next module firebase.auth. in onStart() event in line 76(?) this will call mAuth = FirebaseAuth.getInstance();. If I call a Kroll.method like createUserWithEmail() mAuth is null.

AppWerft commented 6 years ago

I found: FirebaseCore.configure(); must run before window is opened. So the first (splash) activity will taken.