一.安装plugman插件
npm install –g plugman
二. 开发插件
- 创建插件
plugman create –name --plugin_id --plugin_version
[–path][–variableNAME=value]
plugmanName : 插件名字
pluginID : 插件ID
version : 0.0.1
directory : 一个绝对或相对路径的目录,该目录将创建插件项目
variableNAME=VALUE: 额外的描述,如作者信息和相关描述
例子 :
plugman create --name LycPlugin --plugin_id lycPlugin --plugin_version 1.0.0
成功创建插件后的文件结构如下图:
2. 在插件内添加android platform,生成.java文件
cd LycPlugin
plugman platform add –platform_name android
成功添加后目录如下图:
若想添加依赖jar包,可直接放在android目录下,或者在src下新建libs目录。
添加jar包之后记得在工程中添加jar包依赖
三. 安装插件
我的插件所在的路径是与项目同路径
首先切换到最初创建的hello目录 cd hello
执行插件安装命令
cordova plugin add LycPlugin
执行完之后你就发现插件已经安装上去了
注意:如果添加不成功!提示插件无效 Invalid Plugin! needs a valid package.json
终端切换至自定义插件文件夹的位置:执行如下命令
- npm init 回车
显示内容:
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
Seenpm help json
for definitive documentation on these fields
and exactly what they do.
Usenpm install --save
afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: ()
2.输入你的自定义插件名称,不能含大写字母。
3.接下来要填写的信息可依次回车。
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /Users/…./pluginName/package.json:
{
“name”: “”,
“version”: “1.0.0”,
“description”: “”,
“main”: “index.js”,
“scripts”: {
“test”: “echo “Error: no test specified” && exit 1”
},
“author”: “”,
“license”: “ISC”
}
Is this ok? (yes)
4.敲入y 即可。
5.重新执行一遍 cordova plugin add LycPlugin
安装成功!!!
如果你想卸载插件的话,执行cordova plugin remove plugin_id
egg:
cordova plugin remove lycPlugin
四. 插件的使用
lyc.toast.showToast();
lyc.toast.showshowToast(“hello”,0, function(msg) {
alert(msg);
}, function(msg) {
alert(msg);
});