简体   繁体   中英

How to use Ant to auto renaming output apk file?

I'm currently playing with Ant to do some auto branding work. I modified default build.xml and setup my own target. What I hope to ask is that is there a way in Ant Script that could automatic renaming the apk file just build with the certain name?

I currently has this Ant target setup in my build.xml:

<target name="release-brandA"
            depends="default, -set-release-mode, -release-obfuscation-check, -package, -post-package, -release-prompt-for-password, -release-nosign, -release-sign, -post-build"
            description="Builds the application in release mode for brandA.">
    <delete dir="${res}" />
    <copydir dest="${res}" src="${branding}/brandA" forceoverwrite="ture" />
    <replaceregexp flags="g" byline="false">
        <regexp pattern="import com.arthur.android(.*).R;"/>
        <substitution expression="import com.arthur.android.brandA.R;"/>
        <fileset dir="src" includes="**/*.java" />
    </replaceregexp>
    <replaceregexp flags="g" byline="false">
        <regexp pattern="package=&quot;com.arthur.android(.*)&quot;" />
        <substitution expression="package=&quot;com.arthur.android.brandA&quot;" />
        <fileset dir="" includes="AndroidManifest.xml" />
    </replaceregexp>
</target>

Is there a way that I could add some more task, to let the output file just be like brandA.apk?

Thank you!

The final apk filename is actually defined by the property 'out.final.file'

So you could create a new Task that sets this property:

<target name="-set-out-final-file">
    <property name="out.final.file" location="${out.absolute.dir}/brandA.apk" />
</target>

Finally, you just need to invoke the -set-out-final-file target before calling the debug or release targets.

Using your release-brandA task, it would become this:

<target name="release-brandA"
        depends="default, -set-out-final-file, -set-release-mode, -release-obfuscation-check...

Here I found more better explanation and more suitable way to override release target.

Please refer to section:

<target
        name="release"
        depends="custom-set-release-mode, android_rules.release" />

Its very simple.Refer this link [1]: https://ant.apache.org/manual/running.html

So in the above case,we need to run it like this,

ant debug -Dout.final.file=brandA.apk

Thats it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM