build: move custom rules to custom_rules.xml

usb
Georg Lukas 2015-08-27 20:31:00 +02:00
rodzic 08312e7a09
commit 0257620f25
2 zmienionych plików z 105 dodań i 92 usunięć

117
build.xml
Wyświetl plik

@ -4,7 +4,7 @@
<!-- The local.properties file is created and updated by the 'android' tool. <!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. --> Version Control Systems. -->
<loadproperties srcFile="local.properties" /> <property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the <!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it. 'android' tool to add properties to it.
@ -28,6 +28,15 @@
--> -->
<property file="ant.properties" /> <property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android' <!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT. tool, as well as ADT.
@ -41,49 +50,23 @@
<!-- quick check on sdk.dir --> <!-- quick check on sdk.dir -->
<fail <fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'" message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir" unless="sdk.dir"
/> />
<!--
<!-- extension targets. Uncomment the ones where you want to do custom work Import per project custom build rules if present at the root of the project.
in between standard targets --> This is the place to put custom intermediary targets such as:
<property name="mapviewxml" value="res/layout/mapview.xml" /> -pre-build
<target name="-pre-build"> -pre-compile
<fail unless="mapsApiKey">You need to add mapsApiKey=... to local.properties</fail> -post-compile (This is typically used for code obfuscation.
<copy file="mapview.xml.tpl" tofile="${mapviewxml}" overwrite="true"> Compiled code location: ${out.classes.absolute.dir}
<filterchain> If this is not done in place, override ${out.dex.input.absolute.dir})
<replacetokens> -post-package
<token key="apiKey" value="${mapsApiKey}"/> -post-build
</replacetokens> -pre-clean
</filterchain> -->
<import file="custom_rules.xml" optional="true" />
</copy>
<tstamp>
<format property="build.date" pattern="yyyy-MM-dd" />
</tstamp>
<exec executable="git" outputproperty="git.revision">
<arg line="describe --tags --dirty=+"/>
</exec>
<copy file="version.xml.tpl" tofile="${resource.absolute.dir}/values/version.xml" overwrite="true">
<filterchain>
<replacetokens>
<token key="build_version" value="${ant.project.name} ${git.revision} ${build.date}"/>
</replacetokens>
</filterchain>
</copy>
</target>
<!--
<target name="-pre-compile">
</target>
/* This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir} */
-->
<target name="-post-compile" depends="scalac, proguard">
</target>
<!-- Import the actual build file. <!-- Import the actual build file.
@ -103,57 +86,7 @@
In all cases you must update the value of version-tag below to read 'custom' instead of an integer, In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project" in order to avoid having your file be overridden by tools such as "android update project"
--> -->
<!-- version-tag: custom --> <!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" /> <import file="${sdk.dir}/tools/ant/build.xml" />
<target name="check-scalalib">
<available file="tools/scala-library.jar" property="have.scalalib"/>
<fail unless="have.scalalib">You have to place scala-compiler.jar and scala-library.jar to tools/</fail>
</target>
<target name="check-scalac">
<available file="tools/scala-compiler.jar" property="have.scalac"/>
<fail unless="have.scalac">You have to place scala-compiler.jar and scala-library.jar to tools/</fail>
</target>
<target name="scalac" depends="-compile, check-scalalib, check-scalac">
<taskdef resource="scala/tools/ant/antlib.xml"
classpath="tools/scala-compiler.jar:tools/scala-library.jar:tools/scala-reflect.jar" />
<scalac force="changed" deprecation="on"
srcdir="${source.absolute.dir}" includes="**/*.scala"
bootclasspathref="project.target.class.path"
destdir="${out.classes.absolute.dir}">
<classpath>
<pathelement location="${out.classes.absolute.dir}"/>
<fileset dir="tools" includes="*.jar"/>
<fileset dir="${jar.libs.dir}" includes="*.jar"/>
</classpath>
</scalac>
</target>
<target name="check-proguard">
<available file="tools/proguard.jar" property="have.proguard"/>
<fail unless="have.proguard">ProGuard is required to build! Copy proguard.jar to tools/</fail>
</target>
<property name="optimized.dir" value="${out.absolute.dir}/optimized" />
<target name="proguard" depends="scalac, check-proguard">
<taskdef resource="proguard/ant/task.properties"
classpath="tools/proguard.jar" />
<mkdir dir="${optimized.dir}" />
<proguard configuration="proguard.cfg">
-injars ${out.classes.absolute.dir}:${jar.libs.dir}:tools/scala-library.jar(!META-INF/MANIFEST.MF,!library.properties)
-outjars ${out.absolute.dir}/classes.min.jar
-libraryjars ${toString:project.target.class.path}
-printusage ${optimized.dir}/proguard.usage
</proguard>
</target>
<target name="-dex" depends="-post-compile">
<echo>Converting compiled files and external libraries into ${intermediate.dex.file}...</echo>
<apply executable="${dx}" failonerror="true" parallel="true">
<arg value="--dex" />
<arg value="--output=${intermediate.dex.file}" />
<fileset dir="${out.absolute.dir}" includes="*.min.jar"/>
</apply>
</target>
</project> </project>

80
custom_rules.xml 100644
Wyświetl plik

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<property name="mapviewxml" value="res/layout/mapview.xml" />
<target name="-pre-build">
<fail unless="mapsApiKey">You need to add mapsApiKey=... to local.properties</fail>
<copy file="mapview.xml.tpl" tofile="${mapviewxml}" overwrite="true">
<filterchain>
<replacetokens>
<token key="apiKey" value="${mapsApiKey}"/>
</replacetokens>
</filterchain>
</copy>
<tstamp>
<format property="build.date" pattern="yyyy-MM-dd" />
</tstamp>
<exec executable="git" outputproperty="git.revision">
<arg line="describe --tags --dirty=+"/>
</exec>
<copy file="version.xml.tpl" tofile="${resource.absolute.dir}/values/version.xml" overwrite="true">
<filterchain>
<replacetokens>
<token key="build_version" value="${ant.project.name} ${git.revision} ${build.date}"/>
</replacetokens>
</filterchain>
</copy>
</target>
<target name="check-scalalib">
<available file="tools/scala-library.jar" property="have.scalalib"/>
<fail unless="have.scalalib">You have to place scala-compiler.jar and scala-library.jar to tools/</fail>
</target>
<target name="check-scalac">
<available file="tools/scala-compiler.jar" property="have.scalac"/>
<fail unless="have.scalac">You have to place scala-compiler.jar and scala-library.jar to tools/</fail>
</target>
<target name="scalac" depends="-compile, check-scalalib, check-scalac">
<taskdef resource="scala/tools/ant/antlib.xml"
classpath="tools/scala-compiler.jar:tools/scala-library.jar:tools/scala-reflect.jar" />
<scalac force="changed" deprecation="on"
srcdir="${source.absolute.dir}" includes="**/*.scala"
bootclasspathref="project.target.class.path"
destdir="${out.classes.absolute.dir}">
<classpath>
<pathelement location="${out.classes.absolute.dir}"/>
<fileset dir="tools" includes="*.jar"/>
<fileset dir="${jar.libs.dir}" includes="*.jar"/>
</classpath>
</scalac>
</target>
<!-- proguard is always enabled in APRSdroid -->
<target name="-post-compile" depends="scalac, proguard" />
<target name="proguard" depends="scalac">
<property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar" />
<taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" />
<property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard" />
<property name="obfuscated.jar.file" value="${obfuscate.absolute.dir}/obfuscated.jar" />
<property name="out.dex.input.absolute.dir" value="${obfuscated.jar.file}" />
<mkdir dir="${obfuscate.absolute.dir}" />
<proguard configuration="proguard.cfg">
-injars ${out.classes.absolute.dir}:${jar.libs.dir}:tools/scala-library.jar(!META-INF/MANIFEST.MF,!library.properties)
-outjars ${obfuscated.jar.file}
-libraryjars ${toString:project.target.class.path}
-dump "${obfuscate.absolute.dir}/dump.txt"
-printseeds "${obfuscate.absolute.dir}/seeds.txt"
-printusage "${obfuscate.absolute.dir}/usage.txt"
-printmapping "${obfuscate.absolute.dir}/mapping.txt"
</proguard>
<path id="out.dex.jar.input.ref" />
</target>
<target name="-obfuscate" depends="proguard" />
</project>