Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 439
Arthur0902 Avatar asked Feb 06 '13 16:02

Arthur0902


2 Answers

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...
like image 111
azgolfer Avatar answered Sep 27 '22 19:09

azgolfer


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" />
like image 31
N0dGrand87 Avatar answered Sep 27 '22 17:09

N0dGrand87