Cordova Plugin alternate to <source-file> tag to copy entire directory contents
Asked Answered
W

3

12

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.

Washhouse answered 20/1, 2015 at 9:57 Comment(1)
I'm searching too. If we don't find anything, perhaps we should pull the Cordova source and make a new plugin tag handler to copy <source-folder ... and <resource-folder tags the same way as<source-file ... tags todaySikko
O
10

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/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
Obligato answered 18/11, 2015 at 22:22 Comment(0)
P
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.

Pamphylia answered 25/9, 2015 at 6:20 Comment(0)
P
0

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>
Paine answered 15/4, 2022 at 18:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.