javascript - IONIC 4:插件 firebase 和 google-maps 的问题 - 默认 FirebaseApp 未在此进程 com.superagent.agent 中初始化。一定要打电话
问题描述
我正在使用 Ionic 4 开发 android 应用程序,现在在使用 @ionic-native/google-maps 和 @ionic-native/firebase-messaging 时遇到问题。我无法接收推送通知并触发 Firebase 分析。但我的谷歌地图正常工作。另外,我正在为这些应用程序使用 Jscrambler
我总是在调用 fcm.getToken() 方法时遇到这个错误,即 fcm 是 firebase-messaging 插件的别名。这是错误:
ERROR Error: Uncaught (in promise): Default FirebaseApp is not initialized in this process com.xxx.xxx. Make sure to call FirebaseApp.initializeApp(Context) first.
at resolvePromise (/polyfills-es2015.js:4153)
at /polyfills-es2015.js:4063
at Object.callbackFromNative (cordova.js:297)
at processMessage (cordova.js:1134)
at processMessages (cordova.js:1157)
at ZoneDelegate.invoke (/polyfills-es2015.js:3715)
at Object.onInvoke (/vendor-es2015.js:82899)
at ZoneDelegate.invoke (/polyfills-es2015.js:3714)
at Zone.run (/polyfills-es2015.js:3480)
at /polyfills-es2015.js:4211
和在 app.component.ts 上调用 firebase getToken 的函数在这里:
async initializeApp() {
await this.platform.ready().then(() => {
this.params.getUserData().then(userdata => {
this.userData = userdata;
// set fcm token when there is saved session on storage for all environment
this.fcm.getToken().then(this.setDeviceId);
this.fcm.onTokenRefresh().subscribe(this.setDeviceId);
if(environment.production) {
// init fbase analytics only on production & there is saved session on storage
this.initFbAnalytics();
}else{
// subscribe to topic guest_dev when in develeopment mode
this.fcm.subscribe("guest_dev");
}
});
});
};
还有我的 package.json 文件依赖项:
"dependencies": {
"@angular/animations": "^8.2.0",
"@angular/common": "^8.2.0",
"@angular/core": "^8.2.0",
"@angular/forms": "^8.2.0",
"@angular/platform-browser": "^8.2.0",
"@angular/platform-browser-dynamic": "^8.2.0",
"@angular/router": "^8.2.0",
"@ionic-native/app-rate": "^5.33.1",
"@ionic-native/camera": "^5.11.0",
"@ionic-native/clipboard": "^5.27.0",
"@ionic-native/core": "^5.11.0",
"@ionic-native/facebook": "^5.28.0",
"@ionic-native/file": "^5.27.0",
"@ionic-native/file-opener": "^5.27.0",
"@ionic-native/firebase-analytics": "^5.11.0",
"@ionic-native/firebase-messaging": "^5.11.0",
"@ionic-native/google-maps": "^5.5.0",
"@ionic-native/in-app-browser": "^5.12.0",
"@ionic-native/keyboard": "^5.29.0",
"@ionic-native/market": "^5.26.0",
"@ionic-native/mobile-accessibility": "^5.30.0",
"@ionic-native/social-sharing": "^5.11.0",
"@ionic-native/splash-screen": "^5.11.0",
"@ionic-native/sqlite": "^5.29.0",
"@ionic-native/status-bar": "^5.11.0",
"@ionic/angular": "^4.7.1",
"@types/hammerjs": "^2.0.36",
"compare-func": "^2.0.0",
"cordova-android": "9.0.0",
"cordova-browser": "6.0.0",
"cordova-clipboard": "^1.3.0",
"cordova-plugin-androidx": "^1.0.2",
"cordova-plugin-androidx-adapter": "^1.1.0",
"cordova-plugin-appsflyer-sdk": "^4.4.22",
"cordova-plugin-camera": "4.1.0",
"cordova-plugin-device": "2.0.2",
"cordova-plugin-facebook4": "^6.4.0",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-file-opener2": "^3.0.4",
"cordova-plugin-firebase-analytics": "^3.0.0",
"cordova-plugin-firebase-messaging": "^3.0.0",
"cordova-plugin-inappbrowser": "^3.1.0",
"cordova-plugin-ionic-keyboard": "^2.0.5",
"cordova-plugin-ionic-webview": "^3.0.0",
"cordova-plugin-market": "^1.2.0",
"cordova-plugin-splashscreen": "5.0.2",
"cordova-plugin-statusbar": "2.4.2",
"cordova-plugin-whitelist": "1.3.3",
"cordova-plugin-x-socialsharing": "^5.4.7",
"cordova-sqlite-storage": "^5.1.0",
"cordova-support-android-plugin": "^1.0.1",
"cordova-support-google-services": "^1.3.1",
"core-js": "^2.6.9",
"crypto-js": "^4.0.0",
"dom-to-image-more": "^2.8.0",
"es6-promise-plugin": "^4.2.2",
"hammerjs": "^2.0.8",
"ion-bottom-drawer": "^2.0.0",
"ion2-calendar": "^3.0.0-rc.0",
"ionic-long-press": "2.0.3",
"jscrambler": "^5.5.25",
"jspdf": "^1.5.3",
"moment": "^2.27.0",
"rxjs": "~6.5.2",
"text-mask-core": "^5.1.2",
"tslib": "^1.10.0",
"zone.js": "~0.9.1"
}
哦,这是我的离子信息
Ionic:
Ionic CLI : 6.14.0 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 4.11.13
@angular-devkit/build-angular : 0.803.29
@angular-devkit/schematics : 8.3.29
@angular/cli : 8.2.2
@ionic/angular-toolkit : 2.3.3
Cordova:
Cordova CLI : 10.0.0
Cordova Platforms : not available
Cordova Plugins : not available
Utility:
cordova-res : not installed
native-run (update available: 1.4.0) : 1.3.0
System:
Android SDK Tools : 26.1.1 (/home/nt/Android/Sdk)
NodeJS : v10.19.0 (/usr/bin/node)
npm : 6.14.4
OS : Linux 5.8
解决方案
推荐阅读
- excel - 如果我关于 Metabase 的问题有一个带有图像预览的图像列,是否可以将其作为图像类型列本身导出到 excel 中?
- shell - 如何在 GNU Make 中使用 shell 命令来回显字符串
- c++ - C++ 中 std::iota 的效率?
- google-kubernetes-engine - 将我的 GKE 集群连接到本地数据库
- c++ - 递归模板调用中无法调用模板化函数重载
- python - 在将字符串绘制为图像时获取每个字符的边界框信息
- cypher - 无法在 gremlin 中使用密码创建索引
- node.js - GCP:应用服务版本的配置
- cesium - 如何在铯中定义tileset位置
- rust - 为什么 FlatBufferBuilder 有生命周期?