Combine files when adding Cordova plugins

I am developing Android plugins for a Cordova project and I am facing a problem: merging files. In particular, resource files. Most plugins have the same resource files as strings.xml and I want to combine them. I searched Google for a few days and couldn't find an answer.

What should I write in the plugin.xml of my plugin? The original file tag just adds the file. The Config-file tag allows me to add some lines to the file, but this is inconvenient if I have a lot of lines. Is there a command to combine files?

+3


source to share


3 answers


I ran into the same problem as you and didn't find a way to pool resources using a plugin (maybe this has changed in the last couple of years).

What I did was that I created a plugin containing all the common files with this basic content:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
</resources>

      

Then, in every plugin where I need to install resources, I use the plugin syntax in the plugin.xml file:



<config-file target="res/values/ids.xml" parent="/resources">
    <item type="id" name="id1"/>
    <item type="id" name="id2"/>
    <item type="id" name="id3"/>
</config-file>
<config-file target="res/values/strings.xml" parent="/resources">
    <string name="message1">Hello</string>
    <string name="message2">world!</string>
</config-file>

      

Finally, in your plugin, you can set the trustworthiness in the core resources plugin.

The limit of this system is that you want to publish your plugins, and people use it at the same time as other plugins overwriting the same resource files as you ...

I posted a SO question at one time and had no luck getting the aswer. I think we could ask this directly to the plugin people on their jir.

+2


source


A little late



You can just create your_plugin_strings.xml

and use target-dir

to add this to your values ​​folder. The values ​​can then be used as if they were in strings.xml

" @string/your_plugin_hello_message

"

+1


source


I just ran into this problem. Another possibility, although definitely a job for plugins you manage (with source code, not with PhoneGap Builder), is to add your resource values ​​to unused value folder version modifiers. See Android Resources Docs

Android supports modifiers based on Android versions, and any resource folder can use these modifiers. For example, "spoof" and putting your strings in res/values-v1

allows you to create a separate folder for your strings.xml without overwriting different plugin values. Any Android device using android v1 or higher (Honeycomb was v13, Kitkat was v19, Lollipop 5.0 was 21, 5.1 was 22, etc.)

You would need to do this with a different version number for each plugin, but there are many versions before pushing Gingerbread (v9), so if you are not a super plugin, this solution might fix the problem in the short term.

If Android uses modifiers the way I think your plugin values ​​will get auto-preference as the value is "more specific" than the default, and the closest matching vN folder.

If I'm wrong, your system won't get preference, so you'll have to debug / detect naming conflicts and adjust yours accordingly.

0


source







All Articles