Android in Hudson (9) 範例 ant build file

Android in Hudson (9) 範例 ant build file

下面是我android專案用的build file完整內容,大家可以參考。


	<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. -->
<project basedir="." default="help" name="your project name">
  	<property name="sdk.dir" value="path to your Android SDK" />
	
	<property file="default.properties" />
	
	<!-- Sign apk -->
	<property name="key.store" value="path to your key.store" />
	<property name="key.store.password" value="password for your key.store" />
	<property name="key.alias" value="alias for your key.stroe" />
	<property name="key.alias.password" value="password for your alias of key.store" />
	<property name="has.keystore" value="true" />
	
	<!-- daily build apk folder -->
	<property name="out.folder" value="path to store your daily build apk" />
	
	<path id="android.antlibs">
        <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
        <pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
        <pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
        <pathelement path="${sdk.dir}/tools/lib/apkbuilder.jar" />
        <pathelement path="${sdk.dir}/tools/lib/jarutils.jar" />
    </path>
	<taskdef name="setup"
        classname="com.android.ant.SetupTask"
        classpathref="android.antlibs" />

	<!-- findbugs -->
	<property name="findbugs.home" value="path to your findbugs" />
	<path id="fundbugs_lib">
		<fileset dir="${findbugs.home}/lib/">
		   <include name="*.jar"/>
		 </fileset>
	</path>
	
	<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="fundbugs_lib" />
		
	<!-- PMD -->
	<property name="pmd.home" value="path to your PMD" />
	<path id="pmd_lib">
		<fileset dir="${pmd.home}/lib/">
			<include name="*.jar"/>
		</fileset>
	</path>
	
	<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd_lib"/>
	
	<!-- CheckStyle -->
	<property name="checkstyle.home" value="path to your checkstyle" />
	
	<taskdef resource="checkstyletask.properties" classpath="${checkstyle.home}/checkstyle-5.3-all.jar"/>

	<setup />
	
	<!-- release with sign -->
	<target name="daily-release" depends="-set-release-mode, -package-release" >
        <!-- Signs the APK -->
        <echo>Signing final apk...</echo>
        <signjar
                jar="${out.unsigned.file}"
                signedjar="${out.unaligned.file}"
                keystore="${key.store}"
                storepass="${key.store.password}"
                alias="${key.alias}"
                keypass="${key.alias.password}"
                verbose="${verbose}" />

        <!-- Zip aligns the APK -->
        <zipalign-helper in.package="${out.unaligned.file}"
                                   out.package="${out.release.file}" />
        <echo>Release Package: ${out.release.file}</echo>
		<mkdir dir="${out.folder}"/>
		 <tstamp>
			<format property="NOW.TIMESTAMP" pattern="yyyy-MM-dd-hhmm" locale="zh,TW"/>
		</tstamp>
		<move file="${out.release.file}" tofile="${out.folder}/${ant.project.name}/${ant.project.name}-${NOW.TIMESTAMP}.apk"/>
    </target>

	<!-- findbugs -->
	<target name="findbugs" >
		<findbugs home="${findbugs.home}"
	              output="xml:withMessages"
	              outputFile="findbugs.xml" 
	    		  jvmargs="-Xss1m -Xmx800m" >
			<sourcePath path="src" />
			<class location="bin/classes" />
		</findbugs>
	</target>
	
	<!-- PMD -->
	<target name="pmd">
	 <pmd shortFilenames="true">
	  <ruleset>rulesets/favorites.xml</ruleset>
	  <ruleset>basic</ruleset>
	  <formatter type="xml" toFile="pmd.xml"/>
	  <fileset dir="src">
	   <include name="**/*.java"/>
	  </fileset>
	 </pmd>
	</target>
	
	<target name="checkstyle" description="Generates a report of code convention violations.">
		<checkstyle config="${checkstyle.home}/sun_checks.xml"
					failureProperty="checkstyle.failure"
					failOnViolation="false">
			<formatter type="xml" tofile="checkstyle_report.xml"/>
			<fileset dir="src" includes="**/*.java"/>
		</checkstyle>
	</target>
</project>

以下是我android test專案用的 build file完整內容,大家可以參考。


	<?xml version="1.0" encoding="UTF-8"?>
<project name="your test project name" default="help">

    <!-- The local.properties file is created and updated by the 'android' tool.
         It contains the path to the SDK. It should *NOT* be checked in in Version
         Control Systems. -->
	<property name="sdk.dir" value="path to your Android SDK" />
	<property name="tested.project.dir" value="." />
	<property name="test.runner" value="com.zutubi.android.junitreport.JUnitReportTestRunner" />
	<property file="default.properties" />

    <!-- Custom Android task to deal with the project target, and import the proper rules.
         This requires ant 1.6.0 or above. -->
    <path id="android.antlibs">
        <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
        <pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
        <pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
        <pathelement path="${sdk.dir}/tools/lib/apkbuilder.jar" />
        <pathelement path="${sdk.dir}/tools/lib/jarutils.jar" />
    </path>

    <taskdef name="setup"
        classname="com.android.ant.SetupTask"
        classpathref="android.antlibs" />

    <setup />
	
	<target name="coverage-xml" depends="-set-coverage-classpath, -install-instrumented, install"
                description="Runs the tests against the instrumented code and generates
                            code coverage report">
        <run-tests-helper emma.enabled="true">
            <extra-instrument-args>
                <arg value="-e" />
                   <arg value="coverageFile" />
                   <arg value="${emma.dump.file}" />
            </extra-instrument-args>
        </run-tests-helper>
		<echo>Downloading XML test report...</echo>
        <exec executable="${adb}" failonerror="true">
			<arg line="${adb.device.arg}"/>
            <arg value="pull" />
            <arg value="/data/data/${tested.manifest.package}/files/junit-report.xml" />
            <arg value="junit-report.xml" />
        </exec>
        <echo>Downloading coverage file into project directory...</echo>
        <exec executable="${adb}" failonerror="true">
			<arg line="${adb.device.arg}" />
            <arg value="pull" />
            <arg value="${emma.dump.file}" />
            <arg value="coverage.ec" />
        </exec>
        <echo>Extracting coverage report...</echo>
        <emma>
            <report sourcepath="${tested.project.absolute.dir}/${source.dir}"
                              verbosity="${verbosity}">
                <!-- TODO: report.dir or something like should be introduced if necessary -->
                <infileset dir=".">
                    <include name="coverage.ec" />
                    <include name="coverage.em" />
                </infileset>
                <!-- TODO: reports in other, indicated by user formats -->
                <xml outfile="coverage.xml" />
           </report>
        </emma>
        <echo>Cleaning up temporary files...</echo>
        <delete dir="${instrumentation.absolute.dir}" />
        <delete file="coverage.ec" />
        <delete file="coverage.em" />
        <echo>Saving the report file in ${basedir}/coverage/coverage.xml</echo>
    </target>
</project>

這兩個build file寫法應該不是最好的,僅供給大家參考。