如何添加插件到PhoneGap? [英] How to add plugin to PhoneGap?
问题描述
我通过PhoneGap文档感到困惑:
我已根据(1)添加了相机模块。但在(2)中,有信息说我应该添加
< plugin name =Capturevalue = .apache.cordova.Capture/>
至 app / res / xml / plugins.xml
并编辑 app / AndroidManifest.xml
文件。
参考3),还有一些信息,< plugin ... />
已过时和开发人员应改用< gap:plugin ... />
。
帮助理解。
引用最新的 API 文档:
有两种方法可以实现,首先是使用Plugman,另一个是使用CLI。
Plugman方法:
-
首先,必须安装Plugman。 Plugman是PhoneGap 3.4使用的插件管理器。要安装Plugman,请使用Node JS CLI并输入:
npm install -g plugman
-
使用
plugman install
命令安装特定的插件。例如plugman install --platform android --project platforms / android --plugin org.apache.cordova.device-motion
。确保- project
选项的参数直接指向平台文件夹,例如。对于Android,这是AndroidManifest.xml
文件的位置。此命令会自动将对插件的所有引用添加到相关的xml
文件中。 -
HTML
文件引用phonegap.js
由< script type =text / javascript charset =utf-8src =phonegap.js>< / script>
。
使用CLI:
-
前往您的应用程式目录, plugin命令。例如:
phonegap插件添加org.apache.cordova.device-motion
-
插件安装完成后,会自动更新所有
config.xml 添加相应的
< feature>
标签。请注意,这些更新只影响平台特定的config.xml
文件。因此,顶层的config.xml
文件不受影响。您必须手动将< feature>
标签复制并粘贴到顶层config.xml
。否则,当您使用phonegap运行平台
运行应用程序时,插件将被禁用。
请注意,相应的< feature>
标签只能添加到相应的 config.xml
文件,如果您的项目已准备好在该特定平台中部署。
I'm confused a bit by PhoneGap documentation:
I've added camera module according (1). But in (2), there is information saying that I should add
<plugin name="Capture" value="org.apache.cordova.Capture"/>
to app/res/xml/plugins.xml
and edit app/AndroidManifest.xml
files too.
In reference to 3), also there is information that <plugin ... />
construction is obsolete and developer should use <gap:plugin ... />
, instead.
Someone, please help to understand.
Referencing the latest API documentation:
There are two ways to approach this, first is by using Plugman, and the other is by using CLI. The CLI approach is much simpler.
The Plugman approach:
First, Plugman must be installed. Plugman is the plugin manager used by PhoneGap 3.4. To install Plugman, use the Node JS CLI and enter:
npm install -g plugman
Install the specific plugin using the
plugman install
command. For exampleplugman install --platform android --project platforms/android --plugin org.apache.cordova.device-motion
. Be sure that the parameter for the--project
option points directly to the platform folder, e.g. for Android, that's where theAndroidManifest.xml
file is. This command automatically adds all references to the plugins to the pertinentxml
files.Be sure that your
HTML
file referencesphonegap.js
by the line<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
.
Using CLI:
Go to your app directory and enter the plugin command in the CLI. For example:
phonegap plugin add org.apache.cordova.device-motion
installs the accelerometer plugin.
After the plugin has installed, it automatically updates all
config.xml
by adding the corresponding<feature>
tags. Note that these updates only affect the platform-specificconfig.xml
files. And so, the top-levelconfig.xml
file is not affected. You must manually copy and paste the<feature>
tags to the top levelconfig.xml
. Otherwise, the plugins will be disabled when you run the app usingphonegap run platform
.
Take note that the corresponding <feature>
tags can only be added to the corresponding config.xml
files if your project is already ready to deploy in that specific platform.
这篇关于如何添加插件到PhoneGap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!