Target 'run-tests' launches all the unit tests against the tested project. Target 'coverage' emma-instruments the tested project's classes, runs the tests against instrumented classes, collects code coverage data and extracts it to human-readable form as report.html. android_test_rules.xml contain additional rules for test projects. Test projects are auto-recognized by presence of the tested.project.dir property, which will be auto-generated for tests projects. Temporarily, please add this property manually to the build.properties file. Current version is mainly tested with default, android generated test projects. This version includes also fixing relative to absolute paths for properties which are most likely to be changed by user in external property file.
331 lines
14 KiB
XML
331 lines
14 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<project name="android_rules" default="debug">
|
|
|
|
<!--
|
|
This rules file is meant to be imported by the custom Ant task:
|
|
com.android.ant.AndroidInitTask
|
|
|
|
The following properties are put in place by the importing task:
|
|
android.jar, android.aidl, aapt, aidl, and dx
|
|
|
|
Additionnaly, the task sets up the following classpath reference:
|
|
android.target.classpath
|
|
This is used by the compiler task as the boot classpath.
|
|
-->
|
|
|
|
<!-- Custom tasks -->
|
|
<taskdef name="aaptexec"
|
|
classname="com.android.ant.AaptExecLoopTask"
|
|
classpathref="android.antlibs" />
|
|
|
|
<taskdef name="apkbuilder"
|
|
classname="com.android.ant.ApkBuilderTask"
|
|
classpathref="android.antlibs" />
|
|
|
|
<!-- Properties -->
|
|
|
|
<property name="android.tools.dir" location="${sdk.dir}/tools" />
|
|
|
|
<!-- Input directories -->
|
|
<property name="source.dir" value="src" />
|
|
<property name="source.absolute.dir" location="${source.dir}" />
|
|
<property name="gen.dir" value="gen" />
|
|
<property name="gen.absolute.dir" location="${gen.dir}" />
|
|
<property name="resource.dir" value="res" />
|
|
<property name="resource.absolute.dir" location="${resource.dir}" />
|
|
<property name="asset.dir" value="assets" />
|
|
<property name="asset.absolute.dir" location="${asset.dir}" />
|
|
|
|
<!-- Directory for the third party java libraries -->
|
|
<property name="external.libs.dir" value="libs" />
|
|
<property name="external.libs.absolute.dir" location="${external.libs.dir}" />
|
|
|
|
<!-- In this file it is just alias for external.libs.absolute.dir. It is used for
|
|
reusability though, when calling ant targets in this file from other files.
|
|
However, it is a temporary solution. -->
|
|
<property name="external.jars" location="${external.libs.absolute.dir}" />
|
|
|
|
<!-- Directory for the native libraries -->
|
|
<property name="native.libs.dir" value="libs" />
|
|
<property name="native.libs.absolute.dir" location="${native.libs.dir}" />
|
|
|
|
<!-- Output directories -->
|
|
<property name="out.dir" value="bin" />
|
|
<property name="out.absolute.dir" location="${out.dir}" />
|
|
<property name="out.classes.dir" value="${out.dir}/classes" />
|
|
<property name="out.classes.absolute.dir" location="${out.classes.dir}" />
|
|
|
|
<!-- Intermediate files -->
|
|
<property name="dex.file.name" value="classes.dex" />
|
|
<property name="intermediate.dex.file" location="${out.absolute.dir}/${dex.file.name}" />
|
|
|
|
<!-- The final package file to generate -->
|
|
<property name="out.debug.unaligned.package"
|
|
location="${out.absolute.dir}/${ant.project.name}-debug-unaligned.apk" />
|
|
<property name="out.debug.package" location="${out.absolute.dir}/${ant.project.name}-debug.apk" />
|
|
<property name="out.unsigned.package" location="${out.absolute.dir}/${ant.project.name}-unsigned.apk" />
|
|
<property name="out.unaligned.package"
|
|
location="${out.absolute.dir}/${ant.project.name}-unaligned.apk" />
|
|
<property name="out.release.package" location="${out.absolute.dir}/${ant.project.name}-release.apk" />
|
|
|
|
<!-- Tools -->
|
|
<condition property="exe" value=".exe" else=""><os family="windows" /></condition>
|
|
<property name="adb" location="${android.tools.dir}/adb${exe}" />
|
|
<property name="zipalign" location="${android.tools.dir}/zipalign${exe}" />
|
|
|
|
<!-- Rules -->
|
|
|
|
<!-- Creates the output directories if they don't exist yet. -->
|
|
<target name="-dirs">
|
|
<echo>Creating output directories if needed...</echo>
|
|
<mkdir dir="${resource.absolute.dir}" />
|
|
<mkdir dir="${external.libs.absolute.dir}" />
|
|
<mkdir dir="${gen.absolute.dir}" />
|
|
<mkdir dir="${out.absolute.dir}" />
|
|
<mkdir dir="${out.classes.absolute.dir}" />
|
|
</target>
|
|
|
|
<!-- Generates the R.java file for this project's resources. -->
|
|
<target name="-resource-src" depends="-dirs">
|
|
<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 path="${gen.absolute.dir}" />
|
|
<arg value="-M" />
|
|
<arg path="AndroidManifest.xml" />
|
|
<arg value="-S" />
|
|
<arg path="${resource.absolute.dir}" />
|
|
<arg value="-I" />
|
|
<arg path="${android.jar}" />
|
|
</exec>
|
|
</target>
|
|
|
|
<!-- Generates java classes from .aidl files. -->
|
|
<target name="-aidl" depends="-dirs">
|
|
<echo>Compiling aidl files into Java classes...</echo>
|
|
<apply executable="${aidl}" failonerror="true">
|
|
<arg value="-p${android.aidl}" />
|
|
<arg value="-I${source.absolute.dir}" />
|
|
<arg value="-o${gen.absolute.dir}" />
|
|
<fileset dir="${source.absolute.dir}">
|
|
<include name="**/*.aidl" />
|
|
</fileset>
|
|
</apply>
|
|
</target>
|
|
|
|
<!-- Compiles this project's .java files into .class files. -->
|
|
<target name="compile" depends="-resource-src, -aidl"
|
|
description="Compiles project's .java files into .class files">
|
|
<!-- Allows to inject additional classpath from another (build|property) file.
|
|
As ant properties are immutable, the injected value will have priority
|
|
over the one defined below -->
|
|
<property name="extensible.classpath" value="." />
|
|
<javac encoding="ascii" target="1.5" debug="true" extdirs=""
|
|
destdir="${out.classes.absolute.dir}"
|
|
bootclasspathref="android.target.classpath"
|
|
verbose="false" classpath="${extensible.classpath}">
|
|
<src path="${source.absolute.dir}" />
|
|
<src path="${gen.absolute.dir}" />
|
|
<classpath>
|
|
<fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
|
|
</classpath>
|
|
</javac>
|
|
</target>
|
|
|
|
<!-- Configurable macro, which allows to pass as parameters output directory,
|
|
output dex filename and external libraries to dex (optional) -->
|
|
<macrodef name="dex-helper">
|
|
<attribute name="out.absolute.dir" />
|
|
<attribute name="out.dex.file" />
|
|
<element name="external-libs" optional="yes" />
|
|
<sequential>
|
|
<echo>Converting compiled files and external libraries into @{out.dex.file}...</echo>
|
|
<apply executable="${dx}" failonerror="true" parallel="true">
|
|
<arg value="--dex" />
|
|
<arg value="--output=@{out.dex.file}" />
|
|
<arg path="@{out.absolute.dir}" />
|
|
<external-libs />
|
|
</apply>
|
|
</sequential>
|
|
</macrodef>
|
|
|
|
<!-- Converts this project's .class files into .dex files -->
|
|
<target name="-dex" depends="compile">
|
|
<dex-helper out.absolute.dir="${out.absolute.dir}/classes"
|
|
out.dex.file="${intermediate.dex.file}">
|
|
<external-libs>
|
|
<!-- Temporary solution, before <jarfile> in <apkbuilder> is ready -->
|
|
<fileset dir="${external.jars}" includes="*.jar" />
|
|
</external-libs>
|
|
</dex-helper>
|
|
</target>
|
|
|
|
<!-- Puts the project's resources into the output package file
|
|
This actually can create multiple resource package in case
|
|
Some custom apk with specific configuration have been
|
|
declared in default.properties.
|
|
-->
|
|
<target name="-package-resources">
|
|
<echo>Packaging resources</echo>
|
|
<aaptexec executable="${aapt}"
|
|
command="package"
|
|
manifest="AndroidManifest.xml"
|
|
resources="${resource.absolute.dir}"
|
|
assets="${asset.absolute.dir}"
|
|
androidjar="${android.jar}"
|
|
outfolder="${out.absolute.dir}"
|
|
basename="${ant.project.name}" />
|
|
</target>
|
|
|
|
<!-- Packages the application and (maybe) sign it with a debug key.
|
|
This requires the property sign.package to be set to true or false. -->
|
|
<target name="-package">
|
|
<apkbuilder
|
|
outfolder="${out.absolute.dir}"
|
|
basename="${ant.project.name}"
|
|
signed="${sign.package}"
|
|
verbose="true">
|
|
<file path="${intermediate.dex.file}" />
|
|
<sourcefolder path="${source.absolute.dir}" />
|
|
<jarfolder path="${external.jars}" />
|
|
<nativefolder path="${native.libs.absolute.dir}" />
|
|
</apkbuilder>
|
|
</target>
|
|
|
|
<target name="-no-sign">
|
|
<property name="sign.package" value="false" />
|
|
</target>
|
|
|
|
<target name="-debug-sign">
|
|
<property name="sign.package" value="true" />
|
|
</target>
|
|
|
|
<!-- Builds debug output package, provided all the necessary files are already dexed -->
|
|
<target name="-debug-no-dex" depends="-package-resources, -debug-sign, -package">
|
|
<echo>Running zip align on final apk...</echo>
|
|
<exec executable="${zipalign}" failonerror="true">
|
|
<arg value="-f" />
|
|
<arg value="4" />
|
|
<arg path="${out.debug.unaligned.package}" />
|
|
<arg path="${out.debug.package}" />
|
|
</exec>
|
|
<echo>Debug Package: ${out.debug.package}</echo>
|
|
</target>
|
|
|
|
<target name="debug" depends="-dex, -debug-no-dex"
|
|
description="Builds the application and signs it with a debug key." />
|
|
|
|
<target name="-release-package" depends="-dex, -package-resources, -no-sign, -package" />
|
|
|
|
<target name="-release-check">
|
|
<condition property="release.sign">
|
|
<and>
|
|
<isset property="key.store" />
|
|
<isset property="key.alias" />
|
|
</and>
|
|
</condition>
|
|
</target>
|
|
|
|
<target name="-release-nosign" depends="-release-check" unless="release.sign">
|
|
<echo>No key.store and key.alias properties found in build.properties.</echo>
|
|
<echo>Please sign ${out.unsigned.package} manually</echo>
|
|
<echo>and run zipalign from the Android SDK tools.</echo>
|
|
</target>
|
|
|
|
<target name="release" depends="-release-package, -release-nosign" if="release-sign"
|
|
description="Builds the application. The generated apk file must be signed before
|
|
it is published.">
|
|
<!-- Gets passwords -->
|
|
<input
|
|
message="Please enter keystore password (store:${key.store}):"
|
|
addproperty="key.store.password" />
|
|
<input
|
|
message="Please enter password for alias '${key.alias}':"
|
|
addproperty="key.alias.password" />
|
|
|
|
<!-- Signs the APK -->
|
|
<echo>Signing final apk...</echo>
|
|
<signjar
|
|
jar="${out.unsigned.package}"
|
|
signedjar="${out.unaligned.package}"
|
|
keystore="${key.store}"
|
|
storepass="${key.store.password}"
|
|
alias="${key.alias}"
|
|
keypass="${key.alias.password}" />
|
|
|
|
<!-- Zip aligns the APK -->
|
|
<echo>Running zip align on final apk...</echo>
|
|
<exec executable="${zipalign}" failonerror="true">
|
|
<arg value="-f" />
|
|
<arg value="4" />
|
|
<arg path="${out.unaligned.package}" />
|
|
<arg path="${out.release.package}" />
|
|
</exec>
|
|
<echo>Release Package: ${out.release.package}</echo>
|
|
</target>
|
|
|
|
<!-- Installs the package on the default emulator/device -->
|
|
<target name="-install-no-deps">
|
|
<echo>Installing ${out.debug.package} onto default emulator or device...</echo>
|
|
<exec executable="${adb}" failonerror="true">
|
|
<arg value="install" />
|
|
<arg value="-r" />
|
|
<arg path="${out.debug.package}" />
|
|
</exec>
|
|
</target>
|
|
|
|
<target name="install" depends="debug, -install-no-deps"
|
|
description="Installs/reinstalls the debug package onto a running
|
|
emulator or device. If the application was previously installed,
|
|
the signatures must match." />
|
|
|
|
<target name="-install-no-dex" depends="-debug-no-dex, -install-no-deps" />
|
|
|
|
<target name="-uninstall-check">
|
|
<condition property="uninstall.run">
|
|
<isset property="application.package" />
|
|
</condition>
|
|
</target>
|
|
|
|
<target name="-uninstall-error" depends="-uninstall-check" unless="uninstall.run">
|
|
<echo>
|
|
Unable to run 'ant uninstall', application.package is not defined in build.properties
|
|
</echo>
|
|
</target>
|
|
|
|
<!-- Uninstalls the package from the default emulator/device -->
|
|
<target name="uninstall" depends="-uninstall-error" if="uninstall.run"
|
|
description="Uninstalls the application from a running emulator or device.">
|
|
<echo>Uninstalling ${application.package} from the default emulator or device...</echo>
|
|
<exec executable="${adb}" failonerror="true">
|
|
<arg value="uninstall" />
|
|
<arg value="${application.package}" />
|
|
</exec>
|
|
</target>
|
|
|
|
<target name="clean" description="Removes output files created by other targets.">
|
|
<delete dir="${out.absolute.dir}" />
|
|
<delete dir="${gen.absolute.dir}" />
|
|
</target>
|
|
|
|
<target name="help">
|
|
<!-- displays starts at col 13
|
|
|13 80| -->
|
|
<echo>Android Ant Build. Available targets:</echo>
|
|
<echo> help: Displays this help.</echo>
|
|
<echo> clean: Removes output files created by other targets.</echo>
|
|
<echo> compile: Compiles project's .java files into .class files.</echo>
|
|
<echo> debug: Builds the application and signs it with a debug key.</echo>
|
|
<echo> release: Builds the application. The generated apk file must be</echo>
|
|
<echo> signed before it is published.</echo>
|
|
<echo> install: Installs/reinstalls the debug package onto a running</echo>
|
|
<echo> emulator or device.</echo>
|
|
<echo> If the application was previously installed, the</echo>
|
|
<echo> signatures must match.</echo>
|
|
<echo> uninstall: Uninstalls the application from a running emulator or</echo>
|
|
<echo> device.</echo>
|
|
</target>
|
|
</project>
|