<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xml" href="http://blog.jensdriller.com/feed.xslt.xml"?><feed xmlns="http://www.w3.org/2005/Atom"><generator uri="http://jekyllrb.com" version="3.3.1">Jekyll</generator><link href="http://blog.jensdriller.com/feed.xml" rel="self" type="application/atom+xml" /><link href="http://blog.jensdriller.com/" rel="alternate" type="text/html" /><updated>2017-01-18T11:27:43+00:00</updated><id>http://blog.jensdriller.com//</id><title type="html">Jens Driller’s Blog</title><subtitle>I've started this blog to share some cool tips &amp; tricks as well as workarounds for annoying bugs I've come across during development, hoping that it will save others some time and effort.
</subtitle><entry><title type="html">RxJava Tidbits</title><link href="http://blog.jensdriller.com/rxjava-tidbits/" rel="alternate" type="text/html" title="RxJava Tidbits" /><published>2016-10-30T21:48:04+00:00</published><updated>2016-10-30T21:48:04+00:00</updated><id>http://blog.jensdriller.com/rxjava-tidbits</id><content type="html" xml:base="http://blog.jensdriller.com/rxjava-tidbits/">&lt;p&gt;I recently started a mini-series on &lt;strong&gt;RxJava&lt;/strong&gt; riddles. It is a collection of tips &amp;amp; tricks and solutions to common, real-world problems I have come across during development.&lt;/p&gt;

&lt;p&gt;It is published on Medium: &lt;a href=&quot;https://medium.com/rxjava-tidbits&quot;&gt;RxJava Tidbits&lt;/a&gt;&lt;/p&gt;</content><summary type="html">I recently started a mini-series on RxJava riddles. It is a collection of tips &amp;amp; tricks and solutions to common, real-world problems I have come across during development.</summary></entry><entry><title type="html">How to debug a Java Annotation Processor using IntelliJ &amp;amp; Maven</title><link href="http://blog.jensdriller.com/how-to-debug-a-java-annotation-processor-using-intellij/" rel="alternate" type="text/html" title="How to debug a Java Annotation Processor using IntelliJ &amp; Maven" /><published>2015-10-11T09:37:56+01:00</published><updated>2015-10-11T09:37:56+01:00</updated><id>http://blog.jensdriller.com/how-to-debug-a-java-annotation-processor-using-intellij</id><content type="html" xml:base="http://blog.jensdriller.com/how-to-debug-a-java-annotation-processor-using-intellij/">&lt;p&gt;File this post under &lt;em&gt;“stuff-I-google-repeatedly”&lt;/em&gt;.
I’m posting this so it will pop up the next time I’m searching for it in 3 months time.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;firstly-configure-intellij&quot;&gt;Firstly, configure IntelliJ:&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Run &amp;gt; Edit Configurations…&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Add New Configuration (Type: &lt;strong&gt;Remote&lt;/strong&gt;)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Keep all defaults &amp;amp; Just change the port to &lt;strong&gt;8000&lt;/strong&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;http://blog.jensdriller.com/assets/2015/10/mvnDebug.png&quot; alt=&quot;mvnDebug Run Configuration&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;secondly-switch-to-cli&quot;&gt;Secondly, switch to CLI:&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;cd&lt;/code&gt; into the project’s directory&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Run &lt;code class=&quot;highlighter-rouge&quot;&gt;mvnDebug clean install&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This will produce an output like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;mvnDebug&lt;/code&gt; is very similar to the classic &lt;code class=&quot;highlighter-rouge&quot;&gt;mvn&lt;/code&gt; command apart from the crucial difference that it will wait for a debugger to be attached to the Java process before continuing execution.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;lastly-switch-back-to-intellij&quot;&gt;Lastly, switch back to IntelliJ:&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;Set your breakpoints &amp;amp; Run the new configuration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A new debugger session will be created and attached to the Java process on port 8000. If you switch back to the terminal, you can actually see the Maven command being resumed (i.e. logs are being printed out).&lt;/p&gt;

&lt;p&gt;Happy debugging!&lt;/p&gt;</content><summary type="html">File this post under “stuff-I-google-repeatedly”.
I’m posting this so it will pop up the next time I’m searching for it in 3 months time.</summary></entry><entry><title type="html">My new favourite Git feature: git rebase –-autostash</title><link href="http://blog.jensdriller.com/my-new-favourite-git-feature-git-rebase-autostash/" rel="alternate" type="text/html" title="My new favourite Git feature: git rebase –-autostash" /><published>2015-07-20T20:49:27+01:00</published><updated>2015-07-20T20:49:27+01:00</updated><id>http://blog.jensdriller.com/my-new-favourite-git-feature-git-rebase-autostash</id><content type="html" xml:base="http://blog.jensdriller.com/my-new-favourite-git-feature-git-rebase-autostash/">&lt;h1 id=&quot;update-140116&quot;&gt;UPDATE 14/01/16:&lt;/h1&gt;

&lt;p&gt;Git &lt;a href=&quot;https://developer.atlassian.com/blog/2016/01/git-2.7-release&quot;&gt;v2.7.0&lt;/a&gt; is out! All you need to do now is set the following global config flag and you can simply rebase as usual even onto a dirty worktree: &lt;code class=&quot;highlighter-rouge&quot;&gt;git config --global rebase.autostash true&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;update-271015&quot;&gt;UPDATE 27/10/15:&lt;/h1&gt;

&lt;p&gt;The recently released Git &lt;a href=&quot;https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.6.0.txt&quot;&gt;v2.6.0&lt;/a&gt; has been taught to pay attention to your &lt;strong&gt;rebase.autostash&lt;/strong&gt; configuration which enables the &lt;code class=&quot;highlighter-rouge&quot;&gt;--autostash&lt;/code&gt; option by default. That means that a simple &lt;code class=&quot;highlighter-rouge&quot;&gt;git pull --rebase&lt;/code&gt; is now capable of rebasing a dirty worktree.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;original-post&quot;&gt;ORIGINAL POST:&lt;/h1&gt;

&lt;p&gt;I recently stumbled upon a (in my opinion) less well-known feature of Git that’s actually been around since &lt;a href=&quot;https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/1.8.4.txt&quot;&gt;v1.8.4&lt;/a&gt; (current version: &lt;a href=&quot;https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.4.6.txt&quot;&gt;v2.4.6&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;It is the &lt;code class=&quot;highlighter-rouge&quot;&gt;git rebase --autostash&lt;/code&gt; command. And it basically does what it says: Automatically stashing away changes before performing the rebase operation. Before that release, rebase would just refuse to run.&lt;/p&gt;

&lt;p&gt;It is the equivalent to: &lt;code class=&quot;highlighter-rouge&quot;&gt;git stash &amp;amp; git pull --rebase &amp;amp; git stash pop&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now think about how many times you’re doing that per day. At least I find myself executing those commands over and over again to stay up-to-date with the remote origin.&lt;/p&gt;

&lt;p&gt;So I created a handy alias for &lt;code class=&quot;highlighter-rouge&quot;&gt;git fetch &amp;amp;&amp;amp; git rebase --autostash&lt;/code&gt;, so I only need to run &lt;code class=&quot;highlighter-rouge&quot;&gt;git update&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you’re using &lt;a href=&quot;https://www.sourcetreeapp.com&quot;&gt;SourceTree&lt;/a&gt;, you might also want to create a custom action that allows you to do the same operation with a single mouse click. Just create a new file called &lt;code class=&quot;highlighter-rouge&quot;&gt;stash_and_rebase.sh&lt;/code&gt; with the following contents:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/sh&lt;/span&gt;
git fetch &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; git rebase --autostash
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;You can then set it up via &lt;strong&gt;SourceTree / Preferences / Custom Actions / Add&lt;/strong&gt; like so:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://blog.jensdriller.com/assets/2015/07/Screen-Shot-2015-07-16-at-11-07-42.png&quot; alt=&quot;SourceTree&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Baam! That’s it. And it saves me a couple of seconds every day :)&lt;/p&gt;</content><summary type="html">UPDATE 14/01/16:</summary></entry><entry><title type="html">Android Annotation Processing Setup using Gradle</title><link href="http://blog.jensdriller.com/android-annotation-processing-setup-using-gradle/" rel="alternate" type="text/html" title="Android Annotation Processing Setup using Gradle" /><published>2015-04-20T20:36:37+01:00</published><updated>2015-04-20T20:36:37+01:00</updated><id>http://blog.jensdriller.com/android-annotation-processing-setup-using-gradle</id><content type="html" xml:base="http://blog.jensdriller.com/android-annotation-processing-setup-using-gradle/">&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have created an example &lt;a href=&quot;https://github.com/jenzz/Android-StaticLauncher&quot;&gt;Android project&lt;/a&gt; you can use to kickstart your Java and/or Android &lt;strong&gt;annotation processing library&lt;/strong&gt; based on the Gradle build system. It is also setup to easily publish the artifacts to &lt;strong&gt;JCenter&lt;/strong&gt; (via &lt;a href=&quot;https://bintray.com&quot;&gt;Bintray&lt;/a&gt;) using the &lt;a href=&quot;https://github.com/novoda/bintray-release&quot;&gt;novoda/bintray-release&lt;/a&gt; plugin.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Ok, so I’ve read &lt;a href=&quot;http://hannesdorfmann.com/annotation-processing/annotationprocessing101&quot;&gt;this article&lt;/a&gt; about annotation processing some time ago on &lt;a href=&quot;http://hannesdorfmann.com&quot;&gt;Hannes Dorfmann’s blog&lt;/a&gt;. It’s a great article introducing you to the world of annotation processing in Java. It’s well worth reading! So make sure you check it out.&lt;/p&gt;

&lt;p&gt;The example project that’s being created in that tutorial is using &lt;strong&gt;Maven&lt;/strong&gt; as the build system. As an Android developer these days, your preferred companion for building your apps and/or libraries is (hopefully) &lt;strong&gt;Gradle&lt;/strong&gt;. So let’s go ahead and see how we can produce a similar setup using the Gradle build system.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;I’ve decided to create a simple annotation processor called &lt;a href=&quot;https://github.com/jenzz/Android-StaticLauncher&quot;&gt;StaticLauncher&lt;/a&gt;.
The idea is that you can annotate any &lt;strong&gt;Activity&lt;/strong&gt; with &lt;strong&gt;@StaticLauncher&lt;/strong&gt; and it will generate a new &lt;strong&gt;ActivityLauncher&lt;/strong&gt; class for you providing some handy, static helper methods to launch that Activity.&lt;/p&gt;

&lt;p&gt;Here’s what it looks like - an annotated &lt;strong&gt;Activity&lt;/strong&gt;:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;@StaticLauncher
public class ActivityA extends ActionBarActivity {}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;And the generated code:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public final class ActivityALauncher {
  public static Intent getIntent(Context context) {
    return new Intent(context, ActivityA.class);
  }

  public static void startActivity(Context context) {
    context.startActivity(getIntent(context));
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;And that’s it - I guess it’s sufficient for a simple example. However, feel free to fork the repo and enhance the project to make it a truly useful library. For example, by adding support for Intent extras? :)&lt;/p&gt;

&lt;p&gt;Ok, now this article is about the Gradle setup, so let’s have a look at the project structure:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://blog.jensdriller.com/assets/2015/04/Screen-Shot-2015-04-12-at-17-16-53-1.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As Hannes has already pointed out in his blog post, it’s quite common and best practice to separate out your custom annotations into a separate Java module. The main reason being that users of your library shouldn’t need to include all of your annotation processing logic and only use it for compilation.&lt;/p&gt;

&lt;p&gt;Note that I usually name the 2nd module &lt;strong&gt;processor&lt;/strong&gt; since it better describes its purpose. This time I called it &lt;strong&gt;compiler&lt;/strong&gt;… because why not?&lt;/p&gt;

&lt;p&gt;So, the contents of those modules are as follows:&lt;/p&gt;

&lt;h1 id=&quot;api&quot;&gt;api&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Content:&lt;/strong&gt; annotation definitions &amp;amp; potentially other, non-generated code&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dependencies:&lt;/strong&gt; none&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;compiler&quot;&gt;compiler&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Content:&lt;/strong&gt; annotation processing logic (generates the actual code)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dependencies:&lt;/strong&gt; api module &amp;amp; potentially other libraries that aid development (e.g. &lt;a href=&quot;https://github.com/google/auto/tree/master/service&quot;&gt;google/auto&lt;/a&gt; and &lt;a href=&quot;https://github.com/square/javapoet&quot;&gt;square/javapoet&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;sample&quot;&gt;sample&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Content:&lt;/strong&gt; the sample app &lt;em&gt;(ba dum tss)&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dependencies:&lt;/strong&gt; api module &amp;amp; compiler module as a compile time only dependency using &lt;a href=&quot;https://bitbucket.org/hvisser/android-apt&quot;&gt;hvisser/android-apt&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For reference, here are the links to the modules’ build files:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/jenzz/Android-StaticLauncher/blob/master/build.gradle&quot;&gt;Project: StaticLauncher&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/jenzz/Android-StaticLauncher/blob/master/api/build.gradle&quot;&gt;Module: api&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/jenzz/Android-StaticLauncher/blob/master/compiler/build.gradle&quot;&gt;Module: compiler&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/jenzz/Android-StaticLauncher/blob/master/sample/build.gradle&quot;&gt;Module: sample&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I don’t think it’s worth going through every build file in detail. You can just checkout and browse the &lt;a href=&quot;(https://github.com/jenzz/Android-StaticLauncher)&quot;&gt;GitHub repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;One more thing: If you’re using &lt;strong&gt;Java 8&lt;/strong&gt; as your SDK, you need to ensure and tell the compiler to build using Java 7 or you will get the following error during pre-dexing:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;:sample:preDexDebug

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
...while parsing com/jenzz/staticlauncher/StaticLauncher.class

1 error; aborting
Error:Execution failed for task ':sample:preDexDebug'.
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;To solve this, just put the following two lines into your &lt;strong&gt;api&lt;/strong&gt; module’s build file and you’re ready to go:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Finally, to publish your annotation processor to &lt;strong&gt;JCenter&lt;/strong&gt;, all you need to do is modify the &lt;strong&gt;ext&lt;/strong&gt; closure of the &lt;code class=&quot;highlighter-rouge&quot;&gt;build.gradle&lt;/code&gt; file in the project root folder.&lt;/p&gt;

&lt;p&gt;For this example project, it looks like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ext {
  userOrg = 'jenzz'
  groupId = 'com.jenzz.staticlauncher'
  uploadName = 'Android-StaticLauncher'
  publishVersion = '0.1'
  description = 'An example project of Java annotation processing based on Gradle'
  website = 'https://github.com/jenzz/Android-StaticLauncher'
  licences = ['MIT']
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Both submodules reference these properties, so this is the only place you need to make changes. For more info about the available properties and other usages have a look at the plugin’s &lt;a href=&quot;https://github.com/novoda/bintray-release/wiki&quot;&gt;GitHub wiki&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And finally, here’s how to make it available to the world:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun=false
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content><summary type="html">TL;DR</summary></entry><entry><title type="html">Android Gradle workaround for missing placeholder support in resource files</title><link href="http://blog.jensdriller.com/android-gradle-workaround-for-missing-placeholder-support-in-resource-files/" rel="alternate" type="text/html" title="Android Gradle workaround for missing placeholder support in resource files" /><published>2014-11-20T17:28:19+00:00</published><updated>2014-11-20T17:28:19+00:00</updated><id>http://blog.jensdriller.com/android-gradle-workaround-for-missing-placeholder-support-in-resource-files</id><content type="html" xml:base="http://blog.jensdriller.com/android-gradle-workaround-for-missing-placeholder-support-in-resource-files/">&lt;p&gt;Ok, so here’s a bit more Gradle hacking.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note that the following workaround becomes obsolete once the  guys at Google &lt;a href=&quot;https://code.google.com/p/android/issues/detail?id=71365&quot;&gt;add support for placeholders in resource files&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So the problem is as follows:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;You have a &lt;a href=&quot;http://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter.html&quot;&gt;SyncAdapter&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;You have multiple build variants.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;WAAAAT? Yes, that’s already enough to cause some headaches, assuming you wanna install multiple build variants side by side.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;So before we’re getting right into the root of the problem, note that this article might as well take one of the following titles:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;How to provide unique authorities per build variant for your &lt;a href=&quot;http://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter.html&quot;&gt;SyncAdapter&lt;/a&gt;, &lt;a href=&quot;http://developer.android.com/reference/android/accounts/AbstractAccountAuthenticator.html&quot;&gt;AccountAuthenticator&lt;/a&gt; and/or &lt;a href=&quot;http://developer.android.com/reference/android/content/ContentProvider.html&quot;&gt;ContentProvider&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;How to enable the &lt;code class=&quot;highlighter-rouge&quot;&gt;${applicationId}&lt;/code&gt; placeholder in &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;sync-adapter /&amp;gt;&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;searchable /&amp;gt;&lt;/code&gt; and/or &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;account-authenticator /&amp;gt;&lt;/code&gt; XML files&lt;/li&gt;
  &lt;li&gt;How to avoid the dreaded &lt;code class=&quot;highlighter-rouge&quot;&gt;INSTALL_FAILED_CONFLICTING_PROVIDER&lt;/code&gt; exception&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you wonder what the exception in the last title is all about, it occurs if two apps (e.g. debug and release) are registering for the same &lt;a href=&quot;http://developer.android.com/reference/android/content/ContentProvider.html&quot;&gt;ContentProvider&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;So why is this a problem at all? Well, the authority of a &lt;code class=&quot;highlighter-rouge&quot;&gt;SyncAdapter&lt;/code&gt; as listed in &lt;code class=&quot;highlighter-rouge&quot;&gt;android:authorities&lt;/code&gt; must be unique. As per the official &lt;a href=&quot;http://developer.android.com/guide/topics/providers/content-provider-creating.html#ContentURI&quot;&gt;Android documentation&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A provider usually has a &lt;strong&gt;single authority&lt;/strong&gt;, which serves as its Android-internal name. To avoid conflicts with other providers, &lt;strong&gt;you should use Internet domain ownership (in reverse) as the basis of your provider authority.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, for &lt;a href=&quot;http://developer.android.com/reference/android/content/ContentProvider.html&quot;&gt;ContentProviders&lt;/a&gt; that are specified in your &lt;code class=&quot;highlighter-rouge&quot;&gt;AndroidManifest.xml&lt;/code&gt; file this is not a problem at all. You can just use the &lt;code class=&quot;highlighter-rouge&quot;&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;applicationId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt; placeholder as follows:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;provider
    android:name=&quot;com.example.MyApp.MyProvider&quot;
    android:authorities=&quot;${applicationId}.provider&quot;
    android:enabled=&quot;true&quot;
    android:exported=&quot;false&quot; /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Unfortunately, &lt;code class=&quot;highlighter-rouge&quot;&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;applicationId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt; does not work in other XML resource files.&lt;/p&gt;

&lt;p&gt;So how are we gonna fix this? Gradle to the rescue!
What we’re gonna do is dynamically generate a new XML String resource file that provides unique authorities for the current build variant.&lt;/p&gt;

&lt;p&gt;To do that, firstly, we need to tell our build script that the task that merges the resources (called &lt;code class=&quot;highlighter-rouge&quot;&gt;mergeResources&lt;/code&gt;) depends on our own task which I’ve called &lt;code class=&quot;highlighter-rouge&quot;&gt;createBuildVariantResources&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;android {
	applicationVariants.all { variant -&amp;gt;
    	 variant.mergeResources.dependsOn {
            createBuildVariantResources(variant)
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;That task takes the build variant as a parameter. You will soon see why.&lt;/p&gt;

&lt;p&gt;But first, let’s create a simple helper method that returns the application ID for a given build variant:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/**
 * @return the applicationId for the given build variant
 */
ext.applicationId = { variant -&amp;gt;
    def applicationId = variant.productFlavors[0].applicationId
    def suffix = variant.buildType.applicationIdSuffix
    applicationId += suffix ?: &quot;&quot;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;I think this snippet doesn’t need much explanation. It grabs both the app ID and a potential app suffix from the given build variant and returns them as a concatenated String. You can put this anywhere in your &lt;code class=&quot;highlighter-rouge&quot;&gt;build.gradle&lt;/code&gt; file. I usually place it outside of the Android closure at the bottom of the build script.&lt;/p&gt;

&lt;p&gt;Now, let’s generate the resources. Note that regular Strings in Groovy cannot span multiple lines. So we’re gonna use triple double quotes to create a &lt;a href=&quot;http://groovy.codehaus.org/Strings+and+GString&quot;&gt;multi-line GString&lt;/a&gt; that supports interpolating variables:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/**
 * Generates unique resources for the given build variant that are used
 * by our sync adapter, account authenticator, content provider, etc.
 * The resources are based on the application id so that each build variant can be installed
 * alongside each other without causing the dreaded &quot;INSTALL_FAILED_CONFLICTING_PROVIDER&quot; exception.
 */
ext.createBuildVariantResources = { variant -&amp;gt;
    def applicationId = applicationId(variant)
    def syncAuthority = applicationId + &quot;.sync&quot;
    def syncAccountType = applicationId + &quot;.provider&quot;
    def res = &quot;&quot;&quot;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;resources&amp;gt;

    &amp;lt;!-- Automatically generated file. DO NOT MODIFY. --&amp;gt;

    &amp;lt;string name=&quot;application_id&quot;&amp;gt;${applicationId}&amp;lt;/string&amp;gt;
    &amp;lt;string name=&quot;sync_authority&quot;&amp;gt;${syncAuthority}&amp;lt;/string&amp;gt;
    &amp;lt;string name=&quot;sync_account_type&quot;&amp;gt;${syncAccountType}&amp;lt;/string&amp;gt;

&amp;lt;/resources&amp;gt;&quot;&quot;&quot;
	def folder = new File(&quot;${buildDir}/generated/res/generated/${variant.dirName}/values&quot;)
	folder.mkdirs()
	def file = new File(folder, &quot;variant_resources.xml&quot;)
	file.createNewFile()
	file.write(res)
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;I think the code itself is again self-explanatory. It creates a new file called &lt;code class=&quot;highlighter-rouge&quot;&gt;variant_resources.xml&lt;/code&gt; and stores it in the project’s generated values folder. I also added the application ID which you might as well obtain via &lt;code class=&quot;highlighter-rouge&quot;&gt;BuildConfig.APPLICATION_ID&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And that’s it. You can now reference your &lt;a href=&quot;http://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter.html&quot;&gt;SyncAdapter&lt;/a&gt;’s authority using &lt;code class=&quot;highlighter-rouge&quot;&gt;@string/sync_authority&lt;/code&gt; which is guaranteed to be unique per build variant since it’s based on the current variant’s application ID.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One last note: &lt;a href=&quot;https://github.com/android/platform_frameworks_base/commit/cf244ada58539ce857ec041d7288d0271204fbb6&quot;&gt;resource-based authorities&lt;/a&gt; only work on Android 2.2.1 and later.&lt;/strong&gt;
This shouldn’t be a problem for you these days. &lt;a href=&quot;http://chalup.github.io/blog/2014/06/15/minsdkversion-equals-15/&quot;&gt;minSdkVersion=15&lt;/a&gt; FTW!&lt;/p&gt;

&lt;p&gt;Also: &lt;a href=&quot;https://code.google.com/p/android/issues/detail?id=73595&quot;&gt;Android Studio doesn’t yet recognize resources&lt;/a&gt; that are generated by Gradle. So you will see that the references from above are being marked in red and annotated with &lt;code class=&quot;highlighter-rouge&quot;&gt;Cannot resolve symbol '@string/sync_authority'&lt;/code&gt;. However, this is only Android Studio moaning. You can safely ignore that. It will be fixed soon.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;So this solution is obviously not elegant at all, but it does the job. For now. Consider it a temporary workaround until another update of the &lt;a href=&quot;http://tools.android.com/tech-docs/new-build-system&quot;&gt;Android Gradle plugin&lt;/a&gt; will be released that fixes this problem.&lt;/p&gt;</content><summary type="html">Ok, so here’s a bit more Gradle hacking.</summary></entry><entry><title type="html">5 simple Google Chrome extensions to enhance your GitHub experience</title><link href="http://blog.jensdriller.com/5-simple-google-chrome-extensions-to-enhance-your-github-experience/" rel="alternate" type="text/html" title="5 simple Google Chrome extensions to enhance your GitHub experience" /><published>2014-11-03T12:01:00+00:00</published><updated>2014-11-03T12:01:00+00:00</updated><id>http://blog.jensdriller.com/5-simple-google-chrome-extensions-to-enhance-your-github-experience</id><content type="html" xml:base="http://blog.jensdriller.com/5-simple-google-chrome-extensions-to-enhance-your-github-experience/">&lt;p&gt;So you’re using &lt;a href=&quot;https://www.github.com&quot;&gt;GitHub&lt;/a&gt; like your #1 social network?
Here are some Google Chrome extensions that will improve your daily experience. I’ve been using them for a couple of months now and can’t imagine browsing GitHub w/o them anymore.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note that unfortunately some of these extensions only work with public repos.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;octotree&quot;&gt;Octotree&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://chrome.google.com/webstore/detail/octotree/bkhaagjahfmjljalopjnoealnfndnagc&quot;&gt;Chrome Web Store&lt;/a&gt; - &lt;a href=&quot;https://github.com/buunguyen/octotree&quot;&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A Chrome extension to display GitHub code in tree format. This adds a sidebar to the left and makes navigating projects a lot easier!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://lh4.googleusercontent.com/YBD64jR-o0kzLsZwK39mcRYVksugyKrmQc5E2acYBo2UTCnl9hjgoZAf0LNfA2ZZN9njvgET=s1280-h800-e365-rw&quot; alt=&quot;Octotree Screenshot&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;githubexpandinizr&quot;&gt;GitHub.Expandinizr&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://chrome.google.com/webstore/detail/githubexpandinizr/cbehdjjcilgnejbpnjhobkiiggkedfib&quot;&gt;Chrome Web Store&lt;/a&gt; - &lt;a href=&quot;https://github.com/thecodejunkie/github.expandinizr&quot;&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have you ever noticed all the whitespace on almost every GitHub page? This extension gets rid of it and expands the content to full width. Also prevents truncation of commits. Pretty cool.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://lh5.googleusercontent.com/hwxbV5x86iYDgY5NMLI8KZwDOT03v2uA1kIJobbawFAd_FFFL6DIRbUL4ICmnRyd3hncJDMaeA=s1280-h800-e365-rw&quot; alt=&quot;GitHub.Expandinizr Screenshot&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;github-tab-size&quot;&gt;GitHub Tab Size&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://chrome.google.com/webstore/detail/github-tab-size/ofjbgncegkdemndciafljngjbdpfmbkn&quot;&gt;Chrome Web Store&lt;/a&gt; - &lt;a href=&quot;https://github.com/sindresorhus/github-tab-size&quot;&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Makes tab indented code more readable by forcing the tab size to four instead of eight.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/sindresorhus/github-tab-size/master/screenshot.png&quot; alt=&quot;GitHub Tab Size Screenshot&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;coloured-timestamps&quot;&gt;Coloured Timestamps&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://chrome.google.com/webstore/detail/github-add-color-to-recen/gnlanakllhhldoneeennbednopiaadld&quot;&gt;Chrome Web Store&lt;/a&gt; - GitHub n/a&lt;/p&gt;

&lt;p&gt;Have you ever found yourself browsing around a project for quite a while only until you realize that the project is inactive for more than a year? This extension adds colour to all the timestamps in the file list. If you see a red wall on the right, the project’s probably been abandoned…&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://lh5.googleusercontent.com/XoX8o2eTp2k83UQ22FRJdCxUaUWu0vzOe4o8B0jhGhgOob_zW_bM0--nITKpn0nbgKDPlmbXkg=s1280-h800-e365-rw&quot; alt=&quot;Coloured Timestamps Screenshot&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;github-wiki-search&quot;&gt;GitHub Wiki Search&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://chrome.google.com/webstore/detail/github-wiki-search/gdifdhnjmjaidbajhapmbcbnoocoeooc&quot;&gt;Chrome Web Store&lt;/a&gt; - &lt;a href=&quot;https://github.com/linyows/github-wiki-search&quot;&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Adds a search field to the Wiki pages. I found this to be especially useful on large projects where there are loads of different sections in the Wiki.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://lh4.googleusercontent.com/uCeBytkdGbFo8MOC6WZFcQx09UIXkp-ZF8fGhQe5voLasWRX9IOjhMDaHfoD-unHQUVF_lVvhLY=s1280-h800-e365-rw&quot; alt=&quot;GitHub Wiki Search Screenshot&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;And finally, there’s the simple &lt;a href=&quot;https://chrome.google.com/webstore/detail/coderstats-link-for-githu/necogepejonacpphmlmcagmbjaogpbng&quot;&gt;CoderStats extension&lt;/a&gt; which adds a link to the current user’s &lt;a href=&quot;http://coderstats.net/github/jenzz/&quot;&gt;CoderStats&lt;/a&gt; page right below his avatar.&lt;/p&gt;

&lt;p&gt;That’s it. If you know of any other cool extensions that improve your day-to-day experience on GitHub, please let me know in the comments.&lt;/p&gt;</content><summary type="html">So you’re using GitHub like your #1 social network?
Here are some Google Chrome extensions that will improve your daily experience. I’ve been using them for a couple of months now and can’t imagine browsing GitHub w/o them anymore.</summary></entry><entry><title type="html">Simple deserialization of Java enums using Google GSON annotations</title><link href="http://blog.jensdriller.com/simple-deserialization-of-java-enums-using-google-gson-annotations/" rel="alternate" type="text/html" title="Simple deserialization of Java enums using Google GSON annotations" /><published>2014-10-06T09:40:53+01:00</published><updated>2014-10-06T09:40:53+01:00</updated><id>http://blog.jensdriller.com/simple-deserialization-of-java-enums-using-google-gson-annotations</id><content type="html" xml:base="http://blog.jensdriller.com/simple-deserialization-of-java-enums-using-google-gson-annotations/">&lt;p&gt;Here’s a little quick tip about something that I think is a less well-known feature of Google’s awesome &lt;a href=&quot;https://code.google.com/p/google-gson/&quot;&gt;GSON&lt;/a&gt; library:&lt;/p&gt;

&lt;h1 id=&quot;parsing-java-enums-using-annotations&quot;&gt;Parsing Java enums using annotations&lt;/h1&gt;
&lt;p&gt;Assuming you receive a simple JSON response like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;value&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;suit&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;hearts&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;where &lt;code class=&quot;highlighter-rouge&quot;&gt;suit&lt;/code&gt; is always a lower-case &lt;code class=&quot;highlighter-rouge&quot;&gt;String&lt;/code&gt; of the following fixed set:
&lt;code class=&quot;highlighter-rouge&quot;&gt;hearts&lt;/code&gt; - &lt;code class=&quot;highlighter-rouge&quot;&gt;diamonds&lt;/code&gt; - &lt;code class=&quot;highlighter-rouge&quot;&gt;clubs&lt;/code&gt; - &lt;code class=&quot;highlighter-rouge&quot;&gt;spades&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The equivalent POJO would look something like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public class Card {
	private int value;
    private Suit suit;

    public int getValue() {
    	return value;
    }

    public Suit getSuit() {
    	return suit;
    }

    public enum Suit {
    	HEARTS,
        DIAMONDS,
        CLUBS,
        SPADES
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;So what’s the simplest way of deserializing the &lt;code class=&quot;highlighter-rouge&quot;&gt;suit&lt;/code&gt; field into the Java object? A common approach is to create a type adapter (e.g. &lt;a href=&quot;https://code.google.com/p/google-gson/source/browse/trunk/gson/src/main/java/com/google/gson/TypeAdapterFactory.java#25&quot;&gt;LowercaseEnumTypeAdapterFactory&lt;/a&gt;) that will write the enum names in lower-case and map it to the correct constant.&lt;/p&gt;

&lt;p&gt;However, there’s an easier way to do it, using annotations! GSON provides five different annotations, as documented in the &lt;a href=&quot;http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/annotations/package-summary.html&quot;&gt;Java Doc&lt;/a&gt;. The one we’re interested in is called &lt;code class=&quot;highlighter-rouge&quot;&gt;SerializedName&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So let’s annotate our enum constants:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public class Card {
	private int value;
    private Suit suit;

    public int getValue() {
    	return value;
    }

    public Suit getSuit() {
    	if(suit == null) suit = Suit.UNKNOWN;
    	return suit;
    }

    public enum Suit {
    	@SerializedName(&quot;hearts&quot;) HEARTS,
        @SerializedName(&quot;diamonds&quot;) DIAMONDS,
        @SerializedName(&quot;clubs&quot;) CLUBS,
        @SerializedName(&quot;spades&quot;) SPADES,
        UNKNOWN
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Note that I also added another constant to the enum called &lt;em&gt;UNKNOWN&lt;/em&gt;. The reason being that if your server returns (for whatever reason) a value that isn’t part of your enum set, we’ll return &lt;code class=&quot;highlighter-rouge&quot;&gt;Suit.UNKNOWN&lt;/code&gt; in order to avoid a &lt;code class=&quot;highlighter-rouge&quot;&gt;NullPointerException&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;On the downside, this approach is case-sensitive. While solutions like the aforementioned &lt;a href=&quot;https://code.google.com/p/google-gson/source/browse/trunk/gson/src/main/java/com/google/gson/TypeAdapterFactory.java#25&quot;&gt;LowercaseEnumTypeAdapterFactory&lt;/a&gt; are more flexible because of their case-insensitivity, they usually require more code to be written and need to be registered with a &lt;a href=&quot;http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/GsonBuilder.html&quot;&gt;GsonBuilder&lt;/a&gt;. However, most of the time you should know what the  response of the server you’re talking to looks like, so the annotation-based approach is generally the simpler and more concise solution.&lt;/p&gt;</content><summary type="html">Here’s a little quick tip about something that I think is a less well-known feature of Google’s awesome GSON library:</summary></entry><entry><title type="html">How to include Jenkins CI build number in Android APK name &amp;amp; app label</title><link href="http://blog.jensdriller.com/how-to-include-jenkins-ci-build-number-in-android-apk-name/" rel="alternate" type="text/html" title="How to include Jenkins CI build number in Android APK name &amp; app label" /><published>2014-10-01T16:44:24+01:00</published><updated>2014-10-01T16:44:24+01:00</updated><id>http://blog.jensdriller.com/how-to-include-jenkins-ci-build-number-in-android-apk-name</id><content type="html" xml:base="http://blog.jensdriller.com/how-to-include-jenkins-ci-build-number-in-android-apk-name/">&lt;p&gt;Here are two quick tips that let you include your current Jenkins CI build number in both your .apk’s file name and/or the app label.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://blog.jensdriller.com/assets/2014/09/687474703a2f2f6a656e6b696e732d63692e6f72672f73697465732f64656661756c742f66696c65732f6a656e6b696e735f6c6f676f2e706e67.png&quot; alt=&quot;Jenkins&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When Jenkins executes a job, it sets some environment variables that you can refer to in your build script. Here’s a full list of all the variables that are available: &lt;a href=&quot;https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-JenkinsSetEnvironmentVariables&quot;&gt;Jenkins Set Environment Variables&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The one we’re interested in is called &lt;strong&gt;BUILD_NUMBER&lt;/strong&gt;.
And here’s how you can refer to it in your build script using the Groovy DSL:&lt;/p&gt;

&lt;h1 id=&quot;setting-the-apk-name&quot;&gt;Setting the APK name:&lt;/h1&gt;
&lt;p&gt;The default APK base name can be changed with the project’s &lt;code class=&quot;highlighter-rouge&quot;&gt;archivesBaseName&lt;/code&gt; property:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;defaultConfig {
	versionCode System.getenv(&quot;BUILD_NUMBER&quot;) as Integer ?: 0
    versionName 1.0
	project.ext.set(&quot;archivesBaseName&quot;, &quot;MyApp-&quot; + versionName + &quot;-&quot; + versionCode);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This code snippet would produce the following APK names:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;MyApp-1.0-55.apk&lt;/code&gt; for build no. 55 from Jenkins CI and&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;MyApp-1.0-0.apk&lt;/code&gt; for local builds from your IDE.&lt;/p&gt;

&lt;p&gt;It’s as simple as that. You can use &lt;code class=&quot;highlighter-rouge&quot;&gt;System.getenv(&quot;foobar&quot;)&lt;/code&gt; to grab any of the environment variables that are available.&lt;/p&gt;

&lt;p&gt;Ok, now let’s change the app label. That’s the actual name of your app, the way you see it in the app launcher.&lt;/p&gt;

&lt;h1 id=&quot;setting-the-app-label&quot;&gt;Setting the app label:&lt;/h1&gt;
&lt;p&gt;Let’s assume in your &lt;code class=&quot;highlighter-rouge&quot;&gt;AndroidManifest.xml&lt;/code&gt; you are referring to the app label like this: &lt;code class=&quot;highlighter-rouge&quot;&gt;android:label=&quot;@string/app_name&quot;&lt;/code&gt;
The Android Gradle plugin let’s you override resource values using the &lt;code class=&quot;highlighter-rouge&quot;&gt;resValue&lt;/code&gt; command. So in order to include your current Jenkins build number in the app label you can use the following snippet:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;resValue &quot;string&quot;, &quot;app_name&quot;, &quot;MyApp &quot; + (System.getenv(&quot;BUILD_NUMBER&quot;) ?: &quot;IDE&quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This will override the &lt;code class=&quot;highlighter-rouge&quot;&gt;app_name&lt;/code&gt; resource with whatever you pass as the 3rd parameter. In our case that’s again the Jenkins build number (if available) or “IDE” for local builds. Note that you can use that command in both the &lt;em&gt;defaultConfig&lt;/em&gt;, the &lt;em&gt;buildTypes&lt;/em&gt; and the &lt;em&gt;productFlavors&lt;/em&gt; closure. Pretty cool, eh?&lt;/p&gt;

&lt;p&gt;Btw I’ve been using the &lt;a href=&quot;http://groovy.codehaus.org/Operators#Operators-ElvisOperator(?:)&quot;&gt;Elvis operator&lt;/a&gt; to keep the commands nice and concise. Have you ever wondered why it’s called like that? Just turn your head to the left.&lt;/p&gt;

&lt;h1&gt;?:&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;http://blog.jensdriller.com/assets/2014/09/elvis-presley-ca-1950s-everett-2.jpg&quot; alt=&quot;Elvis&quot; /&gt;&lt;/p&gt;</content><summary type="html">Here are two quick tips that let you include your current Jenkins CI build number in both your .apk’s file name and/or the app label.</summary></entry><entry><title type="html">How to publish API level specific Android library implementations to Maven Central</title><link href="http://blog.jensdriller.com/how-to-provide-api-dependent-android-libraries-via-maven-central/" rel="alternate" type="text/html" title="How to publish API level specific Android library implementations to Maven Central" /><published>2014-09-27T10:02:00+01:00</published><updated>2014-09-27T10:02:00+01:00</updated><id>http://blog.jensdriller.com/how-to-provide-api-dependent-android-libraries-via-maven-central</id><content type="html" xml:base="http://blog.jensdriller.com/how-to-provide-api-dependent-android-libraries-via-maven-central/">&lt;p&gt;So what’s this article all about? I’m sure the title can’t be any more puzzling…&lt;/p&gt;

&lt;p&gt;I’ve recently gradlefied one of my open-source libraries: &lt;a href=&quot;https://github.com/jenzz/Android-UndoBar&quot;&gt;Android-UndoBar&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the requirements was to offer two implementations.
One variant with &lt;em&gt;minSdkVersion&lt;/em&gt; set to &lt;strong&gt;API Level 8&lt;/strong&gt; using &lt;a href=&quot;http://nineoldandroids.com&quot;&gt;nineoldandroids&lt;/a&gt; for the animations and another variant for &lt;strong&gt;API Level 15&lt;/strong&gt; using the native animations framework. The reason being that developers &lt;a href=&quot;http://chalup.github.io/blog/2014/06/15/minsdkversion-equals-15/&quot;&gt;targeting API Level 15&lt;/a&gt; or later shouldn’t have to include the 9OA library which is about &lt;em&gt;110 kb&lt;/em&gt; in size.&lt;/p&gt;

&lt;p&gt;Ok, so Gradle’s declarative build system seems to be the perfect problem solver for this. Let’s start with the &lt;a href=&quot;https://github.com/jenzz/Android-UndoBar/blob/master/library/build.gradle&quot;&gt;build.gradle&lt;/a&gt; file:
Firstly, we have to obviously specify the different API levels we wanna target. The &lt;code class=&quot;highlighter-rouge&quot;&gt;productFlavors&lt;/code&gt; closure is the right place for this:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;productFlavors {
        api8 {
            minSdkVersion 8
        }
        api15 {
            minSdkVersion 15
        }
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Secondly, we need to tell Gradle to publish all variants of our library which results in multiple .aar files being created:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;defaultPublishConfig &quot;api15Release&quot;
publishNonDefault true
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Also, since we’re now publishing multiple variants, we should specify a default config. I picked the API level 15 variant in my case. Note that you need to specify the full build variant, so it’s &lt;strong&gt;api15Release&lt;/strong&gt; and not just &lt;del&gt;&lt;strong&gt;api15&lt;/strong&gt;&lt;/del&gt;.
You can read more about these commands for library publication in the official &lt;a href=&quot;http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication&quot;&gt;user guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, don’t forget to list your dependencies. Since we only wanna include the 9OA library for the variant targeting API level 8, we use &lt;code class=&quot;highlighter-rouge&quot;&gt;api8Compile&lt;/code&gt; instead of just &lt;code class=&quot;highlighter-rouge&quot;&gt;compile&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dependencies {
    api8Compile files(&quot;libs/nineoldandroids-2.4.0.jar&quot;)
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Kuul, so that’s the Gradle part done.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Next, let’s write some Java!&lt;/p&gt;

&lt;p&gt;To restate the problem: For &lt;strong&gt;api8&lt;/strong&gt; we wanna use the 90A library to perform the animations, for &lt;strong&gt;api15&lt;/strong&gt; the native animations framework.&lt;/p&gt;

&lt;p&gt;So, how are we gonna do that? The main idea is to create an interface or an abstract base class to hold common logic and provide two API level specific implementations of it.&lt;/p&gt;

&lt;p&gt;Here’s an excerpt of the base class. I decided to call it &lt;a href=&quot;https://github.com/jenzz/Android-UndoBar/blob/master/library/src/main/java/com/jensdriller/libs/undobar/ViewCompat.java&quot;&gt;ViewCompat&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public abstract class ViewCompat {

    protected final View mView;

    public ViewCompat(View view) {
    	mView = view;
    }

    protected abstract void animateIn(long duration);

    /* omitted for brevity */
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;It just keeps a reference to the view we wanna animate and lists some abstract animation methods. No big deal.&lt;/p&gt;

&lt;p&gt;And now the two API level specific implementations.
&lt;a href=&quot;https://github.com/jenzz/Android-UndoBar/blob/master/library/src/api15/java/com/jensdriller/libs/undobar/ViewCompatImpl.java&quot;&gt;ViewCompatImpl&lt;/a&gt; for &lt;strong&gt;API Level 15:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import android.view.ViewPropertyAnimator;

public class ViewCompatImpl extends ViewCompat {

    private final ViewPropertyAnimator mViewPropertyAnimator;

    public ViewCompatImpl(View view) {
        super(view);
        mViewPropertyAnimator = view.animate();
    }

    @Override
    protected void animateIn(long duration) {
        mViewPropertyAnimator.cancel();
        mViewPropertyAnimator.alpha(1)//
                .setDuration(duration);
    }

    /* omitted for brevity */
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/jenzz/Android-UndoBar/blob/master/library/src/api8/java/com.jensdriller.libs.undobar/ViewCompatImpl.java&quot;&gt;ViewCompatImpl&lt;/a&gt; for &lt;strong&gt;API Level 8:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import com.nineoldandroids.view.ViewPropertyAnimator;

public class ViewCompatImpl extends ViewCompat {

    private final ViewPropertyAnimator mViewPropertyAnimator;

    public ViewCompatImpl(View view) {
        super(view);
        mViewPropertyAnimator = ViewPropertyAnimator.animate(view);
    }

    @Override
    protected void animateIn(long duration) {
        mViewPropertyAnimator.cancel();
        mViewPropertyAnimator.alpha(1)//
                .setDuration(duration);
    }

}
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;As you can see the code is pretty similar. The crucial difference is the import and use of &lt;code class=&quot;highlighter-rouge&quot;&gt;android.view.ViewPropertyAnimator;&lt;/code&gt; vs &lt;code class=&quot;highlighter-rouge&quot;&gt;com.nineoldandroids.view.ViewPropertyAnimator&lt;/code&gt;. It’s native animations vs 90A.&lt;/p&gt;

&lt;p&gt;So assuming you comply with the &lt;a href=&quot;http://developer.android.com/sdk/installing/studio-build.html#projectStructure&quot;&gt;default Android project structure&lt;/a&gt;, your library module should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://blog.jensdriller.com/assets/2014/09/Screen-Shot-2014-09-26-at-10-35-12.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://github.com/jenzz/Android-UndoBar/blob/master/library/src/main/java/com/jensdriller/libs/undobar/ViewCompat.java&quot;&gt;ViewCompat&lt;/a&gt; interface resides in the &lt;strong&gt;main&lt;/strong&gt; folder whereas the two API level specific implementations should be placed in respective &lt;strong&gt;api8&lt;/strong&gt; and &lt;strong&gt;api15&lt;/strong&gt; folders based on the product flavors we have defined earlier on.&lt;/p&gt;

&lt;p&gt;So that’s it. If you now create an instance of your &lt;code class=&quot;highlighter-rouge&quot;&gt;ViewCompat&lt;/code&gt; class, like so&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;ViewCompat viewCompat = new ViewCompatImpl(view);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Gradle will make sure to pick up the right implementation for you depending on the variant you are building. If you’re using Android Studio you will see that the &lt;em&gt;java&lt;/em&gt; package of the selected build variant gets a blue tint just like the main &lt;em&gt;java&lt;/em&gt; source package. So you can see right away which implementation is currently being used and will be picked up by the build system. Classes of other, inactive variants are badged with a red exclamation mark. Pretty cool!&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Stevenote#.22One_more_thing....22&quot;&gt;One more thing:&lt;/a&gt; If you’re publishing your library to &lt;a href=&quot;http://search.maven.org&quot;&gt;Maven Central&lt;/a&gt; (and you really should!), you have to specify the full build variant in your dependencies, just like this:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;compile 'com.github.jenzz.undobar:library:1.1:api15Release@aar'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;compile 'com.github.jenzz.undobar:library:1.1:api8Release@aar'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It’s not really nice, but it works!&lt;/p&gt;

&lt;p&gt;If you’re aware of better, cleaner way to achieve this, please let me know in the comments.&lt;/p&gt;</content><summary type="html">So what’s this article all about? I’m sure the title can’t be any more puzzling…</summary></entry></feed>
