<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>a little madness &#187; Build</title>
	<atom:link href="http://www.alittlemadness.com/category/build/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alittlemadness.com</link>
	<description>A man needs a little madness, or else he never dares cut the rope and be free. -Nikos Kazantzakis</description>
	<lastBuildDate>Wed, 11 Aug 2010 04:58:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pulse Continuous Integration Server 2.2!</title>
		<link>http://www.alittlemadness.com/2010/08/11/pulse-continuous-integration-server-2-2/</link>
		<comments>http://www.alittlemadness.com/2010/08/11/pulse-continuous-integration-server-2-2/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 04:58:55 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Zutubi]]></category>

		<guid isPermaLink="false">http://www.alittlemadness.com/?p=722</guid>
		<description><![CDATA[Big news today: Pulse 2.2 has graduated to stable!  This release includes a stack of new features and improvements, including:

Build UI overhaul: all tabs improved and restyled.
New logs tab: making it easier to access stage logs.
Featured artifacts: choose which artifacts should appear prominently.
Build navigator: easily move forward and backward through history.
Working copy browser: view [...]]]></description>
			<content:encoded><![CDATA[<p>Big news today: <a href="http://zutubi.com/products/pulse/">Pulse 2.2</a> has graduated to stable!  This release includes a stack of new features and improvements, including:</p>
<ul>
<li>Build UI overhaul: all tabs improved and restyled.</li>
<li>New logs tab: making it easier to access stage logs.</li>
<li>Featured artifacts: choose which artifacts should appear prominently.</li>
<li>Build navigator: easily move forward and backward through history.</li>
<li>Working copy browser: view working copies for in progress builds.</li>
<li>Move refactoring: move projects and agents in the template hierarchy.</li>
<li>Template navigation: navigate directly up and down a hierarchy.</li>
<li>Subscription by label: subscribe to notifications by project groups.</li>
<li>Agent executing stages: see what all agents are building at a glance.</li>
<li>Subversion exports: for faster and smaller builds.</li>
<li>Performance improvements: key for larger installations.</li>
</ul>
<p>See the <a href="http://zutubi.com/products/pulse/new/">new in 2.2 page</a> for full details.</p>
<p>In conjunction with this release, we&#8217;ve also given our <a href="http://zutubi.com/">website</a> a complete overhaul.  The new site has a fresher look, and communicates the key features of Pulse more directly.  The updates also include some new features: </p>
<ul>
<li>RSS feeds for news items.</li>
<li>Links to our latest blog posts on the front page.</li>
<li>An improved buying process, allowing multiple licenses to be purchased in one transaction.</li>
<li>Self-service renewal payments &#8211; just enter your current license key and go!</li>
<li>A more user-friendly downloads page.</li>
</ul>
<p>We hope you enjoy the new release, and the new site.  And please, <a href="mailto:support@zutubi.com">let us know</a> what you think!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alittlemadness.com/2010/08/11/pulse-continuous-integration-server-2-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simpler Ant Builds With the Ant Script Library</title>
		<link>http://www.alittlemadness.com/2010/07/29/simpler-ant-builds-with-the-ant-script-library/</link>
		<comments>http://www.alittlemadness.com/2010/07/29/simpler-ant-builds-with-the-ant-script-library/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 09:39:21 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Project Automation]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.alittlemadness.com/?p=694</guid>
		<description><![CDATA[Introduction
Ant may be unfashionable these days, but it still has its advantages.  Key among these are familiarity and simplicity: most Java developers have worked with Ant, and with an Ant build what you get is what you see.  A major disadvantage, though, is that Ant provides very little out-of-the-box.  When you start [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p><a href="http://ant.apache.org/">Ant</a> may be unfashionable these days, but it still has its advantages.  Key among these are familiarity and simplicity: most Java developers have worked with Ant, and with an Ant build what you get is what you see.  A major disadvantage, though, is that Ant provides very little out-of-the-box.  When you start a new project, you&#8217;ve got a lot of grunt work to endure just to get your code compiled, packaged, and tested.  An all-too-common solution, in the grand tradition of <a href="http://www.gnu.org/software/make/">make</a>, is to copy a build file from an existing project as an easy starting point.</p>
<p>Over the years, though, Ant has gradually expanded support for creating reusable build file snippets.  On top of this a few projects have emerged which aim to simplify and standardise your Ant builds, including:</p>
<ul>
<li><a href="http://www.easyant.org/">EasyAnt</a></li>
<li><a href="http://code.google.com/p/ant-master-build-scripts/">Ant Master Build Scripts</a></li>
<li><a href="http://www.exubero.com/asl/">Ant Script Library</a></li>
</ul>
<p>Today I&#8217;ve taken my first proper look at the latter, and so far I like what I see.</p>
<h3>The Ant Script Library</h3>
<p>In the author Joe Schmetzer&#8217;s own words:</p>
<blockquote><p>The Ant Script Library (ASL) is a collection of re-usable Ant scripts that can be imported into your own projects. The ASL provides a number of pre-defined targets that simplify setting up build scripts for a new project, bringing re-use and consistency to your own Ant scripts.</p></blockquote>
<p>ASL consists of several Ant XML files, each of which provides a group of related functionality via predefined targets.  For example, the <b>asl-java-build.xml</b> file defines targets for compiling and packaging Java code.  The <b>asl-java-test.xml</b> file extends this with the ability to run JUnit tests, and so on.  Essentially, ASL packages up all the grunt work, allowing you to concentrate on the small tweaks and extra targets unique to your project.  The modular structure of ASL, combined with the fact that it is just Ant properties and targets, makes it easy to take what you like and leave the rest.</p>
<h3>An Example</h3>
<p>Allow me to illustrate with a simple project I have been playing with.  This project has a straightforward directory structure:</p>
<ul>
<li>&lt;project root&gt;
<ul style="font-size: 1em;">
<li>asl/ &#8211; the Ant Script Library</li>
<li>build.xml &#8211; Ant build file</li>
<li>lib/ &#8211; Jar file depedencies</li>
<li>src/ &#8211; Java source files</li>
<li>test/ &#8211; JUnit-based test source files</li>
</ul>
</li>
</ul>
<p>To add ASL to my project, I simply downloaded it from the project <a href="http://www.exubero.com/asl/download.html">download page</a> and unpacked it in the <b>asl/</b> subdirectory of my project<sup>1</sup>.  Then I can start with a very simple build file that supports building my code and running the tests:</p>
<pre class="brush: xml;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;project name=&quot;zutubi-android-ant&quot; default=&quot;dist&quot;&gt;
    &lt;property name=&quot;java-build.src-dir&quot; location=&quot;src&quot;/&gt;
    &lt;property name=&quot;java-test.src-dir&quot; location=&quot;test&quot;/&gt;
    &lt;property name=&quot;java-build.lib-dir&quot; location=&quot;libs&quot;/&gt;

    &lt;property name=&quot;asl.dir&quot; value=&quot;asl&quot;/&gt;

    &lt;import file=&quot;${asl.dir}/asl-java-build.xml&quot;/&gt;
    &lt;import file=&quot;${asl.dir}/asl-java-test.xml&quot;/&gt;
&lt;/project&gt;</pre>
<p>Notice that I am using non-standard source locations, but that is easily tweaked using properties which are <a href="http://www.exubero.com/asl/reference.html">fully documented</a>.  With this tiny build file, let&#8217;s see what targets ASL provides for me:</p>
<pre class="brush: plain;">$ ant -p
Buildfile: build.xml

Main targets:

 clean                 Deletes files generated by the build
 compile               Compiles the java source
 copy-resources        Copies resources in preparation to be packaged in jar
 dist                  Create a distributable for this java project
 generate              Generates source code
 jar                   Create a jar for this java project
 test-all              Runs all tests
 test-integration      Runs integration tests
 test-run-integration  Runs the integration tests
 test-run-unit         Runs the unit tests
 test-unit             Runs unit tests
Default target: dist</pre>
<p>It&#8217;s delightfully simple!</p>
<h3>Adding Reports</h3>
<p>It gets better: ASL also provides reporting with tools like <a href="http://cobertura.sourceforge.net/">Cobertura</a> for coverage, <a href="http://findbugs.sourceforge.net/">FindBugs</a> for static analysis and so on via its <b>asl-java-report.xml</b> module.  The full range of supported reports can be seen in the <b>report-all</b> target:</p>
<pre class="brush: xml;">&lt;target name=&quot;report-all&quot;
        depends=&quot;report-javadoc, report-tests, report-cobertura, report-jdepend, report-pmd, report-cpd, report-checkstyle, report-findbugs&quot;
        description=&quot;Runs all reports&quot;/&gt;</pre>
<p>Having support for several tools out-of-the-box is great.  For my project, however, I&#8217;d like to keep my dependencies down and I don&#8217;t feel that I need all of the reporting.  Although the choice of reports is not something that is parameterised by a property, it is still trivial to override by providing your own report-all target.  This shows the advantage of everything being plain Ant targets:</p>
<pre class="brush: xml;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;project name=&quot;zutubi-android-ant&quot; default=&quot;dist&quot;&gt;
    &lt;property name=&quot;java-build.src-dir&quot; location=&quot;src&quot;/&gt;
    &lt;property name=&quot;java-test.src-dir&quot; location=&quot;test&quot;/&gt;
    &lt;property name=&quot;java-build.lib-dir&quot; location=&quot;libs&quot;/&gt;

    &lt;property name=&quot;asl.dir&quot; value=&quot;asl&quot;/&gt;

    &lt;import file=&quot;${asl.dir}/asl-java-build.xml&quot;/&gt;
    &lt;import file=&quot;${asl.dir}/asl-java-test.xml&quot;/&gt;
    &lt;import file=&quot;${asl.dir}/asl-java-report.xml&quot;/&gt;

    &lt;target name=&quot;report-all&quot;
            depends=&quot;report-javadoc, report-tests, report-cobertura, report-pmd, report-checkstyle&quot;
            description=&quot;Runs all reports&quot;/&gt;
&lt;/project&gt;</pre>
<p>Here I&#8217;ve included the <b>java-report</b> module, but defined my own <b>report-all</b> target that depends on just the reports I want.  This keeps things simple, and allows me to trim out a bunch of ASL dependencies I don&#8217;t need.</p>
<h3>Conclusion</h3>
<p>I&#8217;ve known of ASL and such projects for a while, but this is the first time I&#8217;ve actually given one a go.  Getting started was pleasantly simple, as was applying the small tweaks I needed.  So next time you&#8217;re tempted to copy an Ant build file, give ASL a shot: you won&#8217;t regret it!</p>
<p><br/></p>
<p>&#8211;<br />
<sup>1</sup> In this case I downloaded the full tarball including dependencies, which seemed on the large side (21MB!) but in fact can be easily trimmed by removing the pieces you don&#8217;t need.  Alternatively, you can start with the basic ASL install (sans dependencies) and it can pull down libraries for you.  Sweet <img src='http://www.alittlemadness.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alittlemadness.com/2010/07/29/simpler-ant-builds-with-the-ant-script-library/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Android Testing: XML Reports for Continuous Integration</title>
		<link>http://www.alittlemadness.com/2010/07/14/android-testing-xml-reports-for-continuous-integration/</link>
		<comments>http://www.alittlemadness.com/2010/07/14/android-testing-xml-reports-for-continuous-integration/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 07:57:28 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.alittlemadness.com/?p=680</guid>
		<description><![CDATA[Summary
This post introduces the Android JUnit Report Test Runner, a custom instrumentation test runner for Android that produces XML test reports.  Using this runner you can integrate your Android test results with tools that understand the Ant JUnit task XML format, e.g. the Pulse Continuous Integration Server.
The motivation and details of the runner are [...]]]></description>
			<content:encoded><![CDATA[<h3>Summary</h3>
<p>This post introduces the <a href="http://github.com/jsankey/android-junit-report">Android JUnit Report Test Runner</a>, a custom instrumentation test runner for Android that produces XML test reports.  Using this runner you can integrate your Android test results with tools that understand the Ant JUnit task XML format, e.g. the <a href="http://zutubi.com/products/pulse/">Pulse</a> Continuous Integration Server.</p>
<p>The motivation and details of the runner are discussed below.  For the impatient: simply head on over to the project <a href="http://github.com/jsankey/android-junit-report">home page</a> on GitHub and check out the README.</p>
<h3>Introduction</h3>
<p>If you&#8217;ve been following my <a href="/2010/06/29/android-functional-testing-vs-dependency-injection/">recent</a> <a href="/2010/07/06/android-testing-using-pure-unit-tests/">posts</a> you&#8217;ll know that I&#8217;ve been figuring out the practical aspects of testing Android applications.  And if you&#8217;ve been following for longer, you might know that my day job is development of the <a href="http://zutubi.com/products/pulse/">Pulse</a> Continuous Integration Server.  So it should come as no surprise that in my latest foray into the world of Android testing I sought to bring the two together <img src='http://www.alittlemadness.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<h3>Status Quo</h3>
<p>Out of the box, the Android SDK supports running functional tests on a device or emulator via <a href="http://developer.android.com/guide/topics/testing/testing_android.html">instrumentation</a>.  Running within Eclipse, you get nice integrated feedback.  Unfortunately, though, there are no real options for integrating with other tools such as continuous integration servers.  Test output from the standard Ant builds is designed for human consumption, and lacks the level of detail I&#8217;d like to see in my build reports.</p>
<h3>The Solution</h3>
<p>On the upside, having access to the Android source makes it possible to examine how the current instrumentation works, and therefore how it can be customised.  I found that the default <a href="http://developer.android.com/reference/android/test/InstrumentationTestRunner.html">InstrumentationTestRunner</a> may be fairly easily extended to hook in extra test listeners.  So I&#8217;ve implemented a custom JUnitReportTestRunner that does just that, with a listener that generates a test report in XML format.  The format is designed to be largely compatible with the output of the Ant <a href="http://ant.apache.org/manual/Tasks/junit.html">JUnit task&#8217;s</a> XML formatter &#8212; the most widely supported format in the Java world.  Tools like Pulse can read in this format to give rich test reporting.</p>
<h3>How It Works</h3>
<p>As mentioned, the JUnitReportTestRunner extends the default InstrumentationTestRunner, so it can act as a drop-in replacement.  The custom runner acts identically to the default, with the added side-effect of producing an XML report.</p>
<p>For consistency with the SDK&#8217;s support for generating coverage reports, the XML report is generated in the file storage area of the <em>target application</em>.  The default report location is something like:</p>
<pre class="brush: plain;">/data/data/&lt;tested application package&gt;/files/junit-report.xml</pre>
<p>on the device.  To retrieve the report, you can use <b>adb pull</b>, typically as part of your scripted build.</p>
<h3>Using the Runner</h3>
<p>Full details on using the runner are provided in the README on the project <a href="http://github.com/jsankey/android-junit-report">home page</a>.  Briefly:</p>
<ul>
<li>Add the android-junit-report-&lt;version&gt;.jar to the libraries for your test application.</li>
<li>Replace all occurrences of <b>android.test.InstrumentationTestRunner</b> with <b>com.zutubi.android.junitreport.JUnitReportTestRunner</b>:
<ul style="font-size: 1em;">
<li>In the <b>android:name</b> attribute of the <b>instrumentation</b> tag in you test application&#8217;s <b>AndroidManifest.xml</b>.</li>
<li>In the <b>test.runner</b> property in the Ant build for your test application (<em>before</em> calling the Android <b>setup</b> task).</li>
<li>In the <b>Instrumentation runner</b> field of all Android JUnit Run Configurations in your Eclipse project.</li>
</ul>
</li>
<li>Add logic to your Ant build to run <b>adb pull</b> to retrieve the report after the tests are run.</li>
</ul>
<p>As an example for retrieving the report in your Ant build:</p>
<pre class="brush: xml;">&lt;target name=&quot;fetch-test-report&quot;&gt;
    &lt;echo&gt;Downloading XML test report...&lt;/echo&gt;
    &lt;mkdir dir=&quot;${reports.dir}&quot;/&gt;
    &lt;exec executable=&quot;${adb}&quot; failonerror=&quot;true&quot;&gt;
        &lt;arg line=&quot;${adb.device.arg}&quot;/&gt;
        &lt;arg value=&quot;pull&quot; /&gt;
        &lt;arg value=&quot;/data/data/${tested.manifest.package}/files/junit-report.xml&quot; /&gt;
        &lt;arg value=&quot;${reports.dir}/junit-report.xml&quot; /&gt;
    &lt;/exec&gt;
&lt;/target&gt;</pre>
<h3>In the Wild</h3>
<p>You can see a complete example of this in action in my simple <a href="http://github.com/jsankey/droidscope">DroidScope</a> Android application.  The custom runner is applied in the droidscope-test application in the test/ subdirectory.  You can even see the <a href="http://pulse.zutubi.com/browse/projects/droidscope/builds/latest/tests/default/">test results</a> being picked up by Pulse on our demo server.  Note that some of the tests are <a href="/2010/07/06/android-testing-using-pure-unit-tests/">pure unit tests</a>, which are run on a regular JVM, whereas others are run with the custom runner on an emulator.  It&#8217;s nice for all the results to be collected together!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alittlemadness.com/2010/07/14/android-testing-xml-reports-for-continuous-integration/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Android Testing: Using Pure Unit Tests</title>
		<link>http://www.alittlemadness.com/2010/07/06/android-testing-using-pure-unit-tests/</link>
		<comments>http://www.alittlemadness.com/2010/07/06/android-testing-using-pure-unit-tests/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 08:06:01 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.alittlemadness.com/?p=667</guid>
		<description><![CDATA[Introduction
The Android SDK comes with support for testing, allowing tests to be run on an Android device (or emulator) via instrumentation.  This is useful for functional tests that require a realistic environment, but for the majority of tests it is overkill.  The instrumentation and emulation layers add complexity to the process, making tests [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>The Android SDK comes with support for <a href="http://developer.android.com/guide/topics/testing/testing_android.html">testing</a>, allowing tests to be run on an Android device (or emulator) via instrumentation.  This is useful for functional tests that require a realistic environment, but for the majority of tests it is overkill.  The instrumentation and emulation layers add complexity to the process, making tests much slower to run and harder to debug.</p>
<p>The good news is that there is no need to run most of your tests via instrumentation.  Because Android applications consist of regular Java code, it is possible to isolate much of the implementation from the Android environment.  In fact, if you&#8217;ve separated concerns in your application already, it&#8217;s likely that large parts of it are already independent of the Android APIs.  Those sections of your code can be tested on a regular JVM, using the rich ecosystem of tools available for unit testing.</p>
<h3>Unit Testing Requirements</h3>
<p>To put this idea into practice, I set out the following requirements for unit testing my Android application:</p>
<ol>
<li>The unit tests should run on a regular JVM, with no dependency on the Android APIs or tools.</li>
<li>It should be possible to run the tests within Eclipse.</li>
<li>It should be possible to run tests using Ant.</li>
<li>Running tests via Ant should produce reports suitable for use with a Continuous Integration server.</li>
</ol>
<p>These requirements allow the tests to be run quickly within the development environment, and on every commit on a build server.</p>
<h3>Adding a Unit Testing Project</h3>
<p>In keeping with my existing <a href="/setting-up-an-android-project-build/">Android project setup</a>, I decided to use an additional  project specifically for unit testing.  To recap, in the original setup I had two projects:</p>
<ol>
<li>The main project: containing the application itself.</li>
<li>The test project: containing an Android test project for instrumentation testing, in a test/ subdirectory of the root.</li>
</ol>
<p>Both projects had Ant build files and Eclipse projects.  Similar to the use of a test/ subdirectory for instrumentation tests, I added my new unit test project in a unit/ subdirectory of the root.  As with the other projects, the source code for the unit tests lives in a src/ subdirectory, giving the following overall layout:</p>
<pre class="brush: plain;">my-app/
    src/        - main application source
    test/
        src/    - functional tests
    unit/
        src/    - unit tests</pre>
<p>Creating the Eclipse project for unit testing was trivial: I just added a new Java Project named <b>my-app-unit</b>.  I then edited the build path of this project to depend on my main <b>my-app</b> project, so that I could build against the code under test.</p>
<h3>Testing Libraries</h3>
<p>The main tool required for this setup is a unit testing framework.  I decided to go with <a href="http://junit.org/">JUnit 4</a> as it is well supported in Eclipse, Ant and CI servers.  (JUnit is also used by the instrumentation testing support in the Android SDK.)  In addition, for mocking I am a fan of <a href="http://mockito.org/">Mockito</a>.  Note, though, that the beauty of using pure Java tests is you can use any of the myriad of mocking (and other) libraries out there.</p>
<p>For consistency with the existing projects, I added the JUnit and Mockito jars to a libs/ subdirectory of the unit project.  I then added those jars to the build path of my Eclipse project, and I was ready to implement some tests!</p>
<h3>A Trivial Test</h3>
<p>To make sure the setup works, you can try adding a trivial JUnit 4 test case:</p>
<pre class="brush: java;">package com.zutubi.android.myapp;

import static org.junit.Assert.*;

import org.junit.Test;

public class MyAppTest
{
    @Test
    public void testWorld()
    {
        assertEquals(2, 1 + 1);
    }
}</pre>
<p>If all is well you should be able to run this in Eclipse as a JUnit test case.  Once you have this sanity test passing, you can proceed to some Real Tests.</p>
<h3>Adding an Ant Build</h3>
<p>Setting up an Ant build took a little more effort than for the original projects, as their build files import Android rules from the SDK.  For the unit tests, I wrote a simple build file from scratch, trying to keep within the conventions established by the Android rules:</p>
<pre class="brush: xml;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project name=&quot;my-app-unit&quot; default=&quot;test&quot;&gt;
    &lt;property name=&quot;source.dir&quot; value=&quot;src&quot;/&gt;
    &lt;property name=&quot;libs.dir&quot; value=&quot;libs&quot;/&gt;

    &lt;property name=&quot;out.dir&quot; value=&quot;build&quot;/&gt;
    &lt;property name=&quot;classes.dir&quot; value=&quot;${out.dir}/classes&quot;/&gt;
    &lt;property name=&quot;reports.dir&quot; value=&quot;${out.dir}/reports&quot;/&gt;
    &lt;property name=&quot;tested.dir&quot; value=&quot;..&quot;/&gt;
    &lt;property name=&quot;tested.classes.dir&quot; value=&quot;${tested.dir}/build/classes&quot;/&gt;
    &lt;property name=&quot;tested.libs.dir&quot; value=&quot;${tested.dir}/libs&quot;/&gt;

    &lt;path id=&quot;compile.classpath&quot;&gt;
        &lt;fileset dir=&quot;${libs.dir}&quot; includes=&quot;*.jar&quot;/&gt;
        &lt;fileset dir=&quot;${tested.libs.dir}&quot; includes=&quot;*.jar&quot;/&gt;
        &lt;pathelement location=&quot;${tested.classes.dir}&quot;/&gt;
    &lt;/path&gt;

    &lt;path id=&quot;run.classpath&quot;&gt;
        &lt;path refid=&quot;compile.classpath&quot;/&gt;
        &lt;pathelement location=&quot;${classes.dir}&quot;/&gt;
    &lt;/path&gt;

    &lt;target name=&quot;clean&quot;&gt;
        &lt;delete dir=&quot;${out.dir}&quot;/&gt;
    &lt;/target&gt;

    &lt;target name=&quot;-init&quot;&gt;
    	&lt;mkdir dir=&quot;${out.dir}&quot;/&gt;
    	&lt;mkdir dir=&quot;${classes.dir}&quot;/&gt;
    	&lt;mkdir dir=&quot;${reports.dir}&quot;/&gt;
    &lt;/target&gt;

    &lt;target name=&quot;-compile-tested&quot;&gt;
        &lt;subant target=&quot;compile&quot; buildpath=&quot;${tested.dir}&quot;/&gt;
    &lt;/target&gt;

    &lt;target name=&quot;compile&quot; depends=&quot;-init,-compile-tested&quot;&gt;
        &lt;javac target=&quot;1.5&quot; debug=&quot;true&quot; destdir=&quot;${classes.dir}&quot;&gt;
            &lt;src path=&quot;${source.dir}&quot;/&gt;
            &lt;classpath refid=&quot;compile.classpath&quot;/&gt;
        &lt;/javac&gt;
    &lt;/target&gt;

    &lt;target name=&quot;run-tests&quot; depends=&quot;compile&quot;&gt;
        &lt;junit printsummary=&quot;yes&quot; failureproperty=&quot;test.failure&quot;&gt;
            &lt;classpath refid=&quot;run.classpath&quot;/&gt;

            &lt;formatter type=&quot;xml&quot;/&gt;

            &lt;batchtest todir=&quot;${reports.dir}&quot;&gt;
                &lt;fileset dir=&quot;${source.dir}&quot; includes=&quot;**/*Test.java&quot;/&gt;
            &lt;/batchtest&gt;
        &lt;/junit&gt;

        &lt;fail message=&quot;One or more test cases failed&quot; if=&quot;test.failure&quot;/&gt;
    &lt;/target&gt;
&lt;/project&gt;</pre>
<p>The <b>run-tests</b> target in this build file compiles all of the unit test code against the libraries in the unit test project, plus the classes and libraries from the project under test.  It then runs all JUnit tests in classes that have names ending with <b>Test</b>, printing summarised results and producing full XML reports in build/reports/.  These XML reports are ideal for integrating your results with a CI server (<a href="http://zutubi.com/products/pulse/">Pulse</a> in my case, of course!).</p>
<h3>Wrap Up</h3>
<p>The Android SDK support for testing is useful for functional tests, but too slow and cumbersome for rapid-feedback unit testing.  However, there is nothing to stop you from isolating the pure Java parts of your application and testing them separately.  In fact this is one of those rare win-wins: by clean design of your code you also get access to all the speed and tool support of testing on a regular JVM!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alittlemadness.com/2010/07/06/android-testing-using-pure-unit-tests/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Android Ant Builds: Targeting a Specific Device</title>
		<link>http://www.alittlemadness.com/2010/06/15/android-ant-builds-targeting-a-specific-device/</link>
		<comments>http://www.alittlemadness.com/2010/06/15/android-ant-builds-targeting-a-specific-device/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 06:09:57 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Build]]></category>

		<guid isPermaLink="false">http://www.alittlemadness.com/?p=647</guid>
		<description><![CDATA[While developing for Android, I often have more than one device available.  For example, I might have an actual G1 hooked up via USB, and an emulator instance running.  In this case, when installing and running development versions of my Android applications, I need to specify which device to target.  If I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>While developing for Android, I often have more than one device available.  For example, I might have an actual G1 hooked up via USB, and an emulator instance running.  In this case, when installing and running development versions of my Android applications, I need to specify which device to target.  If I&#8217;m working directly with <a href="http://developer.android.com/guide/developing/tools/adb.html">adb</a>, there are flags for just this purpose:</p>
<pre class="brush: plain;">jsankey@caligula:~$ adb -?
Android Debug Bridge version 1.0.26

 -d                            - directs command to the only connected USB device
                                 returns an error if more than one USB device is present.
 -e                            - directs command to the only running emulator.
                                 returns an error if more than one emulator is running.
 -s &lt;serial number&gt;            - directs command to the USB device or emulator with
                                 the given serial number. Overrides ANDROID_SERIAL
                                 environment variable.
...
</pre>
<p>I prefer to use the general -s flag, as this works no matter how many devices I have connected.  This does require a serial number, but they are easily listed:</p>
<pre class="brush: plain;">jsankey@caligula:~$ adb devices
List of devices attached
HT845KV55555	device
emulator-5554	device
</pre>
<p>Normally, however, I&#8217;m not running adb directly, but indirectly via an Ant build.  If I try, for example, to run the install target with multiple devices attached, adb is not happy:</p>
<pre class="brush: plain;">jsankey@caligula:~/work/my-app$ ant install
Buildfile: build.xml
    [setup] Android SDK Tools Revision 6
    [setup] Project Target: Android 2.2

...

install:
     [echo] Installing /home/jsankey/work/my-app/build/MyAppActivity-debug.apk onto default emulator or device...
     [exec] error: more than one device and emulator

BUILD FAILED
/usr/local/java/android/platforms/android-8/ant/ant_rules_r2.xml:362: The following error occurred while executing this line:
/usr/local/java/android/platforms/android-8/ant/ant_rules_r2.xml:191: exec returned: 1

Total time: 1 second</pre>
<p>The Ant build cannot guess which device to use by default, so it errors out.  By digging into the Android Ant rules file, I found that the Ant builds support a property named <b>adb.device.arg</b>, which allows you to pass flags through to adb.  For example, I can instruct the Ant build to install the application on the emulator as follows:</p>
<pre class="brush: plain;">jsankey@caligula:~/work/my-app$ ant -Dadb.device.arg=&quot;-s emulator-5554&quot; install
Buildfile: build.xml
    [setup] Android SDK Tools Revision 6
    [setup] Project Target: Android 2.2

...

install:
     [echo] Installing /home/jsankey/work/my-app/build/MyAppActivity-debug.apk onto default emulator or device...
     [exec] 266 KB/s (14446 bytes in 0.052s)
     [exec] 	pkg: /data/local/tmp/MyAppActivity-debug.apk
     [exec] Success

BUILD SUCCESSFUL
Total time: 6 seconds</pre>
<p>There is, however, one sticking point.  To run a test application via Ant, you can use the run-tests target.  As of the latest SDK release, however, the run-tests target does <b>not</b> respect the adb.device.arg property.  When I discovered this a couple of weeks ago, I <a href="http://code.google.com/p/android/issues/detail?id=8693">raised an issue</a> about it, and it was promptly fixed.  Until the fix is released, though, a workaround is needed.</p>
<p>Luckily, adb supports another way to specify the device: via the <b>ANDROID_SERIAL</b> environment variable.  This variable takes the same serial values as the -s flag, and being part of the environment is independent of how you end up running adb.  To repeat my previous example, I just need to set the variable to the serial for my emulator:</p>
<pre class="brush: plain;">jsankey@caligula:~/work/my-app$ export ANDROID_SERIAL=emulator-5554
jsankey@caligula:~/work/my-app$ ant install
Buildfile: build.xml
    [setup] Android SDK Tools Revision 6
    [setup] Project Target: Android 2.2

...

install:
     [echo] Installing /home/jsankey/work/my-app/build/MyAppActivity-debug.apk onto default emulator or device...
     [exec] 277 KB/s (14446 bytes in 0.050s)
     [exec] 	pkg: /data/local/tmp/MyAppActivity-debug.apk
     [exec] Success

BUILD SUCCESSFUL
Total time: 4 seconds</pre>
<p>Presuming you have control of the environment in which adb is run, the ANDROID_SERIAL variable is probably your best bet for targeting a specific device.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alittlemadness.com/2010/06/15/android-ant-builds-targeting-a-specific-device/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding the Android Build Process</title>
		<link>http://www.alittlemadness.com/2010/06/07/understanding-the-android-build-process/</link>
		<comments>http://www.alittlemadness.com/2010/06/07/understanding-the-android-build-process/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 04:37:54 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.alittlemadness.com/?p=618</guid>
		<description><![CDATA[Introduction
In my previous post, I ran through how I set up a build for an Android project.  The build was based around the Ant and Eclipse support provided in the Android SDK. This time around, I&#8217;ll dig into what actually happens under the hood when you run an Android build.  This helped me [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>In my <a href="/2010/05/31/setting-up-an-android-project-build/">previous post</a>, I ran through how I set up a build for an Android project.  The build was based around the Ant and Eclipse support provided in the <a href="http://developer.android.com/sdk/index.html">Android SDK</a>. This time around, I&#8217;ll dig into what actually happens under the hood when you run an Android build.  This helped me to understand how everything fits together, which is key for diagnosing problems or making future changes.</p>
<h3>Overview of the Build Process</h3>
<p>The easiest way to get a handle on the build process as a whole is to trace the inputs and outputs at each stage, which I have drawn up in the graph below:</p>
<p><a href="http://www.alittlemadness.com/wp-content/uploads/android-build-2.png"><img src="http://www.alittlemadness.com/wp-content/uploads/android-build-2.png" alt="" title="android-build-2" width="459" height="895" class="aligncenter size-full wp-image-624" style="border: solid 1px #aaa; padding: 6px"/></a></p>
<p>Briefly, your source and resources are compiled, converted to run on the Android VM, and then packaged up in an <b>apk</b> file (a zip-compatible format).  In the following sections I&#8217;ll explain each step in a little more detail.  Note that throughout the explanations I will refer to the default input and output locations (e.g. <b>src/</b> for Java source, and <b>bin/</b> for binary output)  &#8212; if you customise these paths then adjust as necessary.</p>
<h3>Resource Pre-compilation</h3>
<p>The first step in the build process involves generation of Java source files from your Android resources.  The resources, stored in the <b>res</b> subdirectory, include such things as icons, layouts and strings.  These are compiled using the <b>aapt</b> tool into a file named <b>R.java</b>, stored in the <b>gen/</b> subdirectory.  If you take a look at the generated file, you will see that it defines a bunch of constants:</p>
<pre class="brush: java;">/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.zutubi.android.myapp;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}</pre>
<p>The constants are used to refer to your resources, which are stored in the package file separately in a later step.</p>
<h3>Service Interface Pre-compilation</h3>
<p>The second build step also involves generation of Java source.  If your project uses any <a href="http://developer.android.com/guide/developing/tools/aidl.html">service interfaces</a>, you need to include the service interface definition files (which have an <b>.aidl</b> extension) in your project.  These files superficially resemble normal Java interfaces:</p>
<pre class="brush: plain;">package com.zutubi.android.myapp;

interface ISimpleService
{
    String echo(in String s);
}</pre>
<p>The <b>aidl</b> tool is used to generate actual Java interfaces for these services.  The Java source files will have the same name as the input files (with the <b>.aidl</b> extension replaced by <b>.java</b>) and are created in the <b>gen/</b> subdirectory.  These generated sources serve as a basis for you to implement or call the service interfaces in your own code.</p>
<h3>Java Compilation</h3>
<p>After the two pre-compilation steps, your project&#8217;s Java code is complete and ready to be compiled itself.  This step is a standard Java compilation from <b>.java</b> source files (both hand-crafted and generated) to <b>.class</b> bytecode files.  The binary bytecode files are stored in the <b>bin/classes</b> subdirectory.</p>
<p>One thing to be aware of is the <em>classpath</em> used to compile your source.  This includes:</p>
<ul>
<li>The <b>android.jar</b> file for your target Android platform.  This jar includes class and method stubs for all of the Android APIs.</li>
<li>External library jars you have added to your project (all <b>.jar</b> files in the <b>libs/</b> subdirectory).</li>
<li>For test projects only: the class files and external libraries for the <em>tested</em> project.</li>
</ul>
<h3>Bytecode Translation</h3>
<p>After compilation, you have standard Java bytecode, which would run on a standard Java VM.  However, Android uses its own <a href="http://en.wikipedia.org/wiki/Dalvik_(software)">Dalvik VM</a>, which requires a different bytecode format.  Thus, after compilation, the <b>dx</b> tool is used to translate your class files into a Dalvik executable or <b>.dex</b> file.  This includes the class files stored in any external library jars you have added to your project.  All classes are package up in a single output file, named <b>classes.dex</b>, which is produced in the <b>bin/</b> subdirectory.</p>
<h3>Resource Packaging</h3>
<p>Next, the resources are compiled into a partial Android package file.  This is done by the same <b>aapt</b> tool that generates Java source corresponding to the resources.  The resource package is created, named after your application with an <b>ap_</b> suffix in the <b>bin</b> directory.  You can use unzip to take a peek inside the package:</p>
<pre class="brush: plain;"> jsankey@caligula:~/work/my-app/build$ unzip -t MyApp.ap_
Archive:  MyApp.ap_
    testing: res/layout/main.xml      OK
    testing: AndroidManifest.xml      OK
    testing: resources.arsc           OK
    testing: res/drawable-hdpi/icon.png   OK
    testing: res/drawable-ldpi/icon.png   OK
    testing: res/drawable-mdpi/icon.png   OK
No errors detected in compressed data of MyApp.ap_.</pre>
<p>Note that although icon and layout files are included at their original location, they have been processed during packaging (presumably for more efficient storage and/or processing).  The icons appear to be optimised but still valid images, whereas layout XML files are converted to a binary format. Strings are compiled into the binary <b>resources.arsc</b> file.</p>
<h3>Debug Packaging and Signing</h3>
<p>Now all of the components required for the final Android package are ready to be bundled up into an <b>apk</b> file named after your application.  In the default debug mode, this build step also includes signing of the package with a debug key.  Note that for release, signing is a separate step that requires access to your own key (and may prompt for a password).  Android packages are assembled with the <b>apkbuidler</b> tool, which takes input from several sources:</p>
<ul>
<li>The Dalvik executable file <b>bin/classes.dex</b>.</li>
<li>All non-Java resources from your source directory (<b>src/</b>).</li>
<li>All non-Java resources from your external libraries (found by searching all <b>.jar</b> files in the <b>libs/</b> subdirectory).</li>
<li>Any native code shared-libraries included by your project.</li>
<li>The resource package built in the previous step.</li>
</ul>
<p>The produced package will be placed in the <b>bin/</b> subdirectory, named something like <b>MyApp-debug-unaligned.apk</b>.</p>
<h3>Alignment</h3>
<p>As a final optimisation step, the package file is aligned using the <b>zipalign</b> tool.  This step ensures that resources in the package file are aligned on 4-byte word boundaries.  This allows the Dalvik VM to memory-map those parts of the file for more efficient access.  You can read more about alignment on the <a href="http://android-developers.blogspot.com/2009/09/zipalign-easy-optimization.html">Android Developers Blog</a>.  This step takes the <b>-unaligned</b> package as input, and produces an output something like <b>bin/MyApp-debug.apk</b>.  This is the final, signed, aligned Android package &#8212; ready to be installed on an Android device!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alittlemadness.com/2010/06/07/understanding-the-android-build-process/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting Up An Android Project Build</title>
		<link>http://www.alittlemadness.com/2010/05/31/setting-up-an-android-project-build/</link>
		<comments>http://www.alittlemadness.com/2010/05/31/setting-up-an-android-project-build/#comments</comments>
		<pubDate>Mon, 31 May 2010 02:28:11 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.alittlemadness.com/?p=523</guid>
		<description><![CDATA[As the owner of a G1 I&#8217;ve played around at several times in the past with simple Android application development.  The SDK tools and introductory documentation provided by Google make it easy to get started.  Before embarking on a more serious project, however, I decided to figure out how to set up projects [...]]]></description>
			<content:encoded><![CDATA[<p>As the owner of a <a href="http://www.t-mobileg1.com/">G1</a> I&#8217;ve played around at several times in the past with simple Android application development.  The SDK tools and <a href="http://developer.android.com/index.html">introductory documentation</a> provided by Google make it easy to get started.  Before embarking on a more serious project, however, I decided to figure out how to set up projects in a systematic way that allows for both development and reliable scripted builds (e.g. for continuous integration).  Creating a project layout and build that works takes a few steps and tweaks, not all of which are covered in the documentation I found, so I thought I&#8217;d walk through my approach to it for those that are interested.</p>
<h3> Goals</h3>
<p>My goals for this project setup were as follows:</p>
<ul>
<li>Support for development in <a href="http://www.eclipse.org/">Eclipse</a> using the <a href="http://developer.android.com/guide/developing/eclipse-adt.html">ADT</a>.  Although Eclipse is not my first choice of IDE, it is decent enough and compelling when combined with the ADT tooling.</li>
<li>Support for building from the command-line, with no dependency on an IDE.</li>
<li>The ability to run tests on a device (or emulator) using the SDK <a href="http://developer.android.com/guide/topics/testing/testing_android.html">testing and instrumentation</a> support.</li>
<li>Containment of all components within a single directory which can be easily versioned.</li>
</ul>
<p>This all seems like it should be simple: the Android SDK has support for Eclipse, Ant builds, and testing.  However, putting it all together can take some work, because not all the pieces play together as nicely as you might hope.  First of all, although it is easy to create either an Eclipse project or an Ant one (and both cases are well documented), I would like both.  I experimented with two methods: creating an Eclipse project either before or after setting up the Ant build.  In my experience adding an Eclipse project to an existing Ant build proved more troublesome, and more difficult to debug if there was an issue.  So I recommend starting by setting up your projects (application and test) in Eclipse first.</p>
<h3>Setting Up the Eclipse Projects</h3>
<p>Select <strong>File &gt; New &gt; Project</strong>, and choose <strong>Android Project</strong> in the dialog:</p>
<p><a href="http://www.alittlemadness.com/wp-content/uploads/new-project.png"><img src="http://www.alittlemadness.com/wp-content/uploads/new-project.png" alt="" title="Choose Project Wizard" width="400" height="326" class="aligncenter size-full wp-image-553" /></a></p>
<p>Fill in your Project, Application, Package and Activity names:</p>
<p><a href="http://www.alittlemadness.com/wp-content/uploads/app-project.png"><img src="http://www.alittlemadness.com/wp-content/uploads/app-project.png" alt="" title="Application Project" width="400" height="517" class="aligncenter size-full wp-image-557" /></a></p>
<p>Click <strong>Next</strong>, then check the box to <strong>Create a Test Project</strong>.  So that both projects live under simple, single root directory, <em>uncheck</em> the <strong>Use default location</strong> box, and specify the location as the &#8220;test&#8221; subdirectory of your main application&#8217;s directory:</p>
<p><a href="http://www.alittlemadness.com/wp-content/uploads/test-project.png"><img src="http://www.alittlemadness.com/wp-content/uploads/test-project.png" alt="" title="test-project" width="400" height="517" class="aligncenter size-full wp-image-559" /></a></p>
<p>Click <strong>Finish</strong> and the easy part is done: you should have two new projects in your workspace, with the test project nested neatly within the main one<sup>1</sup>.  If you list the contents of your application&#8217;s directory, you should see something like:</p>
<pre class="brush: plain;">jsankey@caligula:~$ ls -a1 work/my-app/
.
..
AndroidManifest.xml
assets
bin
.classpath
default.properties
gen
.project
res
.settings
src
test</pre>
<p>Likewise, the test subdirectory should contain:</p>
<pre class="brush: plain;">jsankey@caligula:~$ ls -a1 work/my-app/test
.
..
AndroidManifest.xml
assets
bin
.classpath
default.properties
gen
.project
res
.settings
src</pre>
<h3>Adding a Simple Test Case</h3>
<p>At this point, it&#8217;s worth adding a simple test case to your test project as a starting point.  This will allow you to experiment with the Eclipse setup and (forthcoming) Ant builds.  To do this, navigate to your test project and select <strong>File &gt; New &gt; Class</strong>.  To actually utilise the instrumentation support in the test project, have your test class extend <strong>android.test.ActivityInstrumentationTestCase2</strong>:</p>
<p><a href="http://www.alittlemadness.com/wp-content/uploads/test-class.png"><img src="http://www.alittlemadness.com/wp-content/uploads/test-class.png" alt="" title="test-class" width="400" height="484" class="aligncenter size-full wp-image-567" /></a></p>
<p>You&#8217;ll need to fill in the generic type parameter for this class, add a constructor, and add a simple test case:</p>
<pre class="brush: java;">package com.zutubi.android.myapp.test;

import com.zutubi.android.myapp.MyAppActivity;

import android.test.ActivityInstrumentationTestCase2;

public class MyAppActivityTest extends ActivityInstrumentationTestCase2&lt;MyAppActivity&gt; {

	public MyAppActivityTest() {
		super(&quot;com.zutubi.android.myapp&quot;, MyAppActivity.class);
	}

	public void testSanity() {
		assertEquals(2, 1 + 1);
	}
}</pre>
<p>To try it out, select <strong>Run > Run As > Android JUnit Test</strong> and choose (or start) a device.  If the universe is in working order, the test should pass!</p>
<h3>Adding Ant Builds</h3>
<p>To add standard Android Ant builds to the existing projects, I used the android command line tool from the SDK.  Firstly, I added a build to the main application using <strong>android update project</strong>:</p>
<pre class="brush: plain;">jsankey@caligula:~$ cd /home/jsankey/work/my-app
jsankey@caligula:~/work/my-app$ android update project -p .
Updated local.properties
Added file ./build.xml
It seems that there are sub-projects. If you want to update them
please use the --subprojects parameter.</pre>
<p>As the output suggests, this command adds an Ant build.xml file to your project, and a local.properties file that stores the location of the Android SDK. Notice that the tool has picked up the fact that there is a test/ subdirectory with another project in it.  However, <strong>do not</strong> be tempted to take its advice to run with the &#8211;subprojects flag: this will treat your test project as a regular project.  Instead, change into the test/ subdirectory and run <strong>android update test-project</strong>:</p>
<pre class="brush: plain;">jsankey@caligula:~/work/my-app$ cd test
jsankey@caligula:~/work/my-app/test$ android update test-project -p . -m ..
Resolved location of main project to: /home/jsankey/work/my-app
Updated default.properties
Updated local.properties
Added file ./build.xml
Updated build.properties</pre>
<p>Again, the build.xml and local.properties files are added, although this time the build file will contain test rules.  Notice that the <em>relative</em> path to the main project is passed using the -m flag.  You can see the effect of this in the created build.properties file, which sets the value of tested.project.dir.</p>
<p>At this point you can build the project and run the tests from the command line.  First ensure that you have only one device available (e.g. one emulator running), then, in the test/ subdirectory where we left off, run <strong>ant run-tests</strong>:</p>
<pre class="brush: plain;">jsankey@caligula:~/work/my-app/test$ ant run-tests
... clipped several lines of output ...
run-tests:
     [echo] Running tests ...
     [exec]
     [exec] com.zutubi.android.myapp.test.MyAppActivityTest:.
     [exec] Test results for InstrumentationTestRunner=.
     [exec] Time: 0.158
     [exec]
     [exec] OK (1 test)
     [exec]
     [exec] 

BUILD SUCCESSFUL
Total time: 10 seconds</pre>
<p>Excellent: now we have the build and test working with both Eclipse and Ant (or so it seems&#8230;).</p>
<h3>Separating the Output Directories</h3>
<p>Although on the surface our two methods of building appear to work, once you start working in this environment you will notice problems.  Most likely, you will start to see errors showing up in your Eclipse build (or the Android Console) after builds from the command line.  By default both the Eclipse and Ant builds use the same folders for generated source (gen/) and output (bin/), which causes this conflict.  The Eclipse project does not react well to changes that occur underneath it.</p>
<p>To solve this problem, we can force the two different builds to use different output locations.  The Ant build makes it easy to override both the generated source and output locations, using gen.dir and out.dir properties.  The best place to set these properties is in the build.properties file for each of the projects:</p>
<pre class="brush: plain;">out.dir=build
gen.dir=build/gen</pre>
<p>Note that you will need to create build.properties for your main project (your test project should already have one).  I chose to put the gen/ directory used by Ant under the output directory just to tidy things up a little.</p>
<p>This should be all that is required, however, thanks to a <a href="http://code.google.com/p/android/issues/detail?id=8001">bug</a> in the default Ant rules, if you customise the output directory your test project will not find the output of your main project to build against.  To fix this, you need to edit test/build.xml, and add the line:</p>
<pre class="brush: xml;">&lt;property name=&quot;extensible.classpath&quot; value=&quot;${tested.project.absolute.dir}/${out.dir}/classes&quot;/&gt;</pre>
<p>just before the closing &lt;/project&gt; tag.  This assumes your test and main projects have the same out.dir, which although slightly lazy is a simpler than loading the main project&#8217;s properties to get its out.dir (and a sane assumption in my book).</p>
<p>You can make sure everything works by doing clean builds using Ant:</p>
<pre class="brush: plain;">jsankey@caligula:~/work/my-app/test$ cd ..
jsankey@caligula:~/work/my-app$ ant clean
Buildfile: build.xml
    [setup] Android SDK Tools Revision 6
    [setup] Project Target: Android 2.2
    [setup] API level: 8
    [setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
    [setup] Importing rules file: platforms/android-8/ant/ant_rules_r2.xml

clean:
   [delete] Deleting directory /home/jsankey/work/my-app/build
   [delete] Deleting directory /home/jsankey/work/my-app/build.gen

BUILD SUCCESSFUL
Total time: 0 seconds
jsankey@caligula:~/work/my-app$ cd test
jsankey@caligula:~/work/my-app/test$ ant clean run-tests
... clipped several lines of output ...
run-tests:
     [echo] Running tests ...
     [exec]
     [exec] com.zutubi.android.myapp.test.MyAppActivityTest:.
     [exec] Test results for InstrumentationTestRunner=.
     [exec] Time: 0.147
     [exec]
     [exec] OK (1 test)
     [exec]
     [exec] 

BUILD SUCCESSFUL
Total time: 9 seconds</pre>
<p>Then switch back to Eclipse, try editing and saving the activity and test cases and ensure everything is happy.</p>
<h3>Checking It In</h3>
<p>Finally, you can check the project into your version control system.  I won&#8217;t go into the tool-specific details, just make sure you check in the correct files.  You should <strong>exclude</strong>:</p>
<ul>
<li>The bin/, build/, and gen/ directories: as these all contain build output.</li>
<li>The files local.properties and test/local.properties: which are intended to contain properties specific to your machine (e.g. the location of the Android SDK).</li>
</ul>
<p>Make sure you don&#8217;t forget to check in the hidden Eclipse files .classpath, .project and .settings.  By structuring the projects so they live under a single top-level folder, it should be easy to add them to the version control server of your choice.</p>
<h3>Wrap Up</h3>
<p>That covers the basics of setting up an Android project, with tests, for both development and automated builds.  Although some tweaking is required, this setup is still built upon the tooling provided by the Android SDK.  I hope that this will mean it is easy to take advantage of new capabilities when new SDK versions are released (which happens pretty frequently at the moment!).</p>
<p>&#8211;<br />
<sup>1</sup> For reasons unknown to me, when my projects were first created they had build errors.  A clean rebuild magically fixed the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alittlemadness.com/2010/05/31/setting-up-an-android-project-build/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Zero To Continuous Integration in Three Minutes</title>
		<link>http://www.alittlemadness.com/2010/04/12/zero-to-continuous-integration-in-three-minutes/</link>
		<comments>http://www.alittlemadness.com/2010/04/12/zero-to-continuous-integration-in-three-minutes/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 07:37:54 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Zutubi]]></category>

		<guid isPermaLink="false">http://www.alittlemadness.com/?p=487</guid>
		<description><![CDATA[A large part of our focus with Pulse revolves around saving time.  We started Pulse with the belief that it shouldn&#8217;t be so hard to set up a continuous integration server, nor should it take so much effort to maintain.  With that in mind, I&#8217;ve highlighted the main ways we achieve simplicity and [...]]]></description>
			<content:encoded><![CDATA[<p>A large part of our focus with <a href="http://zutubi.com/products/pulse/">Pulse</a> revolves around saving time.  We started Pulse with the belief that it shouldn&#8217;t be so hard to set up a continuous integration server, nor should it take so much effort to maintain.  With that in mind, I&#8217;ve highlighted the main ways we achieve simplicity and maintainability in Pulse in two new demo videos:</p>
<ul>
<li><a href="http://zutubi.com/products/pulse/videos/setup/">Getting Started With Pulse</a>: in which I start from scratch, installing Pulse, adding a new project and running a first build in under three minutes.  By watching the video, you&#8217;ll see that it is unabridged, and I did nothing but follow the simple steps laid out in front of me.</li>
<li><a href="http://zutubi.com/products/pulse/videos/templates/">Templated Configuration</a>: in which I demonstrate how Pulse&#8217;s unique templated configuration system saves you time configuring and (especially) maintaining your continuous integration server.  Templates make CI <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a>.</li>
</ul>
<p>We focus on saving time simply because it adds a lot of value to Pulse.  Our customers tell us that simplicity, maintainability and dedicated support are the main reasons they chose <a href="http://zutubi.com/products/pulse/">Pulse</a> to manage their builds.  <a href="http://zutubi.com/products/pulse/downloads/">Give it a go</a> yourself: you can get started in no time <img src='http://www.alittlemadness.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alittlemadness.com/2010/04/12/zero-to-continuous-integration-in-three-minutes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Article: Optimise Your Acceptance Tests</title>
		<link>http://www.alittlemadness.com/2010/03/09/article-optimise-your-acceptance-tests/</link>
		<comments>http://www.alittlemadness.com/2010/03/09/article-optimise-your-acceptance-tests/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 04:43:02 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.alittlemadness.com/?p=483</guid>
		<description><![CDATA[In a similar vein to my previous post, I&#8217;ve revived some old posts about acceptance testing &#8212; and made significant additions. The end result is a new article:
Many developers have a love-hate relationship with automated acceptance tests. One major sticking point is the time acceptance tests take to execute, which can easily cause a blow [...]]]></description>
			<content:encoded><![CDATA[<p>In a similar vein to my <a href="/2010/02/22/article-testing-is-a-developers-perspective/">previous post</a>, I&#8217;ve revived some old posts about acceptance testing &#8212; and made significant additions. The end result is a new article:</p>
<blockquote><p>Many developers have a love-hate relationship with automated acceptance tests. One major sticking point is the time acceptance tests take to execute, which can easily cause a blow out of project build times. In this article I&#8217;ll review 7 successful techniques we&#8217;ve put to work in our own projects to optimise our acceptance testing.</p></blockquote>
<p>You can read the full article at <a href="http://zutubi.com/products/pulse/articles/optimise-your-acceptance-tests/">zutubi.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alittlemadness.com/2010/03/09/article-optimise-your-acceptance-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pulse 2.1.11: Get More From Your Build Agents</title>
		<link>http://www.alittlemadness.com/2009/12/16/pulse-2-1-11-get-more-from-your-build-agents/</link>
		<comments>http://www.alittlemadness.com/2009/12/16/pulse-2-1-11-get-more-from-your-build-agents/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 18:17:16 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Zutubi]]></category>

		<guid isPermaLink="false">http://www.alittlemadness.com/?p=463</guid>
		<description><![CDATA[The latest Pulse 2.1 beta build, 2.1.11, has just been freshly baked.  This build includes several new features and improvements.  Prominent among them is a new &#8220;statistics&#8221; tab for agents.  This tab lists various figures such as the number of recipes the agent executes each day and how long the average recipe [...]]]></description>
			<content:encoded><![CDATA[<p>The latest <a href="http://zutubi.com/products/pulse/">Pulse</a> 2.1 beta build, 2.1.11, has just been freshly baked.  This build includes several new features and improvements.  Prominent among them is a new &#8220;statistics&#8221; tab for agents.  This tab lists various figures such as the number of recipes the agent executes each day and how long the average recipe keeps the agent busy.  Statistics are also shown for agent utilisation, including a pie chart that makes it easy to visualise:</p>
<p><a href="http://www.alittlemadness.com/wp-content/uploads/agent-utilisation-chart.png"><img src="http://www.alittlemadness.com/wp-content/uploads/agent-utilisation-chart.png" alt="agent utilisation chart" title="agent utilisation chart" width="410" height="415" class="aligncenter size-full wp-image-464" /></a></p>
<p>This allows you to see if you are getting the most out of your agent machines.  If you do notice a machine is underutilised, another new feature could help identify the cause: compatibility information for projects and agents.  Pulse matches builds to agents by considering if the resources required for the project are all available on the agent.  Now when you configure requirements, Pulse shows you which agents those requirements are compatible with.  On the flip side, when configuring an agent&#8217;s available resources, Pulse shows you which projects those resources satisfy.</p>
<p>Other highlights in this build:</p>
<ul>
<li>Optional compression of large build logs (on by default).</li>
<li>Visual indicators of which users are logged in, and last access times for all users.</li>
<li>Support for Subversion 1.6 working copies for personal builds.</li>
<li>Actions can now be performed on all descendants of a project or agent template (e.g. disable all agents with one click).</li>
<li>New options to terminate a build early if a critical stage or number of stages have already failed.</li>
<li>The system/agent info tabs now show the Pulse process environment (visible to administrators only).</li>
<li>Use of bare git repositories on the Pulse master to save disk space.</li>
</ul>
<p>Yes, we have been busy <img src='http://www.alittlemadness.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .  Get over to our website and <a href="http://zutubi.com/products/pulse/downloads/">download</a> the beta now &#8212; it&#8217;s free to try, and a free upgrade for customers with current support contracts!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alittlemadness.com/2009/12/16/pulse-2-1-11-get-more-from-your-build-agents/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
