How to use Ant to automatically rename output apk file?

I am currently playing with Ant to do some auto-branding work. I changed the default build.xml and set my own goal. What I hope to ask, is there a way in Ant Script that can automatically rename an apk file with only a specific name?

I currently have this target Ant installation in my build.xml file:

<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 other task so that the output file just looks like brandA.apk?

Thank!

+5
source share
3 answers

The final apk file name is actually determined by the 'out.final.file' property

, , :

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

, -set-out-final-file .

release-brandA, :

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

.

:

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

It is very simple. Refer to 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

Here it is.

0
source

All Articles