Adding drawable resource using Cordova

Jose Granja picture Jose Granja · Feb 19, 2016 · Viewed 10.6k times · Source

I want to add a drawable resource to my cordova project. I did add the icon and splashscreen items just fine. They get copied to my platform/android/res/drawable just fine. The problem is when I try to add another resource. How do I do that? I can't find anything on cordova rather than icon and splashscreen

<platform name="android">
<icon src="xx.png" density="ldpi"/>
<icon src="xx.png" density="mdpi"/>
<icon src="xx.png" density="hdpi"/>
<icon src="xx.png" density="xhdpi"/>
<icon src="xx.png" density="xxhdpi"/>
<icon src="xx.png" density="xxxhdpi"/>
<splash src="xx.png" density="ldpi"/>
<splash src="xx.png" density="mdpi"/>
<splash src="xx.png" density="hdpi"/>
<splash src="xx.png" density="xhdpi"/>
<splash src="xx.png" density="xxhdpi"/>
<splash src="xx.png" density="xxxhdpi"/>

Can somebody help there? I don't see any option in the config.xml to add other drawable resources.

Answer

jcesarmobile picture jcesarmobile · Feb 22, 2016

EDIT:

Since Cordova CLI 7.x.x, when using cordova-android 6.2.x or cordova-ios 4.4.x you can use the resource-file tag from config.xml as I explained for on my old answer for plugins. You have to put it inside the platform tag.

Example:

<platform name="android">
  <resource-file src="www/res/drawable-hdpi/yourImage.png" target="res/drawable-hdpi/yourImage.png" />
</platform>

src is where you have the image right now, could be in www as in my example or even in the root of the project if you don't want the file duplicated. target is the destination, it will be in yourProject/platforms/platform/target for the example it would be yourProject/platforms/android/res/drawable-hdpi/yourImage.png

OLD answer:

From the config.xml you can only add icons and launch images

If you want to add a resource you can create a plugin and use the resource-file tag

<resource-file src="src/android/res/drawable-hdpi/yourImage.png" target="res/drawable-hdpi/yourImage.png" />

Or you can use a hook that copies the image to wherever you want