'Cordova Plugin alternate to <source-file> tag to copy entire directory contents

Is there any way to specify in plugin.xml to copy every file in plugin source folder to the target platform directory either with one dir copy statement or automatically copy every file in src directory.

Using to be copied as part of big plugin is the nightmare, as we are seeing manual changes needed during the massive refactoring.



Solution 1:[1]

I can't vote yet :( but Rafita is correct. To expand on that answer, I do the same thing because I have a large set of files that comprise an Android Activity that include many java source files, assets, layouts, and resources that all need to be installed into the platforms (and merged with any existing ones generated by the core android plugin).

  • For Android, I copied my whole activity's sources into the android plugin directory and then arrange for copying them all like this:

<source-file src="src/android/java/com/acme" target-dir="src/com" /> will copy your entire package tree into the platforms/android/src/com/acme directory.

And for the resources and assets, you can do this:

<resource-file src="src/android/res" target="res" /> <resource-file src="src/android/assets" target="assets" />

  • For iOS,

<source-file src="src/ios" target-dir="src"/> Will copy all source files from your plugin/src/ios directory to platforms/ios/Project-Name/Plugins/plugin-name directory

Solution 2:[2]

You can do the same thing as you do with any file.

Simply use:

<source-file src="src/android/libs/YourDIR" target-dir="libs"/>

Cordova will recognize that, thereby will copy the entire YourDIR into a destination libs, for example.

Solution 3:[3]

The reason this was happening for me is that I had my plugin files buried inside a nested folder structure (as is generally required with Java):

-- my-plugin/
   +-- src/
       +-- com/
           +-- abc/
               +-- def/
                   +-- MyPlugin.java

but the plugin.xml settings didn't match this. Specifically the setting

<param name="android-package" value="com.abc.def.MyPlugin"/>

has to contain the class name with the fully qualified namespace. Also make sure the <source-file> element has the correct values.

Here is more of the plugin.xml file for reference:

<platform name="android">
    <config-file target="res/xml/config.xml" parent="/*">
        <feature name="MyPlugin">
            <param name="android-package" value="com.abc.def.MyPlugin"/>
        </feature>
    </config-file>
    ...
    <source-file src="src/com/abc/def/MyPlugin.java" target-dir="com/abc/def" />
</platform>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Buddhisthead
Solution 2 Nakket
Solution 3 d512