How does gradle execute an ant build file

Ive been driving myself crazy trying to rebuild my custom_rules.xml into something in gradle and its proving to be quite difficult. So my next step is Im trying to just import the last few things I cant do in gradle as an build.xml.

However this doesnt seem to do anything. When I try using

ant.importBuild ‘build.xml’ I get no feed back or no echos from my script. Ive read through gradles documentation a lot especially on ant and for the life of me I cant figure out what Im supposed to do once the build gets imported. How does the script get executed?

This is my build.xml

<?xml version="1.0" encoding="UTF-8"?>
    <project>
    <target name="postPackage" >
    <property name="config_path" location="${cert.dir}" />
    <property name="out.pre.widevine.signed.file" location="release-pre-widevine-sign.apk" />
    <property name="out.widevine.signed.file" location="release-widevine-signed.apk" />
    <echo>sign with widevine certificate</echo>
    <touch file="res/raw/wv.properties"/>
    <copy file="${out.packaged.file}" tofile="${out.pre.widevine.signed.file}"/>
    <java jar="apksigtool.jar" failonerror="true" fork="true">
        <arg value="${out.packaged.file}"/>
        <arg value="private_key.der" />
        <arg value="rovi.crt" />
    </java>
    <copy file="${out.packaged.file}" tofile="${out.widevine.signed.file}"/>
    </target>
    </project>

I figured it out. All I had to do was type out the target name and use execute()

so in my task I just used

ant.importBuild ‘build.xml’

postPackage.doFirst{println(“IM done”)}

postPackage.execute()

That ran the ant task. There needs to be a lot more examples in the documentation. PLEASE!!! :slight_smile:

Using the ‘execute()’ method is not recommended since it is an internal API. You can run the task like so.

$ gradle postPackage

This is explained in the Gradle documentation. Calling ‘ant.importBuild’ simply creates a Gradle task for every ant target.

Thank you for the reply :slight_smile: Im working in android studio and its my goal to have the ide do everything. The less I have to do from the command line the more time I can save. Is there another way to execute my build file in a more “gradle” way.

You could make that task (target) a dependency of another task. In this case I assume you want to run this task after the apk is built? You could add something like this to your ‘build.gradle’.

postPackage.dependsOn assemble

build.dependsOn postPackage

There is probably a better part of the Android build lifecycle to place this task. I’d suggest looking at the Android Gradle Plugin documentation for more information on how to modify build tasks.