Reputation: 105459
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?
Upvotes: 1
Views: 3657
Reputation: 11721
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).
The recommended way to add plugins directly into a platform is to use the plugman tool.
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.
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.
Upvotes: 1
Reputation: 2768
You should use cordova cli (command line interface) methods in order to add plugins, assuming you are using cordova/phonegap version > 3. As far as I remember, core plugins (maintained by cordova team) are also needed to be added/removed since version 3.2 or 3.4.
Anyhow, you should call: cordova plugin add org.apache.cordova.device
from command prompt (where your top level www folder is).
See cordova documentation here for more details (scroll to bottom).
Please note that, I've never used Android Studio, only Eclipse, but these should be IDE agnostic.
Upvotes: 0