Skip to content

Instantly share code, notes, and snippets.

@mobiRic
Created February 22, 2015 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mobiRic/5303bc1c74256cc42c3a to your computer and use it in GitHub Desktop.
Save mobiRic/5303bc1c74256cc42c3a to your computer and use it in GitHub Desktop.
Custom rules build file for Android to copy APK to different output folder
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (C) 2015 Glowworm Software
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="custom_rules" >
<property name="grep" location="${basedir}/extras/tools/grep.exe" />
<property name="sed" location="${basedir}/extras/tools/sed.exe" />
<property name="glowworm.build.dir" location="${basedir}/build" />
<property name="temp.out.aapt" location="${glowworm.build.dir}/aapt.out" />
<property name="temp.out.grep" location="${glowworm.build.dir}/grep.out" />
<target name="-post-build" description="Copies the output file into custom build folder.">
<!-- EXTRACT APPLICATION NAME AS SET IN ANDROID MANIFEST FROM BUILT APK FILE -->
<exec executable="${aapt}" taskName="aapt" outputproperty="null">
<arg value="dump" />
<arg value="badging" />
<arg path="${out.final.file}" />
<redirector output="${temp.out.aapt}" alwayslog="false"/>
</exec>
<exec executable="${grep}" taskName="grep" outputproperty="null">
<arg value="application-label" />
<arg value="${temp.out.aapt}" />
<redirector output="${temp.out.grep}" alwayslog="false"/>
</exec>
<exec executable="${sed}" taskName="sed" outputproperty="glowworm.build.appname">
<arg value="-r" />
<arg value="&quot;s/(application-label:)*([ '])*//g&quot;" />
<arg value="${temp.out.grep}" />
</exec>
<!-- COPY COMPILED APK INTO OUTPUT FOLDER -->
<echo>Copying ${out.final.file} to ${glowworm.build.dir}\${glowworm.build.appname}.apk</echo>
<copy file="${out.final.file}" tofile="${glowworm.build.dir}/${glowworm.build.appname}.apk" overwrite="true"/>
<!-- CLEAN UP TEMPORARY FILES -->
<delete file="${temp.out.aapt}"/>
<delete file="${temp.out.grep}"/>
</target>
</project>
@mobiRic
Copy link
Author

mobiRic commented Feb 22, 2015

Custom rules file for Android ANT build script.

Copies the output APK file to the .\build folder, and renames it according to the name set in the Android manifest file.

Requires grep.exe and sed.exe to exist in .\extras\tools folder - self-contained executables can be found at:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment