<?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>AndroidDev Tips &#8211; Wiebe Elsinga</title>
	<atom:link href="http://wiebe-elsinga.com/blog/category/androiddev-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://wiebe-elsinga.com/blog</link>
	<description>Blog</description>
	<lastBuildDate>Thu, 09 Apr 2015 09:21:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8</generator>
	<item>
		<title>What’s new in Android Testing</title>
		<link>http://wiebe-elsinga.com/blog/whats-new-in-android-testing/</link>
		
		<dc:creator><![CDATA[W.Elsinga]]></dc:creator>
		<pubDate>Thu, 09 Apr 2015 02:20:09 +0000</pubDate>
				<category><![CDATA[AndroidDev Tips]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[espresso]]></category>
		<category><![CDATA[testing]]></category>
		<guid isPermaLink="false">http://wiebe-elsinga.com/blog/?p=1755</guid>

					<description><![CDATA[During Droidcon Italy Stephan Linzner from Google explained upcoming features in the Android Testing Support Library. Lets have a closer look at some: Test Filtering If you want to suppress a test to run on certain target Api levels, just add the @SdkSuppress annotation. @SdkSuppress&#40;minSdkVersion=15&#41; @Test public void featureWithMinSdk15&#40;&#41; &#123; &#160; ... &#125; You can also filter tests to only run on a (physical) device by adding the @RequiresDevice annotation. @RequiresDevice @Test public void SomeDeviceSpecificFeature&#40;&#41; &#123; &#160; ... &#125; ActivityTestRule Because ActivityInstrumentationTestCase2 will become deprecated you need to define a @Rule. Rules allow very flexible addition or redefinition of the behavior of each test method in a test class https://github.com/junit-team/junit/wiki/Rules So in your test add a @Rule annotation, and create an ActivityTestRule for your Activity @RunWith&#40;AndroidJUnit4.class&#41; @LargeTest public class ChangeTextBehaviorTest &#123; &#160; &#160; ... &#160; &#160; @Rule &#160; &#160; public ActivityTestRule&#60;MainActivity&#62; mActivityRule = new ActivityTestRule&#60;&#62;&#40;MainActivity.class&#41;; &#160; &#160; @Test &#160; &#160; public void changeText_sameActivity&#40;&#41; &#123; &#160; &#160; &#160; &#160; // Type text and then press the button. &#160; &#160; &#160; &#160; onView&#40;withId&#40;R.id.editTextUserInput&#41;&#41;.perform&#40;typeText&#40;STRING_TO_BE_TYPED&#41;, closeSoftKeyboard&#40;&#41;&#41;; &#160; &#160; &#160; &#160; onView&#40;withId&#40;R.id.changeTextBt&#41;&#41;.perform&#40;click&#40;&#41;&#41;; &#160; &#160; &#160; &#160; // Check that the text was changed. &#160; &#160; &#160; &#160; onView&#40;withId&#40;R.id.textToBeChanged&#41;&#41;.check&#40;matches&#40;withText&#40;STRING_TO_BE_TYPED&#41;&#41;&#41;; &#160; &#160; &#125; &#125; Now create your ActivityTestRule public class ActivityTestRule&#60;T extends Activity&#62; &#123; &#160; &#160; public T getActivity&#40;&#41; &#123;&#125; &#160; &#160; protected Intent getActivityIntent&#40;&#41; &#123;&#125; &#160; &#160; protected void beforeActivityLaunched&#40;&#41; &#123;&#125; &#160; &#160; protected void afterActivityFinished&#40;&#41; &#123;&#125; &#125; Espresso-Intents Espresso-Intents is like Mockito but for Intent, basically hermetic inter-app testing. To give you an example, lets say in your application when a user presses a &#8220;call&#8221; button, you want to know if the correct data will be send to the Intent.ACTION_CALL. So first create an IntentsTestRule and then verify that the Intent was sent using Espresso-Intents @RunWith&#40;AndroidJUnit4.class&#41; @LargeTest public class DialerActivityTest &#123; &#160; &#160; ... &#160; &#160; @Rule &#160; &#160; public IntentsTestRule&#60;DialerActivity&#62; mRule = new IntentsTestRule&#60;&#62;&#40;DialerActivity.class&#41;; &#160; &#160; @Test &#160; &#160; public void typeNumber_ValidInput_InitiatesCall&#40;&#41; &#123; &#160; &#160; &#160; &#160; onView&#40;withId&#40;R.id.edit_text_caller_number&#41;&#41;.perform&#40;typeText&#40;VALID_PHONE_NUMBER&#41;, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; closeSoftKeyboard&#40;&#41;&#41;; &#160; &#160; &#160; &#160; onView&#40;withId&#40;R.id.button_call_number&#41;&#41;.perform&#40;click&#40;&#41;&#41;; &#160; &#160; &#160; &#160; intended&#40;allOf&#40; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; hasAction&#40;is&#40;equalTo&#40;Intent.ACTION_CALL&#41;&#41;&#41;, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; hasData&#40;equalTo&#40;INTENT_DATA_PHONE_NUMBER&#41;&#41;, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; toPackage&#40;PACKAGE_ANDROID_DIALER&#41;&#41;&#41;; &#160; &#160; &#125; &#125; So now you know&#8230; All code can be found in android-testing github: ActivityTestRule Sample IntentsBasicSample General Espresso Github samples by Google Thanks Stephan Linzner for the resources. #HappyTesting]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" src="http://wiebe-elsinga.com/blog/wp-content/uploads/2015/04/DroidconIT.jpg" width="4096" height="3040" class="aligncenter size-full wp-image-1779" data-wp-pid="1779" srcset="http://wiebe-elsinga.com/blog/wp-content/uploads/2015/04/DroidconIT.jpg 4096w, http://wiebe-elsinga.com/blog/wp-content/uploads/2015/04/DroidconIT-300x223.jpg 300w, http://wiebe-elsinga.com/blog/wp-content/uploads/2015/04/DroidconIT-1024x760.jpg 1024w, http://wiebe-elsinga.com/blog/wp-content/uploads/2015/04/DroidconIT-800x594.jpg 800w" sizes="(max-width: 4096px) 100vw, 4096px" /></p>
<p>During Droidcon Italy <a href="https://plus.google.com/+StephanLinzner">Stephan Linzner</a> from Google explained upcoming features in the <a href="https://developer.android.com/tools/support-library/index.html">Android Testing Support Library</a>. Lets have a closer look at some:<br />
<span id="more-1755"></span><br />
</p>
<h3>Test Filtering</h3>
<p>If you want to suppress a test to run on certain target Api levels, just add the <code class="codecolorer bash default"><span class="bash"><span style="color: #000000; font-weight: bold;">@</span>SdkSuppress</span></code> annotation.</p>
<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@SdkSuppress<span style="color: #009900;">&#40;</span>minSdkVersion<span style="color: #339933;">=</span><span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><br />
@Test<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> featureWithMinSdk15<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; ...<br />
<span style="color: #009900;">&#125;</span></div></div>
<p>You can also filter tests to only run on a (physical) device by adding the <code class="codecolorer bash default"><span class="bash"><span style="color: #000000; font-weight: bold;">@</span>RequiresDevice</span></code> annotation.</p>
<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@RequiresDevice<br />
@Test<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> SomeDeviceSpecificFeature<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; ...<br />
<span style="color: #009900;">&#125;</span></div></div>
<p></p>
<h3>ActivityTestRule</h3>
<p>Because <code class="codecolorer bash default"><span class="bash">ActivityInstrumentationTestCase2</span></code> will become deprecated you need to define a <code class="codecolorer bash default"><span class="bash"><span style="color: #000000; font-weight: bold;">@</span>Rule.</span></code></p>
<blockquote><p>Rules allow very flexible addition or redefinition of the behavior of each test method in a test class</p></blockquote>
<div align="right" ><small>https://github.com/junit-team/junit/wiki/Rules</small></div>
<p>
So in your test add a <code class="codecolorer bash default"><span class="bash"><span style="color: #000000; font-weight: bold;">@</span>Rule</span></code> annotation, and create an <code class="codecolorer bash default"><span class="bash">ActivityTestRule</span></code> for your Activity</p>
<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@RunWith<span style="color: #009900;">&#40;</span>AndroidJUnit4.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
@LargeTest<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ChangeTextBehaviorTest <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; ...<br />
<br />
&nbsp; &nbsp; @Rule<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> ActivityTestRule<span style="color: #339933;">&lt;</span>MainActivity<span style="color: #339933;">&gt;</span> mActivityRule <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ActivityTestRule<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span>MainActivity.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Test<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> changeText_sameActivity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Type text and then press the button.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; onView<span style="color: #009900;">&#40;</span>withId<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">editTextUserInput</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">perform</span><span style="color: #009900;">&#40;</span>typeText<span style="color: #009900;">&#40;</span>STRING_TO_BE_TYPED<span style="color: #009900;">&#41;</span>, closeSoftKeyboard<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; onView<span style="color: #009900;">&#40;</span>withId<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">changeTextBt</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">perform</span><span style="color: #009900;">&#40;</span>click<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check that the text was changed.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; onView<span style="color: #009900;">&#40;</span>withId<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">textToBeChanged</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">check</span><span style="color: #009900;">&#40;</span>matches<span style="color: #009900;">&#40;</span>withText<span style="color: #009900;">&#40;</span>STRING_TO_BE_TYPED<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Now create your <code class="codecolorer bash default"><span class="bash">ActivityTestRule</span></code></p>
<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ActivityTestRule<span style="color: #339933;">&lt;</span>T <span style="color: #000000; font-weight: bold;">extends</span> Activity<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> T getActivity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> Intent getActivityIntent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> beforeActivityLaunched<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> afterActivityFinished<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p></p>
<h3>Espresso-Intents</h3>
<p>Espresso-Intents is like <a href="http://site.mockito.org/">Mockito</a> but for Intent, basically hermetic inter-app testing.<br />
To give you an example, lets say in your application when a user presses a &#8220;call&#8221; button, you want to know if the correct data will be send to the <code class="codecolorer bash default"><span class="bash">Intent.ACTION_CALL</span></code>. </p>
<p><img loading="lazy" src="http://wiebe-elsinga.com/blog/wp-content/uploads/2015/04/EspressoIntent.png" alt="EspressoIntent" width="1067" height="573" class="aligncenter size-full wp-image-1768" data-wp-pid="1768" srcset="http://wiebe-elsinga.com/blog/wp-content/uploads/2015/04/EspressoIntent.png 1067w, http://wiebe-elsinga.com/blog/wp-content/uploads/2015/04/EspressoIntent-300x161.png 300w, http://wiebe-elsinga.com/blog/wp-content/uploads/2015/04/EspressoIntent-1024x550.png 1024w, http://wiebe-elsinga.com/blog/wp-content/uploads/2015/04/EspressoIntent-800x430.png 800w" sizes="(max-width: 1067px) 100vw, 1067px" /></p>
<p>So first create an <code class="codecolorer bash default"><span class="bash">IntentsTestRule</span></code> and then verify that the Intent was sent using Espresso-Intents</p>
<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@RunWith<span style="color: #009900;">&#40;</span>AndroidJUnit4.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
@LargeTest<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DialerActivityTest <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; ...<br />
&nbsp; &nbsp; @Rule<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> IntentsTestRule<span style="color: #339933;">&lt;</span>DialerActivity<span style="color: #339933;">&gt;</span> mRule <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> IntentsTestRule<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span>DialerActivity.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Test<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> typeNumber_ValidInput_InitiatesCall<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; onView<span style="color: #009900;">&#40;</span>withId<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">edit_text_caller_number</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">perform</span><span style="color: #009900;">&#40;</span>typeText<span style="color: #009900;">&#40;</span>VALID_PHONE_NUMBER<span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closeSoftKeyboard<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; onView<span style="color: #009900;">&#40;</span>withId<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">button_call_number</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">perform</span><span style="color: #009900;">&#40;</span>click<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; intended<span style="color: #009900;">&#40;</span>allOf<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hasAction<span style="color: #009900;">&#40;</span>is<span style="color: #009900;">&#40;</span>equalTo<span style="color: #009900;">&#40;</span>Intent.<span style="color: #006633;">ACTION_CALL</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hasData<span style="color: #009900;">&#40;</span>equalTo<span style="color: #009900;">&#40;</span>INTENT_DATA_PHONE_NUMBER<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toPackage<span style="color: #009900;">&#40;</span>PACKAGE_ANDROID_DIALER<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p></br><br />
So now you know&#8230;<br />
<br />
All code can be found in <a href="https://github.com/googlesamples/android-testing">android-testing github</a>:</p>
<ul>
<li><a href="https://github.com/googlesamples/android-testing/tree/master/espresso/BasicSample">ActivityTestRule Sample</a></li>
<li><a href="https://github.com/googlesamples/android-testing/tree/master/espresso/IntentsBasicSample">IntentsBasicSample</a></li>
<li><a href="">General Espresso Github samples by Google</a></li>
</ul>
<p>
Thanks <a href="https://plus.google.com/+StephanLinzner">Stephan Linzner</a> for the resources. #HappyTesting</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>The Hitchhiker&#8217;s guide to Android Testing, part 2: Espresso</title>
		<link>http://wiebe-elsinga.com/blog/the-hitchhikers-guide-to-android-testing-part-2-espresso/</link>
		
		<dc:creator><![CDATA[W.Elsinga]]></dc:creator>
		<pubDate>Fri, 03 Apr 2015 02:04:02 +0000</pubDate>
				<category><![CDATA[AndroidDev Tips]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[AndroidDev]]></category>
		<category><![CDATA[espresso]]></category>
		<category><![CDATA[testing]]></category>
		<guid isPermaLink="false">http://wiebe-elsinga.com/blog/?p=1711</guid>

					<description><![CDATA[As mentioned in the first article Ali Derbane and me wrote about Android Functional Testing, there are a lot of frameworks you can use. In this second part of the journey I will be explaining the functional testing framework called Espresso. So now you know a bit more about Espresso. If you want to know more, you may want to visit: Espresso website Github repo corresponding to this article General Espresso Github samples by Google Updated (08-04) When running the tests with gradle you can just use gradle connectedAndroidTest]]></description>
										<content:encoded><![CDATA[<p>As mentioned in the <a href="http://www.technotalkative.com/part-10-the-hitchhikers-guide-to-android-testing/">first article</a> <a href="https://plus.google.com/+AliDerbane">Ali Derbane</a> and me wrote about Android Functional Testing, there are a lot of frameworks you can use. In this second part of the journey I will be explaining the functional testing framework called <a href="https://code.google.com/p/android-test-kit/">Espresso</a>.<br />
<span id="more-1711"></span><br />
<img src="http://i.giphy.com/VtFd68Pr19fYk.gif" width=100%" /></p>
<h3>Introduction</h3>
<p>Introduced at the GTAC in 2013, Espresso is designed to be used in environments where the developers write their own tests, and makes it possible to write concise, beautiful, and reliable Android UI tests quickly.<br />
Espresso has several general components:</p>
<ul>
<li>The <code class="codecolorer bash default"><span class="bash">Espresso</span></code> class offers the <code class="codecolorer bash default"><span class="bash">onView</span></code> and <code class="codecolorer bash default"><span class="bash">onData</span></code> methods which, alone, can be used for a good numbers of possible tests on a given interface.</li>
<li><code class="codecolorer bash default"><span class="bash">ViewMatchers</span></code> contains a collection of objects that implements the interface <code class="codecolorer bash default"><span class="bash">Matcher <span style="color: #000000; font-weight: bold;">&lt;</span>? super View<span style="color: #000000; font-weight: bold;">&gt;</span></span></code>. Using this Class you can collect and check View elements. For example, getting a View element (Button) with text &#8220;7&#8221;.</li>
<li><code class="codecolorer bash default"><span class="bash">ViewActions</span></code> contains a collection of <code class="codecolorer bash default"><span class="bash">viewAction</span></code> objects to perform actions on a view. These actions are passed to the method <code class="codecolorer bash default"><span class="bash">ViewInteraction.perform</span></code> and may contain multiple actions. For example, clicking on a View element (Button).</li>
<li><code class="codecolorer bash default"><span class="bash">ViewAssertions</span></code> contains a collection of <code class="codecolorer bash default"><span class="bash">ViewAssertion</span></code> to conduct checks on views. </li>
</ul>
<p>
To illustrate these components a test can look like this:</p>
<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&nbsp; Espresso.<span style="color: #006633;">onView</span><span style="color: #009900;">&#40;</span>ViewMatchers.<span style="color: #006633;">withText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;7&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">perform</span><span style="color: #009900;">&#40;</span>ViewActions.<span style="color: #006633;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Espresso.<span style="color: #006633;">onView</span><span style="color: #009900;">&#40;</span>withId<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">check</span><span style="color: #009900;">&#40;</span>ViewAssertions.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span>ViewMatchers.<span style="color: #006633;">withText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;42&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>And the good news, as of last year Google has introduced a <a href="https://developer.android.com/tools/support-library/index.html">Testing Support Library</a> containing Espresso. So lets start by implementing Espresso.</p>
<div style="background: lightgray; padding: 12pt;">To illustrate, we are going to write some tests that tests agains a <a href="https://github.com/welsinga/sample_espresso/app">Android calculator application</a>. The common test scenario we will be implementing is testing if <em>‘6’ x ‘7’ equals ‘42’</em>.</div>
<p>&nbsp;&nbsp;</p>
<h3>Define the test runner</h3>
<p>To use Espresso we first need to define who is running the tests. Espresso uses a new runner named <code class="codecolorer bash default"><span class="bash">AndroidJUnitRunner</span></code>. This runner, based on <code class="codecolorer bash default"><span class="bash">InstrumentationTestRunner</span></code> and <code class="codecolorer bash default"><span class="bash">GoogleInstrumentationTestRunner</span></code>, runs <em>JUnit3</em> and <em>JUnit4</em> tests against your Android application.</p>
<p>First add the dependencies to your <code class="codecolorer bash blackboard"><span class="bash">build.gradle</span></code>, assuming you have installed the <a href="https://developer.android.com/tools/support-library/index.html">Testing Support Library</a>.</p>
<div class="codecolorer-container groovy blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="groovy codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">dependencies <span style="color: #66cc66;">&#123;</span><br />
&nbsp; androidTestCompile <span style="color: #ff0000;">'com.android.support.test:testing-support-lib:0.1'</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Then add the runner in your build.gradle<code class="codecolorer groovy default"><span class="groovy">android.<span style="color: #006600;">defaultConfig</span></span></code> configuration:</p>
<div class="codecolorer-container groovy blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="groovy codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">defaultConfig <span style="color: #66cc66;">&#123;</span><br />
&nbsp; ...<br />
&nbsp; <span style="color: #006600;">testInstrumentationRunner</span> <span style="color: #ff0000;">&quot;android.support.test.runner.AndroidJUnitRunner&quot;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>&nbsp;&nbsp;</p>
<h3>Writing the test</h3>
<p>As you may know test classes must be in <code class="codecolorer bash default"><span class="bash">src\androidTest\com.example.package.tests</span></code>, com.example.package being the package specified in the package attribute of the manifest element in the <code class="codecolorer bash default"><span class="bash">AndroidManifest</span></code> file.&nbsp;<br />
Also each test class must extend the abstract class <code class="codecolorer bash default"><span class="bash">ActivityInstrumentationTestCase2</span></code> and supply the Test Activity as generic type that will be used by default for testing.<br />
It must also be passed to the superclass via the <code class="codecolorer bash default"><span class="bash">super<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></span></code>. To make the Test Activity being called by the test framework, simply define a setup which calls the synchronous method <code class="codecolorer bash default"><span class="bash">getActivity<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>.</span></code></p>
<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FunctionalInstrumentationTest <span style="color: #000000; font-weight: bold;">extends</span> ActivityInstrumentationTestCase2<span style="color: #339933;">&lt;</span>ActivityToTest<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> FunctionalInstrumentationTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>ActivityToTest.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+exception"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">setUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; getActivity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>As mentioned we want to check if <em>‘6’ x ‘7’ equals ‘42’</em>.</p>
<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testAnswer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; onView<span style="color: #009900;">&#40;</span>withText<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;7&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">perform</span><span style="color: #009900;">&#40;</span>click<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; onView<span style="color: #009900;">&#40;</span>withText<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;×&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">perform</span><span style="color: #009900;">&#40;</span>click<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; onView<span style="color: #009900;">&#40;</span>withText<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;6&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">perform</span><span style="color: #009900;">&#40;</span>click<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; onView<span style="color: #009900;">&#40;</span>withText<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">perform</span><span style="color: #009900;">&#40;</span>click<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; onView<span style="color: #009900;">&#40;</span>withId<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">resText</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">check</span><span style="color: #009900;">&#40;</span>matches<span style="color: #009900;">&#40;</span>withText<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;42&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>You may have noticed, this example is using static imports. This is solely done to make the code more readable.</p>
<p>Other actions you want to use are:</p>
<ul>
<li><code class="codecolorer java default"><span class="java">pressBack<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></span></code> to simulate the use of the &#8220;back&#8221; button,</li>
<li><code class="codecolorer java default"><span class="java">isDisplayed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></span></code> to check if an element is being shown and </li>
<li><code class="codecolorer java default"><span class="java">scrollTo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></span></code> to scroll to an element.</li>
</ul>
<p>&nbsp;&nbsp;</p>
<h3>Running the test</h3>
<p>Now lets do the fun part, lets run the test. This can be done from the command line with he command line with <code class="codecolorer bash blackboard"><span class="bash">gradle connectedAndroidTest</span></code> or using Android Studio by:</p>
<ol>
<li><em>Open Run menu | Edit Configurations</em></li>
<li><em>Add a new Android Tests configuration</em></li>
<li><em>Choose the module you are testing</em></li>
<li><em>Define our test runner: <code class="codecolorer bash default"><span class="bash">android.support.test.runner.AndroidJUnitRunner</span></code></em></li>
</ol>
<p>	<br />
<img src="http://i.giphy.com/10OjZwNlstPj9e.gif" width=100%"/><br />
<br />	<br />
So now you know a bit more about Espresso. If you want to know more, you may want to visit:</p>
<ul>
<li><a href="https://code.google.com/p/android-test-kit/">Espresso website</a></li>
<li><a href="https://github.com/welsinga/sample_espresso">Github repo corresponding to this article</a></li>
<li><a href="https://github.com/googlesamples/android-testing">General Espresso Github samples by Google</a></li>
</ul>
<p>
<strong>Updated</strong> (08-04) When running the tests with gradle you can just use <code class="codecolorer bash blackboard"><span class="bash">gradle connectedAndroidTest</span></code></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Archive addition Android artifacts with Gradle.</title>
		<link>http://wiebe-elsinga.com/blog/archive-addition-android-artifacts-with-gradle/</link>
		
		<dc:creator><![CDATA[W.Elsinga]]></dc:creator>
		<pubDate>Fri, 20 Mar 2015 06:42:19 +0000</pubDate>
				<category><![CDATA[AndroidDev Tips]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[gradle]]></category>
		<category><![CDATA[javadoc]]></category>
		<category><![CDATA[Proguard]]></category>
		<guid isPermaLink="false">http://wiebe-elsinga.com/blog/?p=1651</guid>

					<description><![CDATA[When building Android applications or libraries common practice is to save your artifacts to a local file storage or repo. Beside your APK there are some additional artifacts you want/need to save, and you want gradle to do this. Most common ones are Javadoc, your source files and perhaps your proguard generated files like the mapping file. I naturally wanted a Gradle task to handle this. So lets have a look as some tasks you may want to use. Adding Javadoc archive tasks The following will add tasks to generate Javadocs for each build type and assemble it into a jar archive . 123456789101112131415161718192021222324252627282930313233343536android.applicationVariants.all &#123; variant -&#62; &#160; &#160; project.task&#40;&#34;${variant.name.capitalize()}Javadoc&#34;, type: Javadoc&#41; &#123; &#160; &#160; &#160; &#160; destinationDir = new File&#40;&#34;$project.buildDir/javadoc/$variant.name&#34;&#41; &#160; &#160; &#160; &#160; source = variant.javaCompile.source &#160; &#160; &#160; &#160; ext.androidJar = &#34;${project.android.sdkDirectory}/platforms/${project.android.compileSdkVersion}/android.jar&#34; &#160; &#160; &#160; &#160; classpath = project.files&#40;variant.javaCompile.classpath.files&#41; + project.files&#40;ext.androidJar&#41; &#160; &#160; &#160; &#160; options &#123; &#160; &#160; &#160; &#160; &#160; &#160; linksOffline&#40;&#34;http://d.android.com/reference&#34;, &#34;${project.android.sdkDirectory}/docs/reference&#34;&#41; &#160; &#160; &#160; &#160; &#160; &#160; links&#40;&#34;http://docs.oracle.com/javase/7/docs/api/&#34;&#41;; &#160; &#160; &#160; &#160; &#160; &#160; setMemberLevel&#40;JavadocMemberLevel.PACKAGE&#41; &#160; &#160; &#160; &#160; &#160; &#160; docEncoding = 'UTF-8' &#160; &#160; &#160; &#160; &#160; &#160; encoding = 'UTF-8' &#160; &#160; &#160; &#160; &#160; &#160; charSet = 'UTF-8' &#160; &#160; &#160; &#160; &#125; &#160; &#160; &#160; &#160; exclude '**/BuildConfig.java' &#160; &#160; &#160; &#160; exclude '**/R.java' &#160; &#160; &#125; &#160; &#160; project.task&#40;&#34;generate${variant.name.capitalize()}JavadocJar&#34;, type: Jar, dependsOn: &#34;${variant.name.capitalize()}Javadoc&#34;&#41; &#123; &#160; &#160; &#160; &#160; classifier 'javadoc' &#160; &#160; &#160; &#160; description = 'Assembles a jar archive containing the generated Javadoc API documentation of $variant.name.' &#160; &#160; &#160; &#160; destinationDir = new File&#40;&#34;$project.buildDir/libs/&#34;&#41; &#160; &#160; &#160; &#160; exclude '**/BuildConfig.class' &#160; &#160; &#160; &#160; exclude '**/R.class' &#160; &#160; &#160; &#160; from &#34;$project.buildDir/javadoc/$variant.name&#34; &#160; &#160; &#125; &#125; When added to your build.gradle file, generate your Javadoc jar archive from the command line with gradle generateReleaseJavadocJar. Adding Source archive tasks The following will add tasks to assemble a jar archive containing the Java sources. 123456789101112131415android.applicationVariants.all &#123; variant -&#62; &#160; &#160; project.task&#40;&#34;generate${variant.name.capitalize()}SourcesJar&#34;, type: Jar&#41; &#123; &#160; &#160; &#160; &#160; classifier = 'sources' &#160; &#160; &#160; &#160; description = 'Assembles a jar archive containing the main sources of $variant.name..' &#160; &#160; &#160; &#160; destinationDir = new File&#40;&#34;$project.buildDir/libs/&#34;&#41; &#160; &#160; &#160; &#160; // exclude generated files &#160; &#160; &#160; &#160; exclude '**/BuildConfig.java' &#160; &#160; &#160; &#160; exclude '**/R.java' &#160; &#160; &#160; &#160; from variant.javaCompile.source &#160; &#160; &#125; &#125; When added to your build.gradle file, generate your Sources jar archive from the command line with gradle generateReleaseSourcesJar. Adding Proguard archive tasks The following will add tasks to assemble a zip archive containing the generated proguard files. 12345678910android.applicationVariants.all &#123; variant -&#62; &#160; &#160; project.task&#40;&#34;generate${variant.name.capitalize()}ProguardFilesJar&#34;, type: Zip&#41; &#123; &#160; &#160; &#160; &#160; classifier 'proguard' &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; description = 'Assembles a jar archive containing the Proguard files of $variant.name..' &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; destinationDir = new File&#40;&#34;$project.buildDir/libs/&#34;&#41; &#160; &#160; &#160; &#160; from &#34;$project.buildDir/outputs/mapping&#34; &#160; &#160; &#125; &#160; &#160; &#125; When added to your build.gradle file, generate your Proguard zip archive from the command line with gradle generateReleaseProguardFilesJar.]]></description>
										<content:encoded><![CDATA[<p>When building Android applications or libraries common practice is to save your artifacts to a local file storage or repo.</p>
<p>Beside your APK there are some additional artifacts you want/need to save, and you want gradle to do this. Most common ones are Javadoc, your source files and perhaps your <a href="http://proguard.sourceforge.net/">proguard</a> generated files like the mapping file.</p>
<p>I naturally wanted a Gradle task to handle this. So lets have a look as some tasks you may want to use.<br />
</p>
<h3>Adding Javadoc archive tasks</h3>
<p>The following will add tasks to generate Javadocs for each build type and assemble it into a jar archive .</p>
<div class="codecolorer-container groovy blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:100%;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="groovy codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">android.<span style="color: #006600;">applicationVariants</span>.<span style="color: #006600;">all</span> <span style="color: #66cc66;">&#123;</span> variant <span style="color: #66cc66;">-&gt;</span><br />
&nbsp; &nbsp; project.<span style="color: #006600;">task</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;${variant.name.capitalize()}Javadoc&quot;</span>, type: Javadoc<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; destinationDir <span style="color: #66cc66;">=</span> <a href="http://www.google.de/search?q=site%3Agroovy.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=File&amp;num=100&amp;hl=en&amp;as_occt=url&amp;as_sitesearch=java.sun.com%2Fj2se%2F1%2E5%2E0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$project.buildDir/javadoc/$variant.name&quot;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; source <span style="color: #66cc66;">=</span> variant.<span style="color: #006600;">javaCompile</span>.<span style="color: #006600;">source</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ext.<span style="color: #006600;">androidJar</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;${project.android.sdkDirectory}/platforms/${project.android.compileSdkVersion}/android.jar&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; classpath <span style="color: #66cc66;">=</span> project.<span style="color: #006600;">files</span><span style="color: #66cc66;">&#40;</span>variant.<span style="color: #006600;">javaCompile</span>.<span style="color: #006600;">classpath</span>.<span style="color: #006600;">files</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> project.<span style="color: #006600;">files</span><span style="color: #66cc66;">&#40;</span>ext.<span style="color: #006600;">androidJar</span><span style="color: #66cc66;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; options <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; linksOffline<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://d.android.com/reference&quot;</span>, <span style="color: #ff0000;">&quot;${project.android.sdkDirectory}/docs/reference&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; links<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://docs.oracle.com/javase/7/docs/api/&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setMemberLevel<span style="color: #66cc66;">&#40;</span>JavadocMemberLevel.<a href="http://www.google.de/search?q=site%3Agroovy.codehaus.org/%20package"><span style="color: #000000; font-weight: bold;">PACKAGE</span></a><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; docEncoding <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'UTF-8'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; encoding <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'UTF-8'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; charSet <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'UTF-8'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/BuildConfig.java'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/R.java'</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; project.<span style="color: #006600;">task</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;generate${variant.name.capitalize()}JavadocJar&quot;</span>, type: Jar, dependsOn: <span style="color: #ff0000;">&quot;${variant.name.capitalize()}Javadoc&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; classifier <span style="color: #ff0000;">'javadoc'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Assembles a jar archive containing the generated Javadoc API documentation of $variant.name.'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; destinationDir <span style="color: #66cc66;">=</span> <a href="http://www.google.de/search?q=site%3Agroovy.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=File&amp;num=100&amp;hl=en&amp;as_occt=url&amp;as_sitesearch=java.sun.com%2Fj2se%2F1%2E5%2E0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$project.buildDir/libs/&quot;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/BuildConfig.class'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/R.class'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; from <span style="color: #ff0000;">&quot;$project.buildDir/javadoc/$variant.name&quot;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>When added to your <code class="codecolorer bash blackboard"><span class="bash">build.gradle</span></code> file, generate your Javadoc jar archive from the command line with <code class="codecolorer bash blackboard"><span class="bash">gradle generateReleaseJavadocJar</span></code>.<br />
</p>
<h3>Adding Source archive tasks</h3>
<p>The following will add tasks to assemble a jar archive containing the Java sources.</p>
<div class="codecolorer-container groovy blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="groovy codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">android.<span style="color: #006600;">applicationVariants</span>.<span style="color: #006600;">all</span> <span style="color: #66cc66;">&#123;</span> variant <span style="color: #66cc66;">-&gt;</span><br />
&nbsp; &nbsp; project.<span style="color: #006600;">task</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;generate${variant.name.capitalize()}SourcesJar&quot;</span>, type: Jar<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; classifier <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'sources'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Assembles a jar archive containing the main sources of $variant.name..'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; destinationDir <span style="color: #66cc66;">=</span> <a href="http://www.google.de/search?q=site%3Agroovy.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=File&amp;num=100&amp;hl=en&amp;as_occt=url&amp;as_sitesearch=java.sun.com%2Fj2se%2F1%2E5%2E0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$project.buildDir/libs/&quot;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// exclude generated files</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/BuildConfig.java'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/R.java'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; from variant.<span style="color: #006600;">javaCompile</span>.<span style="color: #006600;">source</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>When added to your <code class="codecolorer bash blackboard"><span class="bash">build.gradle</span></code> file, generate your Sources jar archive from the command line with <code class="codecolorer bash blackboard"><span class="bash">gradle generateReleaseSourcesJar</span></code>.<br />
</p>
<h3>Adding Proguard archive tasks</h3>
<p>The following will add tasks to assemble a zip archive containing the generated proguard files.</p>
<div class="codecolorer-container groovy blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="groovy codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">android.<span style="color: #006600;">applicationVariants</span>.<span style="color: #006600;">all</span> <span style="color: #66cc66;">&#123;</span> variant <span style="color: #66cc66;">-&gt;</span><br />
&nbsp; &nbsp; project.<span style="color: #006600;">task</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;generate${variant.name.capitalize()}ProguardFilesJar&quot;</span>, type: Zip<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; classifier <span style="color: #ff0000;">'proguard'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Assembles a jar archive containing the Proguard files of $variant.name..'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; destinationDir <span style="color: #66cc66;">=</span> <a href="http://www.google.de/search?q=site%3Agroovy.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=File&amp;num=100&amp;hl=en&amp;as_occt=url&amp;as_sitesearch=java.sun.com%2Fj2se%2F1%2E5%2E0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$project.buildDir/libs/&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; from <span style="color: #ff0000;">&quot;$project.buildDir/outputs/mapping&quot;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; &nbsp;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>When added to your <code class="codecolorer bash blackboard"><span class="bash">build.gradle</span></code> file, generate your Proguard zip archive from the command line with <code class="codecolorer bash blackboard"><span class="bash">gradle generateReleaseProguardFilesJar</span></code>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>AndroidDev (Pro) tip: Do not forget screenSize</title>
		<link>http://wiebe-elsinga.com/blog/androiddev-pro-tip-dont-reload-when-orientation-changes/</link>
					<comments>http://wiebe-elsinga.com/blog/androiddev-pro-tip-dont-reload-when-orientation-changes/#comments</comments>
		
		<dc:creator><![CDATA[W.Elsinga]]></dc:creator>
		<pubDate>Fri, 01 Feb 2013 08:34:52 +0000</pubDate>
				<category><![CDATA[AndroidDev Tips]]></category>
		<category><![CDATA[AndroidDev]]></category>
		<guid isPermaLink="false">http://wiebe-elsinga.com/blog/?p=1424</guid>

					<description><![CDATA[So you are stuck using screenOrientation in your android:configChanges list within your AndroidManifest. Your activity will not be recreated, but will receive a callback instead. You may not know that this is insufficient on API level of 13 or above. In API level 13 or above, the screen size changes when the orientation changes, so this cause the activity to be destroyed. If you still want to keep the state and use onConfigurationChanged() you will also need to use screenSize.]]></description>
										<content:encoded><![CDATA[<p>So you are stuck using screenOrientation in your <em>android:configChanges</em> list within your <em>AndroidManifest</em>. Your activity will not be recreated, but will receive a callback instead.<br />
You may not know that this is insufficient on API level of 13 or above.</p>
<p>In API level 13 or above, the screen size changes when the orientation changes, so this cause the activity to be destroyed. If you still want to keep the state and use <em>onConfigurationChanged()</em> you will also need to use <em>screenSize</em>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://wiebe-elsinga.com/blog/androiddev-pro-tip-dont-reload-when-orientation-changes/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>AndroidDev (Pro) tip: Fragment meets container</title>
		<link>http://wiebe-elsinga.com/blog/androiddev-pro-tip-fragment-meets-container/</link>
					<comments>http://wiebe-elsinga.com/blog/androiddev-pro-tip-fragment-meets-container/#respond</comments>
		
		<dc:creator><![CDATA[W.Elsinga]]></dc:creator>
		<pubDate>Fri, 01 Feb 2013 08:04:58 +0000</pubDate>
				<category><![CDATA[AndroidDev Tips]]></category>
		<category><![CDATA[AndroidDev]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[Fragment]]></category>
		<guid isPermaLink="false">http://wiebe-elsinga.com/blog/?p=1415</guid>

					<description><![CDATA[Today a tip from my colleague Coen Houtman, a tip about Fragments and the container to put them in. What all of you Fragment users know, is that you must have a container (i.e. ViewGroup) to put your fragments in. Which ViewGroup is the best to use? Normally, with any other layout I want to create, I start with a LinearLayout. It&#8217;s simple, easy and lightweight; something that you will experience in more complex layouts. If you use LinearLayout as the container for your Fragments, you will probably run into some issues. In the image below, the content doesn&#8217;t even take up half the screen. Even though the width was set to match it&#8217;s parent. The solution to the problem above: use FrameLayout! I&#8217;m not claiming that FrameLayout is always the way to go. In all our projects though, we use FrameLayout as the container for our Fragments. At the moment I don&#8217;t have the answer of why FrameLayout works better than LinearLayout. But when I do, you&#8217;ll read it here!]]></description>
										<content:encoded><![CDATA[<p>Today a tip from my colleague Coen Houtman, a tip about Fragments and the container to put them in. What all of you Fragment users know, is that you must have a container (i.e. ViewGroup) to put your fragments in.</p>
<h4>Which ViewGroup is the best to use?</h4>
<p>Normally, with any other layout I want to create, I start with a LinearLayout. It&#8217;s simple, easy and lightweight; something that you will experience in more complex layouts. If you use LinearLayout as the container for your Fragments, you will probably run into some issues. In the image below, the content doesn&#8217;t even take up half the screen. Even though the width was set to match it&#8217;s parent.</p>
<p style="text-align: justify;"><a href="http://wiebe-elsinga.com/blog/wp-content/uploads/2013/02/device-2012-12-14-111146.png" rel="lightbox[1415]" title="AndroidDev (Pro) tip: Fragment meets container"><img loading="lazy" class="aligncenter size-full wp-image-1417" alt="device-2012-12-14-111146" src="http://wiebe-elsinga.com/blog/wp-content/uploads/2013/02/device-2012-12-14-111146.png" width="187" height="300" srcset="http://wiebe-elsinga.com/blog/wp-content/uploads/2013/02/device-2012-12-14-111146.png 800w, http://wiebe-elsinga.com/blog/wp-content/uploads/2013/02/device-2012-12-14-111146-187x300.png 187w, http://wiebe-elsinga.com/blog/wp-content/uploads/2013/02/device-2012-12-14-111146-640x1024.png 640w" sizes="(max-width: 187px) 100vw, 187px" /></a></p>
<p>The solution to the problem above: use FrameLayout! I&#8217;m not claiming that FrameLayout is always the way to go. In all our projects though, we use FrameLayout as the container for our Fragments. At the moment I don&#8217;t have the answer of why FrameLayout works better than LinearLayout. But when I do, you&#8217;ll read it here!</p>
]]></content:encoded>
					
					<wfw:commentRss>http://wiebe-elsinga.com/blog/androiddev-pro-tip-fragment-meets-container/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
