After updating to plugin version 1.1.0, app crashes immediately at launch on Android devices.
Log excerpt:
09-01 13:01:12.929 25125-25125/com.xxx.xxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx.xxx, PID: 25125
java.lang.ExceptionInInitializerError
at com.google.android.gms.internal.firebase-perf.zzw.zzae(Unknown Source)
at com.google.firebase.perf.metrics.Trace.start(Unknown Source)
at com.google.android.gms.internal.firebase-perf.zze.onActivityStarted(Unknown Source)
at android.app.Application.dispatchActivityStarted(Application.java:207)
at android.app.Activity.onStart(Activity.java:1191)
at org.apache.cordova.CordovaActivity.onStart(CordovaActivity.java:297)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1249)
at android.app.Activity.performStart(Activity.java:6701)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2751)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1496)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6186)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.xxx.xxx. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.1:219)
at com.google.android.gms.internal.firebase-perf.zzw.<init>(Unknown Source)
at com.google.android.gms.internal.firebase-perf.zzw.<clinit>(Unknown Source)
I realize this may be a duplicate of #142, #715 or #206 but those are closed and meant to be fixed.
We have been using the plugin for quite a while and never actually encountered this before. It's only occurring in plugin version 1.1.0 for us. We have downgraded to version 1.0.5 again and now everything works again. So, I thought I'd open a new issue for this as there may be some regression error. Happy to provide more info if there are questions...
+1
On iOS I was getting the error "Firebase isn't initialised" when calling the getToken method.
I also managed to get things working by downgrading to v1.0.5 (which my Android version was already running and was working fine with, as far as I could tell).
+1 I have the same problem
Get "Firebase isn't initialised" on Android after the DeviceReady,too
+1 Same issue, Was working 2 weeks ago, Just installed it and now android won't compile. iOS is fine though
In an GDPR approch you have to let users choose if they want or not to upload data to Firebase services. So Firebase haven't to be initialized by default.
Look at the code and use following methods to initialize services before using them :
exports.initFirebase
exports.initCrashlytics
exports.initAnalytics
exports.initPerformance
exports.initRemoteConfig
For my own I still using my fork which is working fine. I didn't have time to check if all merged PR are working.
Adding window.FirebasePlugin.initFirebase(); before getToken worked for me.
@CWollinger thanks! adding window.FirebasePlugin.initFirebase() worked for me too. i am using version 1.1.2
Calling window.FirebasePlugin.initFirebase() didn't work for me. App crashes just at startup.
Reviewing the plugin, version 1.0.5 I found this, :
Context context is defined and FirebaseApp.initializaApp(context) called on pluginitialize thread.
Edit,
I just read comment @gvieduc comment I I see that Firebase is not initialized by default.
I will recheck my code in case I made a mistake and, in case I can't fix it, I will downgrade.
Thanks for the fix @CWollinger
For Ionic 3 users add (<any>window).FirebasePlugin.initFirebase() before getToken
Looks like issue is related to this https://stackoverflow.com/questions/37321728/firebaseinitprovider-firebaseapp-initialization-unsuccessful we need google services on gradle.build file
Got the "Firebase isn't initialised" on Android. I have two computers, and one Ionic project : When i npm install > add android platform on the first one, then build : no problem, getToken() gives me the token. But on the second one i keep having the error even after 1/ doing the same exact steps, 2/ messing with MainActivity.java / push in build.gradle or manually adding dependencies.
The only differences i have on the 2 computers is Android Studio Versions & gradle.
@8tomo8 when you say : (<any>window).FirebasePlugin.initFirebase() where do i have to put this code exactly ? in which file ? Because my getToken() function is called in .ts file.
@8tomo8 I have the same question. I added (<any>window).FirebasePlugin.initFirebase() in app.components.ts, my app just froze. I'm using ionic 3 too. Could you please explain where I should use it?
@BrainOverflown @rubytann I am using iOS so Android would look slightly different, but here is my getToken() function that is working 100% on emulator and device. The code is in a provider that is called on the ionViewDidEnter() lifestyle hook on the root page.
async getToken() {
(<any>window).FirebasePlugin.initFirebase()
let token;
if (this.platform.is('ios')) {
token = await this.fireNative.getToken();
const perm = await this.fireNative.grantPermission()
}
return this.saveToken(token)
}
@8tomo8 Doesn't work for me, i got this error :
Uncaught (in promise): TypeError: (<any>window).FirebasePlugin.initFirebase(); is not a function
TypeError: (<any>window).FirebasePlugin.initFirebase(); is not a function
@BrainOverflown this isn't a suggested solution, but rather just isolating the problem. Can you put the getToken inside a timeout of 3 seconds from the ionViewDidEnter() and see if it makes a difference? I have had this before.
ionViewDidEnter() {
setTimeout(() => {
//call your get token from your provider here
},3000)
}
Did not change anything. "Firebase isn't initialised" still.
The problem is that i can build with "Firebase working well" on one computer, but not the second one.
Here is my code :
home.ts
ionViewWillEnter() {
this.platform.ready().then(() => {
this.statusBar.show();
});
this.firebaseNotifications.start().then(() => {
this.firebaseNotifications.onNotifications((data) => {
// data received
})
});
}
Which call on this provider : firebase-poc.ts
platform.ready().then(() => {
firebase.getToken().then(token => console.log(token)).catch(err => console.log(err));
firebase.onNotificationOpen().subscribe(data => {
console.log(data);
console.log(data.name)
const toast = this.toastCtrl.create({
message: data.body,
duration: 3000
});
toast.present();
}, err => console.log(err));
});
}
Created pull request to fix google services issue, which causes app crash, after this with latest changes we need to do window.FirebasePlugin.initFirebase()
@Drintios So basically, what you're advising is to update cordova-plugin-firebase to it's latest version which support the initFirebase method ?
yep, with my PR it shouldn't crash anymore
fix has been published via v1.1.3
You should reopen it, i still have the problem
@BrainOverflown would you suggest also reverting the PR?
No, since my problem is not related to the fix made by @Drintios .
Just let more people to test the commit and we'll see. Thank you
I am currently running into this issue now, this is happening on an iOS device. Have not tested this on an Android device.
App crashing/not starting ? or issue with init firebase in js console ?
Just with the init firebase part. I tried using the (<any>window).FirebasePlugin.initFirebase() solution, but that has been giving me a type error. I am building with Ionic 3.
i see, i think we need to open need thread for this issue as it not related to app crash.
I already did @Drintios
great :)
Thanks @BrainOverflown , I'll follow your thread!
Closing per the community discussion
On ionic v3 i created a provider for Analytics.. Works for me!
`import { Injectable } from '@angular/core';
import { Firebase } from '@ionic-native/firebase';
@Injectable()
export class AnalyticsProvider {
constructor(private firebaseCtrl: Firebase) { }
private initAnalytics(callback) {
(<any>window).FirebasePlugin.initAnalytics();
setTimeout(() => {
if (callback) callback();
}, 100);
}
setScreenName(name: string): void {
this.firebaseCtrl.setScreenName(name).then(
data => console.log('firebaseCtrl > setCurrentScreen > success', data),
error => {
console.log('firebaseCtrl > setCurrentScreen > error', error);
if (error == "Analytics isn't initialised") {
this.initAnalytics(() => this.setScreenName(name));
}
}
).catch(exception => console.error('firebaseCtrl > setCurrentScreen > exception', exception));
}
logEvent(event: string, data: any) {
this.firebaseCtrl.logEvent(event, data).then(
data => console.log('firebaseCtrl > logEvent > success', data),
error => {
console.log('firebaseCtrl > logEvent > error', error);
if (error == "Analytics isn't initialised") {
this.initAnalytics(() => this.logEvent(event, data));
}
}
).catch(exception => console.error('firebaseCtrl > logEvent > exception', exception));
}
}`
I managed to make it working (the 1.1.3 version) by calling these methods in my app.components.ts, just after the device is ready
observableFromEvent(document, 'deviceready').pipe(first()).subscribe(() => {
FirebasePlugin.initFirebase();
FirebasePlugin.initAnalytics();
})
You also need to declare Firebase Plugin to use it
declare var FirebasePlugin: any;
This is being fixed via #830. Hopefully the community can help get the PR tested soon so I can release the fix.
Unfortunately this is still exist on android
I need to support this legacy code and include firebase, all good on iOS just on Android it's always the same error. I checked the source code and indeed the firebase init code was there.
Any lead is highly appreciated.
Ionic:
Ionic CLI : 5.2.3
Ionic Framework : ionic-angular 3.9.5-201905161949
@ionic/app-scripts : 3.2.3
Cordova:
Cordova CLI : 8.1.2 ([email protected])
Cordova Platforms : android, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-webview 1.2.1, (and 34 other plugins)
Utility:
cordova-res : 0.6.0
native-run : 0.2.8
System:
Android SDK Tools : 26.1.1
ios-deploy : 1.9.2
NodeJS : v11.10.1
npm : 6.7.0
OS : macOS Mojave
Xcode : Xcode 10.1 Build version 10B61
Most helpful comment
@CWollinger thanks! adding window.FirebasePlugin.initFirebase() worked for me too. i am using version 1.1.2