后台地理定位插件不适用于 Android 版本
Posted
技术标签:
【中文标题】后台地理定位插件不适用于 Android 版本【英文标题】:Background Geolocation plugin not working on Android builds 【发布时间】:2018-06-30 23:23:36 【问题描述】:我有一个安装了 BackgroundGeolocation 插件的 Ionic 应用程序。当我使用ionic cordova run android
运行该应用程序时,它运行良好,但是当我在手机上手动构建并安装它时,我在启动应用程序时收到此错误:
Native: tried calling BackgroundGeolocation.configure, but the BackgroundGeolocation plugin is not installed
这是我的packaje.json
文件:
"name": "cm-mobile",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts":
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
,
"dependencies":
"@angular/common": "5.0.3",
"@angular/compiler": "5.0.3",
"@angular/compiler-cli": "5.0.3",
"@angular/core": "5.0.3",
"@angular/forms": "5.0.3",
"@angular/http": "5.0.3",
"@angular/platform-browser": "5.0.3",
"@angular/platform-browser-dynamic": "5.0.3",
"@ionic-native/background-geolocation": "^4.5.2",
"@ionic-native/background-mode": "^4.5.2",
"@ionic-native/barcode-scanner": "^4.5.2",
"@ionic-native/battery-status": "^4.5.2",
"@ionic-native/camera": "^4.5.2",
"@ionic-native/core": "^4.5.2",
"@ionic-native/file": "^4.5.2",
"@ionic-native/file-transfer": "^4.5.2",
"@ionic-native/geolocation": "^4.5.2",
"@ionic-native/launch-navigator": "^4.5.2",
"@ionic-native/push": "^4.5.2",
"@ionic-native/splash-screen": "4.4.0",
"@ionic-native/status-bar": "^4.4.0",
"@ionic/storage": "2.1.3",
"@types/leaflet": "^1.2.5",
"cordova-android": "6.3.0",
"cordova-plugin-actionsheet": "^2.3.3",
"cordova-plugin-background-mode": "^0.7.2",
"cordova-plugin-battery-status": "^2.0.1",
"cordova-plugin-camera": "^4.0.1",
"cordova-plugin-device": "^1.1.4",
"cordova-plugin-dialogs": "^2.0.1",
"cordova-plugin-file": "^5.0.0",
"cordova-plugin-file-transfer": "^1.7.0",
"cordova-plugin-geolocation": "^4.0.1",
"cordova-plugin-ionic-webview": "^1.1.16",
"cordova-plugin-mauron85-background-geolocation": "^2.3.3",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-statusbar": "^2.4.1",
"cordova-plugin-whitelist": "^1.3.1",
"ionic-angular": "3.9.2",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"leaflet": "^1.2.0",
"phonegap-plugin-barcodescanner": "^7.0.1",
"phonegap-plugin-push": "^2.1.2",
"rxjs": "5.5.2",
"sw-toolbox": "3.6.0",
"uk.co.workingedge.phonegap.plugin.launchnavigator": "^4.1.3",
"zone.js": "0.8.18"
,
"devDependencies":
"@ionic/app-scripts": "3.1.6",
"typescript": "2.4.2"
,
"description": "An Ionic project",
"cordova":
"plugins":
"ionic-plugin-keyboard": ,
"cordova-plugin-whitelist": ,
"cordova-plugin-device": ,
"cordova-plugin-splashscreen": ,
"cordova-plugin-ionic-webview": ,
"cordova-plugin-mauron85-background-geolocation":
"GOOGLE_PLAY_SERVICES_VERSION": "11.0.1",
"ICON": "@mipmap/icon",
"SMALL_ICON": "@mipmap/icon",
"ACCOUNT_NAME": "@string/app_name",
"ACCOUNT_LABEL": "@string/app_name",
"ACCOUNT_TYPE": "$PACKAGE_NAME.account",
"CONTENT_AUTHORITY": "$PACKAGE_NAME"
,
"phonegap-plugin-push":
"FCM_VERSION": "11.0.1"
,
"cordova-plugin-file-transfer": ,
"cordova-plugin-file": ,
"cordova-plugin-geolocation": ,
"cordova-plugin-camera": ,
"cordova-plugin-background-mode": ,
"phonegap-plugin-barcodescanner": ,
"cordova-plugin-battery-status": ,
"uk.co.workingedge.phonegap.plugin.launchnavigator": ,
"cordova-plugin-statusbar": ,
"cordova-plugin-datecs-printer":
,
"platforms": [
"android"
]
是我做错了什么,还是来自ionic-native
或插件的错误?
【问题讨论】:
【参考方案1】:这发生在我身上,因为我没有从正确的位置调用函数(我从服务而不是 app.component.ts 调用它)。
guide 声明:
BackgroundGeolocation 必须在 app.ts 中调用 并且...
【讨论】:
仅作记录:应用此解决方案后,我仍然在控制台中收到消息,但这只是一个警告,插件工作正常。【参考方案2】:问题似乎在最新版本中得到解决,如下所述: https://github.com/ionic-team/ionic-native/issues/258
当 ionic-native 无法找到包装器定义中提供的 pluginRef 时,会发生插件未安装错误。 pluginRef 设置为 plugins.backgroundGeoLocation 而不是 backgroundGeolocation
【讨论】:
以上是关于后台地理定位插件不适用于 Android 版本的主要内容,如果未能解决你的问题,请参考以下文章
Cordova 插件 Geolocation 不适用于 Android 版本 Kitkat
Phonegap 2.5.0 地理定位不适用于 android 4.0.4