3

I have added a plugin with Java code (for Android) to my Cordova project. The same java file can now be found under plugins folder and also under the platforms/android folder. Unfortunately when I edit the code in the plugins folder and build the application then the code under the platforms folder is not changed and the emulated app never get updated. Do I have to do something else?

Update

Ok, it seems there is no "automatic" way to update the code in the platforms folder. One has to re-add it. See Cordova 3.5, how to update local plugin? or In Phonegap/Cordova 3.0+, is there any way to refresh plugins after you make changes?

Or does someone know a better way?

Community
  • 1
  • 1
medihack
  • 16,045
  • 21
  • 90
  • 134

3 Answers3

1

This is old but I was searching and this one is without answer. If you have plugin that you've created, you can add directory instead of url. So if you have template on github that need to be modified you need clone it, make changes, and add using:

cordova plugin add /path/to/plugin --nofetch 

see docs for cordova cli

I think that you will need to execute this command each time you make changes and before you do you need to remove the plugin:

cordova plugin remove com.example.plugin.name

You can speed things up if you create simple node script that will execute this when file changes:

var watch = require('watch');
var exec = require('child_process').exec;
if (process.argv.length == 4) {
    var name = process.argv[2]
    var path = process.argv[3];
    watch.watchTree(path, function() {
        var cmd = 'cordova plugin remove ' + name +
            ' && cordova plugin add ' + path + ' --nofetch';
        console.log(cmd);
        exec(cmd, function (error, stdout, stderr) {
            if (error !== null) {
                console.log('exec error: ' + error);
            } else {
                console.log('done');
            }
        });
    });
} else {
    console.log('usage: ' + process.argv[1] + ' [NAME] [PATH]');
}

then you can save is as plugin.js and run (from your cordova application path):

node plugin.js com.example.plugin.name /path/to/plugin

it will work when you put more then one plugin. Before you run it you need to execute:

npm install -g watch

or:

npm install --save-dev watch

cordova application have package.json file so this dependency will be save there.

jcubic
  • 61,973
  • 54
  • 229
  • 402
1

I just had/resolved the same issue and found the solution and thought it should be here:

Changes of the java file in the plugin directory won't be updated when building, but editing the one in the platforms/android/app/src/main/java/* will.

Dharman
  • 30,962
  • 25
  • 85
  • 135
MarBo
  • 61
  • 3
0

you are add plugin using cmd or manually add plugin for your cordova project.

you can directly add plugin using cmd, select your project in directory and direct hit plugin url Example: cordova plugin add nl.x-services.plugins.socialsharing

and automatically add all plugin file, that plugin permissions.

  • I added the plugin using the command line (`cordova plugin add https://github.com/Red-Folder/bgs-sample.git`). But the plugin is just a template (see https://github.com/Red-Folder/bgs-core/wiki/Using-the-MyService-Sample). After editing the template (the Java file) in the plugins folder the appropriate file in the platforms folder does unfortunately not get updated. – medihack Aug 08 '15 at 15:20