调用 firebase.messaging() 在 Capacitor 构建中导致白屏,但在浏览器中正常运行。

huangapple go评论55阅读模式
英文:

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 消息服务。以下是一些现有的插件链接:

声明: 我是 @capacitor-firebase/messaging 的维护者。

英文:

You have to use a Capacitor plugin to integrate Firebase messaging.
Among others the following plugins exist:

Disclosure: I am the maintainer of @capacitor-firebase/messaging.

huangapple
  • 本文由 发表于 2023年3月31日 03:24:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892213.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定