<?xml version="1.0" encoding="UTF-8">
<project name="First-Aid" default="zipalign" basedir=".">
<property file="build.properties"></property>
<!-- The absolute paths for the tools. -->
<property name="android.framework" value="${sdk.home}/platforms/${sdk.platform}/framework.aidl"></property>
<property name="android.core" value="${sdk.home}/platforms/${sdk.platform}/android.jar"></property>
<property name="jarsigner" value="${jdk.home}/bin/jarsigner.exe"></property>
<property name="zipalign" value="${sdk.home}/tools/zipalign.exe"></property>
<property name="dx" value="${sdk.home}/platform-tools/dx.bat"></property>
<property name="apk-builder" value="${sdk.home}/tools/apkbuilder.bat"></property>
<property name="aapt" value="${sdk.home}/platform-tools/aapt.exe"></property>
<property name="aidl" value="${sdk.home}/platform-tools/aidl.exe"></property>
<!-- The absolute path. -->
<property name="src.abs" value="${basedir}\src"></property>
<property name="lib.abs" value="${basedir}\libs"></property>
<property name="bin.abs" value="${basedir}\bin"></property>
<property name="dex.abs" value="${basedir}\bin\classes.dex"></property>
<property name="resources.abs" value="${basedir}\bin\resources.ap_"></property>
<property name="unsigned.abs" value="${basedir}\bin\${ant.project.name}-unsigned.apk"></property>
<property name="signed.abs" value="${basedir}\bin\${ant.project.name}-signed.apk"></property>
<!-- Cleaning the project -->
<target name="clean">
<echo>Cleaning the project...</echo>
<delete includeemptydirs="true" verbose="true">
<fileset dir="bin" includes="**/*">
</fileset></delete>
<delete includeemptydirs="true" verbose="true">
<fileset dir="gen" includes="**/*">
</fileset></delete>
</target>
<!-- Generate R.jave -->
<target name="generate" depends="clean">
<echo>Generating R.java / Manifest.java from the resources...</echo>
<exec executable="${aapt}" failonerror="true">
<arg value="package">
<arg value="-m">
<arg value="-J">
<arg value="gen">
<arg value="-M">
<arg value="AndroidManifest.xml">
<arg value="-S">
<arg value="res">
<arg value="-I">
<arg value="${android.core}">
</arg></arg></arg></arg></arg></arg></arg></arg></arg></arg></exec>
</target>
<!-- Package the resources. -->
<target name="package">
<echo>Packaging resources and assets...</echo>
<exec executable="${aapt}" failonerror="true">
<arg value="package">
<arg value="-f">
<arg value="-M">
<arg value="AndroidManifest.xml">
<arg value="-S">
<arg value="res">
<arg value="-A">
<arg value="assets">
<arg value="-I">
<arg value="${android.core}">
<arg value="-F">
<arg value="bin/resources.ap_">
</arg></arg></arg></arg></arg></arg></arg></arg></arg></arg></arg></arg></exec>
</target>
<!-- Convert and compile AIDL files. -->
<target name="aidl" depends="clean">
<echo>Compiling aidl files into Java classes...</echo>
<apply executable="${aidl}" failonerror="true">
<arg value="-p${android.framework}">
<arg value="-Isrc">
<arg value="-ogen">
<fileset dir="src">
<include name="**/*.aidl">
</include></fileset>
</arg></arg></arg></apply>
</target>
<!-- Compile -->
<target name="compile" depends="clean,generate,aidl">
<javac encoding="UTF-8" target="1.6" debug="off" extdirs="" srcdir="src:gen" destdir="bin" bootclasspath="${android.core}">
<classpath>
<fileset dir="libs" includes="*.jar">
</fileset></classpath>
</javac>
</target>
<!-- Convert and compress .class files to .dex file. -->
<target name="dex" depends="compile">
<echo>Converting compiled files and external libraries into dex format file...</echo>
<apply executable="${dx}" failonerror="true" parallel="true">
<arg value="--dex">
<arg value="--output=${dex.abs}">
<arg path="${bin.abs}">
<fileset dir="libs" includes="*.jar">
</fileset></arg></arg></arg></apply>
</target>
<!-- Package an unsigned APK file. -->
<target name="release" depends="dex, package">
<echo>Packaging an unsigned APK file...</echo>
<exec executable="${apk-builder}" failonerror="true">
<arg value="${unsigned.abs}">
<arg value="-u">
<arg value="-z">
<arg value="${resources.abs}">
<arg value="-f">
<arg value="${dex.abs}">
<arg value="-rf">
<arg value="${src.abs}">
<arg value="-rj">
<arg value="${lib.abs}">
</arg></arg></arg></arg></arg></arg></arg></arg></arg></arg></exec>
<echo>It will need to be signed with jarsigner before being published.</echo>
</target>
<!-- Sign the APK. -->
<target name="jarsigner" depends="release">
<exec executable="${jarsigner}" failonerror="true">
<arg value="-verbose">
<arg value="-storepass">
<arg value="${keystore.password}">
<arg value="-keystore">
<arg value="${keystore.path}">
<arg value="-signedjar">
<arg value="${signed.abs}">
<arg value="${unsigned.abs}">
<arg value="${keystore.alias}">
</arg></arg></arg></arg></arg></arg></arg></arg></arg></exec>
</target>
<!-- Zipalign -->
<target name="zipalign" depends="jarsigner">
<tstamp>
<format property="time" pattern="yyyy-MM-dd-HH-mm-ss"></format>
</tstamp>
<exec executable="${zipalign}" failonerror="true">
<arg value="-v">
<arg value="-f">
<arg value="4">
<arg value="${signed.abs}">
<arg value="${basedir}\bin\${ant.project.name}-${time}.apk">
</arg></arg></arg></arg></arg></exec>
</target>
</project>
</?xml>