如何添加插件到PhoneGap? [英] How to add plugin to PhoneGap?

查看:151
本文介绍了如何添加插件到PhoneGap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过PhoneGap文档感到困惑:

  • 链接1 //如何添加插件使用phonegap local plugin add命令

  • 链接2 //有关如何使用相机的教程模块

  • 链接3 // 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方法


    1. 首先,必须安装Plugman。 Plugman是PhoneGap 3.4使用的插件管理器。要安装Plugman,请使用Node JS CLI并输入:



      npm install -g plugman

      / li>
    2. 使用 plugman install 命令安装特定的插件。例如 plugman install --platform android --project platforms / android --plugin org.apache.cordova.device-motion 。确保 - project 选项的参数直接指向平台文件夹,例如。对于Android,这是 AndroidManifest.xml 文件的位置。此命令会自动将对插件的所有引用添加到相关的 xml 文件中。


    3. HTML 文件引用 phonegap.js < script type =text / javascript charset =utf-8src =phonegap.js>< / script>


    使用CLI:


    1. 前往您的应用程式目录, plugin命令。例如:



      phonegap插件添加org.apache.cordova.device-motion

      $ b $


    2. 插件安装完成后,会自动更新所有 config.xml 添加相应的< feature> 标签。请注意,这些更新只影响平台特定的 config.xml 文件。因此,顶层的 config.xml 文件不受影响。您必须手动将< feature> 标签复制并粘贴到顶层 config.xml 。否则,当您使用 phonegap运行平台运行应用程序时,插件将被禁用。


    请注意,相应的< feature> 标签只能添加到相应的 config.xml 文件,如果您的项目已准备好在该特定平台中部署。


    I'm confused a bit by PhoneGap documentation:

  • Link 1 // How add plugins using "phonegap local plugin add" command
  • Link 2 // Tutorial about how to use camera module
  • Link 3 // PhoneGap Plugins

    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:

    1. 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

    2. Install the specific plugin using the plugman install command. For example plugman 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 the AndroidManifest.xml file is. This command automatically adds all references to the plugins to the pertinent xml files.

    3. Be sure that your HTML file references phonegap.js by the line <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>.

    Using CLI:

    1. 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.

    2. 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-specific config.xml files. And so, the top-level config.xml file is not affected. You must manually copy and paste the <feature> tags to the top level config.xml. Otherwise, the plugins will be disabled when you run the app using phonegap 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屋!

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