1

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="my.crt" />
</java>
<copy file="${out.packaged.file}" tofile="${out.widevine.signed.file}"/>
</target>
</project>
jcateca
  • 65
  • 5
James andresakis
  • 5,335
  • 9
  • 53
  • 88

3 Answers3

1

I was able to accomplish this by using the following snippet in a method

    ant.importBuild 'build.xml'
    postPackage.doFirst{println("Im starting")}
    postPackage.execute()
James andresakis
  • 5,335
  • 9
  • 53
  • 88
0

ant.importBuild will create an equally named Gradle task for each Ant target found in the Ant build. You can then invoke those tasks from the command line and/or make other tasks depend on them. For more information, see "16.2. Importing an Ant build" in the Gradle User Guide,

abd3721
  • 1,374
  • 1
  • 11
  • 10
Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • Thank you for the reply :) Im working in android studio and the less time I spend on the command line means more time doing other things. So if I understand correctly, when I import my build file all the targets become tasks? Im still learing the build.gradle lifecycle so could you please explain when and where I should implement the target/task dependencies. Ive read through a lot of the documentation and its left me with a lot more questions than when I started. – James andresakis Sep 25 '14 at 17:00
  • That's a new question, and the current question doesn't contain enough information to answer that. Either edit the question or create a new one. – Peter Niederwieser Sep 25 '14 at 17:05
  • 1
    RFM responses are limited in their usefulness. – William T. Mallard Jan 29 '16 at 20:11
0

Hmm I think this Kotlin is working for me;

  val t : Task = tasks.named("war").get()
  t.actions.forEach { a -> a.execute(t) }
Dima Kozhevin
  • 3,602
  • 9
  • 39
  • 52
Adligo
  • 51
  • 2
  • Note this was my earlier answer and doesn't seem to work gradle.run { tasks.getByName("war") } – Adligo Aug 10 '20 at 19:10