Search code examples
cordovacordova-pluginscordova-cli

Remove source along with cordova plugin


I have a custom cordova plugin that includes both a *.aar file and *.kt (kotlin) files. When I remove and re-add my plugin (it's in the local file system, it fails because the remove step didn't actually remove all of it; here's an example error:

Error during processing of action! Attempting to revert...
Failed to install 'com.rsginc.mobilesurvey': CordovaError: Uh oh!
"/Users/me/code/ms-client-echidna/platforms/android/app/src/main/kotlin/com/rsginc/mobilesurvey/BreadCrumbs.kt" already exists!
    at copyNewFile (/Users/me/code/ms-client-echidna/platforms/android/cordova/lib/pluginHandlers.js:261:45)
    ...

I have a workaround - an alias that will remove the plugin, rm the source, and then reinstall it, but that's ugly to share with other developers in my group.

Here's a line from my plugin.xml (that matches the above error):

<source-file src="src/android/BreadCrumbs.kt" target-dir="app/src/main/kotlin/com/rsginc/mobilesurvey" />

Is there something else I can add to my plugin.xml so it will clean up during the 'cordova plugin rm ...'?


Solution

  • Currently (as of cordova-android@7.1.1), Cordova only removes .java files when plugins are uninstalled from the Android platform.

    You can use --force when re-adding the plugin to ignore the error that occurs because the .kt source files already exist in the android platform project.

    Or, if you take a look at my cordova-plugin-hello-kotlin example plugin, you can add the uninstall hook script to your plugin which removes any .kt specified in the plugin.xml from the android platform project.