英文:
Calling firebase.messaging() yields white screen in Capacitor build, but works in the browser
问题
I'm building a web app and using Capacitor to build an Android version. Everything works until I add Firebase messaging in my app, which I import from the following firebase.js file:
import firebase from 'firebase/app'
import 'firebase/firebase-messaging'
const firebaseConfig = {
// my details here
};
firebase.initializeApp(firebaseConfig);
export default firebase.messaging()
When I do this, the app works fine when I serve it up in the browser, but when I run it in Capacitor (with no errors) shown, the app shows only a "white screen of death" in my Android emulator. Prior to that the app worked fine in the Android emulator.
I've narrowed the problem down to running firebase.messaging(). The app runs fine in Capacitor when I replace the last line above with export default function dummy_function() { return true; }
Unfortunately, the Android Studio event log says only "Failed to start monitoring emulator-5554." So that's not helpful!
How do I fix this? Here's my complete code.
英文:
I'm building a web app and using Capacitor to build an Android version. Everything works until I add Firebase messaging in my app, which I import from the following firebase.js file:
import firebase from 'firebase/app'
import 'firebase/firebase-messaging'
const firebaseConfig = {
// my details here
};
firebase.initializeApp(firebaseConfig);
export default firebase.messaging()
When I do this, the app works fine when I serve it up in the browser, but when I run it in Capacitor (with no errors) shown, the app shows only a "white screen of death" in my Android emulator. Prior to that the app worked fine in the Android emulator.
I've narrowed the problem down to running firebase.messaging(). The app runs fine in Capacitor when I replace the last line above with export default function dummy_function() { return true; }
Unfortunately the Android Studio event log says only "Failed to start monitoring emulator-5554". So that's not helpful!
How do I fix this? Here's my complete code.
答案1
得分: 1
你需要使用 Capacitor 插件来集成 Firebase 消息服务。以下是一些现有的插件链接:
- https://www.npmjs.com/package/@capacitor/push-notifications
- https://www.npmjs.com/package/@capacitor-firebase/messaging
- https://www.npmjs.com/package/@capacitor-community/fcm
声明: 我是 @capacitor-firebase/messaging 的维护者。
英文:
You have to use a Capacitor plugin to integrate Firebase messaging.
Among others the following plugins exist:
- https://www.npmjs.com/package/@capacitor/push-notifications
- https://www.npmjs.com/package/@capacitor-firebase/messaging
- https://www.npmjs.com/package/@capacitor-community/fcm
Disclosure: I am the maintainer of @capacitor-firebase/messaging.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论