Replacement for xmltask in Gradle

884 views Asked by At

I am trying to migrate my projects from Eclipse + Ant to Android Studio + Gradle. All of them have special builds for different app stores with different tracking ids, ad ids and so on. On Eclipse I had a ant xmltask that set the values of this ids in their respective xml files. For example I had:

<xmltask source="res/values/admob.xml" dest="res/values/admob.xml">
<replace path="//string[@name='bottom_ad_unit_id']/text()" withText="${bottomAdUnitId}"/>
</xmltask>

For each store I only had to set bottomAdUnitId with the correct id and call run the task.

Is there something similar in Gradle that would allow me to do the same thing?

1

There are 1 answers

1
Mark Vieira On BEST ANSWER

You could just use Gradle's Ant support.

ant.taskdef(name: 'xmltask', classpath: 'path/to/xmltask.jar', classname: 'com.oopsconsultancy.xmltask.ant.XmlTask') 

ant.xmltask(source: 'res/values/admob.xml', dest: 'res/values/admob.xml') {
    replace(path: '//string[@name='bottom_ad_unit_id']/text()', withText: "${bottomAdUnitId}")
}