什么是科尔多瓦插件手动添加到科尔多瓦项目的正确方法 [英] what is the correct way to manually add Cordova plugin to Cordova project

查看:219
本文介绍了什么是科尔多瓦插件手动添加到科尔多瓦项目的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用Android Studio的科尔多瓦项目。我想科尔多瓦设备插件到我的项目。据我了解科尔多瓦的插件包括 device.js Device.java ,这是我的文件夹中找到插入。我复制 Device.java CordovaLib / src目录/组织/阿帕奇/科尔多瓦/设备/ 文件夹和 device.js 资产/ WWW /插件/ org.apache.cordova.device / WWW 文件夹中。我也纳入 index.html的 cordova_plugins.js 文件,该文件是自动创建科尔多瓦。它具有以下内容:

I'm developing Cordova project using Android Studio. I want to Cordova device plugin to my project. As I understand Cordova plugin consists of device.js and Device.java, which I've found in the folder of plugin. I copied Device.java into CordovaLib/src/org/apache/cordova/device/ folder and device.js into assets/www/plugins/org.apache.cordova.device/www folder. I also included into index.html cordova_plugins.js file, which was automatically created by Cordova. It has the following content:

cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
    {
        "file": "plugins/org.apache.cordova.device/www/device.js",
        "id": "org.apache.cordova.device.device",
        "clobbers": [
            "device"
        ]
    }
];
module.exports.metadata = 
// TOP OF METADATA
{
    "org.apache.cordova.device": "0.2.12"
}
// BOTTOM OF METADATA
});

现在,当我成功打造我的应用程序并运行它,我得到错误初始化科尔多瓦:类没有找到错误。我在做什么错了?

Now when I successfully build my app and run it I get Error initializing Cordova: Class not found error. What am I doing wrong?

推荐答案

如果您直接在平台/ android文件夹,使您的更改,请不要使用CLI添加插件,你可能会失去你的code(当你使用CLI添加一个插件,它是唯一真正在平台上添加当您运行科尔多瓦prepare机器人这将覆盖在平台上的code /安卓在根www文件夹的code /资产/ WWW你想要的东西可能不是)。

If you make your changes directly in the platform/android folder, do not use the CLI to add plugins, you may loose your code (when you use the cli to add a plugin, it is only really added in the platform when you run cordova prepare android which will overwrite the code in platforms/android/assets/www with the code in the root www folder which may not be what you want).

添加插件直接进入一个平台的推荐方法是<一个href=\"http://cordova.apache.org/docs/en/4.0.0/plugin_ref_plugman.md.html#Using%20Plugman%20to%20Manage%20Plugins\"相对=nofollow>使用plugman工具。

The recommended way to add plugins directly into a platform is to use the plugman tool.

如果你真的想手工做的一切,那么你需要看文件的plugin.xml。在这个文件中,你会发现文件修改的config.xml一样,AndroidManifest.xml中或cordova_plugins.js。

If you really want to do everything manually, then the file you need to watch is plugin.xml. In this file you will find files to modify like config.xml, AndroidManifest.xml or cordova_plugins.js.

您应该使用要求不会加载(从插件以及javascrips)从INDEX.XML cordova_plugins.js,它会自动从cordova.js加载。

You should not load cordova_plugins.js from index.xml, it is automatically loaded from cordova.js (as well as javascrips from plugins) using require.

这篇关于什么是科尔多瓦插件手动添加到科尔多瓦项目的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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