为什么使用 Ionic Framework 插件 healthkit 时会出现 plugin_not_installed 错误? [英] Why am I getting the error plugin_not_installed with the Ionic Framework plugin healthkit?

查看:28
本文介绍了为什么使用 Ionic Framework 插件 healthkit 时会出现 plugin_not_installed 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 Ionic Framework 一段时间,但我最近遇到了这个错误 plugin_not_installed 用于 Health Kit 插件,我知道我基于我的 ionic cordova 插件列表代码>输出.

$ ionic cordova插件列表>科尔多瓦插件lscom.telerik.plugins.healthkit 0.5.5 "HealthKit"科尔多瓦插件应用程序 1.3.0 "AppRate"科尔多瓦插件徽章 0.8.5 徽章"科尔多瓦插件设备 1.1.4 设备"cordova-plugin-dialogs 1.3.4 通知"cordova-plugin-globalization 1.0.8 全球化"cordova-plugin-google-analytics 1.8.3谷歌通用分析插件"cordova-plugin-inappbrowser 1.7.2InAppBrowser"cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview"cordova-plugin-local-notification 0.9.0-beta.1LocalNotification"cordova-plugin-splashscreen 4.0.3Splashscreen"科尔多瓦插件状态栏 2.3.0 状态栏"科尔多瓦插件白名单 1.3.1 白名单"离子插件键盘 2.2.1 键盘"

我的代码包含在 platform.ready() 中,所以我知道一切都已加载.我还有我的健康套件代码,它在 healthKit.available() 和一个 healthKit.requestAuthorization 中抛出错误,它们没有错误.

getWeight.then(function () {alert("Healthkit 准备好了!");警报(重量);healthKitReady = 真;}).catch(函数(错误){如果(错误){控制台日志(错误);//这是错误返回的地方.}});

getWeight 函数是这样的:

const getWeight = new Promise(function(resolve, reject) {变量错误;healthKit.readWeight({单位:磅"}).then(函数(输出){重量 = Math.round(out.value);警报(重量:"+重量);解决(重量);}, 函数(错误){错误 = 错误;拒绝(错误);});});

以防万一这是一个版本问题,这是离子信息的输出:

cli 包:(/usr/local/share/.config/yarn/global/node_modules)@ionic/cli-utils:1.19.0离子(离子 CLI):3.19.0全局包:科尔多瓦(科尔多瓦 CLI):7.1.0本地包:@ionic/app-scripts:3.1.4Cordova 平台:ios 4.5.4离子框架:离子角3.9.2系统:ios部署:1.9.2ios-sim:6.1.2节点:v8.9.1npm : 2.15.12操作系统:macOS High SierraXcode:Xcode 9.2 构建版本 9C40b环境变量:ANDROID_HOME : 未设置杂项:后端:亲

解决方案

如果你来到这里却没有任何效果,别担心,这不是你的错.

您可能已经按照官方文档执行了这两个命令来安装插件:

$ ionic cordova plugin add <你的插件>$ npm install --save @ionic-native/<你的插件>

您还在 app-module.ts 文件中添加了插件:

@NgModule({...提供者:[...你的插件...]...})

您已经在调用已正确导入并注入到调用类的构造函数中的插件.

您甚至正在等待 deviceReady 事件开始使用您的插件:

this.platform.ready().then(() => {//现在使用插件});

然后您仍然收到 plugin_not_installed 错误.可能发生的一件事是,尽管节点和配置文件有这个多 MB 的集群,但该插件是最近在创建项目时添加的.当您添加插件时,它已经下载了存储库中可用的最新版本 (!!!) 并且对于您项目中安装的某些平台(android 或 ios),该插件需要一个比您现在拥有的 Cordova 版本更高的 Cordova 版本.再次输入第一个命令:

$ ionic cordova plugin add <你的插件>

并仔细查看输出.看起来一切正常,但是如果您向上滚动,您可能会发现一条错误消息,指出您下载的这个插件需要 Cordova android(或 ios)版本 X,而您拥有 Cordova android(或 ios)版本 Y,其中 Y <十、示例:

通过 npm 获取插件phonegap-plugin-push@~2.1.0"在2.1.0"处为 android 安装phonegap-plugin-push"插件不支持该项目的cordova 版本.科尔多瓦:7.0.2,失败的版本要求:>=7.1.0跳过 android 的phonegap-plugin-push"

更糟糕的是,该插件已被部分添加,它可能存在于根插件文件夹和 config.xml 中,并在 cordova 插件列表 中列出> 命令输出,但它不存在于 platform_wwwplugins 文件夹中.

如果是这种情况,您需要更新违规平台.并且 cordova 平台更新 已被弃用,因此您现在需要执行以下操作:

ionic cordova 平台移除android离子cordova平台添加android@X

其中 X 是插件需要的版本或更高版本,例如7.1.0".

现在您需要再次正确安装插件:

$ ionic cordova plugin add <你的插件>$ npm install --save @ionic-native/<你的插件>

我们还没有完成.在 Android 中,您现在可能会在设备上运行时遇到此错误:

FAILURE:构建失败,出现异常.* 什么地方出了错:任务:app:processDebugManifest"执行失败.>清单合并失败:uses-sdk:minSdkVersion 16 不能小于库 [:CordovaLib] 中声明的版本 19

更新平台后,部分新代码需要更高的新minSDK.对于 ionic,您需要在 config.xml 中更改此项:

希望你现在一切都好.Cordova 在依赖管理方面真的很烂.此外,文档的编写方式好像每个人都拥有最新的一切.

I have been using Ionic Framework for a while but I have recently come across this error plugin_not_installed for the Health Kit plugin which I know I have based on my ionic cordova plugin list output.

$ ionic cordova plugin list
> cordova plugin ls
com.telerik.plugins.healthkit 0.5.5 "HealthKit"
cordova-plugin-apprate 1.3.0 "AppRate"
cordova-plugin-badge 0.8.5 "Badge"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-dialogs 1.3.4 "Notification"
cordova-plugin-globalization 1.0.8 "Globalization"
cordova-plugin-google-analytics 1.8.3 "Google Universal Analytics Plugin"
cordova-plugin-inappbrowser 1.7.2 "InAppBrowser"
cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview"
cordova-plugin-local-notification 0.9.0-beta.1 "LocalNotification"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.3.0 "StatusBar"
cordova-plugin-whitelist 1.3.1 "Whitelist"
ionic-plugin-keyboard 2.2.1 "Keyboard"

My code is wrapped in platform.ready() so I know that everything is loaded. I also have my health kit code that is throwing the error in a healthKit.available() and a healthKit.requestAuthorization which have no error.

getWeight.then(function () {
    alert("Healthkit is ready!");
    alert(weight);
    healthKitReady = true;
 }).catch(function(err) {
     if (err) {
         console.log(err); // This is where the error is returned.
     }
  });

The function getWeight is this:

const getWeight = new Promise(function(resolve, reject) {
    var error;
    healthKit.readWeight({
        unit: "lb"
    }).then(function (out) {
        weight = Math.round(out.value);
        alert("weight: " + weight);
        resolve(weight);
    }, function (err) {
        error = err;
        reject(error);
    });
});

Just in case this is a version issue this is the output for ionic info:

cli packages: (/usr/local/share/.config/yarn/global/node_modules)

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 7.1.0 

local packages:

    @ionic/app-scripts : 3.1.4
    Cordova Platforms  : ios 4.5.4
    Ionic Framework    : ionic-angular 3.9.2

System:

    ios-deploy : 1.9.2 
    ios-sim    : 6.1.2 
    Node       : v8.9.1
    npm        : 2.15.12 
    OS         : macOS High Sierra
    Xcode      : Xcode 9.2 Build version 9C40b 

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

解决方案

If you came here and nothing worked, don't worry, it's not your fault.

You probably have executed these two commands to install the plugin as per the official documentation:

$ ionic cordova plugin add <your plugin>
$ npm install --save @ionic-native/<your plugin>

You have also added the plugin in the app-module.ts file:

@NgModule({
    ...

    providers: [
        ...
        Your plugin
        ...
    ]
...
})

You are already making calls to your plugin which has been correctly imported and injected into your calling class's constructor.

You are even waiting for the deviceReady event to start using your plugin:

this.platform.ready().then(() => {
    //Use plugin now
});

And then you are still getting the plugin_not_installed error. One thing that could be happening is that, despite this multi-MB clusterfuck of node and configuration files, the plugin was added recently while the project was created some time ago. When you added the plugin it has downloaded the most recent version available in the repository (!!!) and for some of the platforms installed in your project (android or ios) this plugin needs a Cordova version greater than the one you have now. Type again the first command:

$ ionic cordova plugin add <your plugin>

And look carefully at the output. It looks like it went OK but if you scroll up you might find an error saying that this plugin you have downloaded requires Cordova android (or ios) version X and you have Cordova android (or ios) version Y with Y < X. Example:

Fetching plugin "phonegap-plugin-push@~2.1.0" via npm
Installing "phonegap-plugin-push" at "2.1.0" for android
Plugin doesn't support this project's cordova version. cordova: 7.0.2, failed version requirement: >=7.1.0
Skipping 'phonegap-plugin-push' for android

What is worse, the plugin has been partially added and it might be present in the root plugin folder and the config.xml, and is listed in the cordova plugin list command output, but it is not present in the platform_wwwplugins folder.

If this is the case you need to update the offending platform. And cordova platform update has been deprecated, so you now need to do this:

ionic cordova platform remove android
ionic cordova platform add android@X

Where X is the version the plugin needs or greater, for instance "7.1.0".

Now you need to properly install the plugin again:

$ ionic cordova plugin add <your plugin>
$ npm install --save @ionic-native/<your plugin>

We are not done yet. In Android you might now get this error when running on device:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:CordovaLib]

After updating the platform, some of the new code requires a higher new minSDK. For ionic, you need to change this in the config.xml:

<preference name="android-minSdkVersion" value="19" />

And hopefully you will be OK now. Cordova really sucks in dependency management. Also the documentation is written as if everybody had the latest everything.

这篇关于为什么使用 Ionic Framework 插件 healthkit 时会出现 plugin_not_installed 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆