diff --git a/app/app.iml b/app/app.iml
index 2b5e23654951bb58355a1db4dfdd43a8858409fc..f00cf65903a2f74f71544ad4ccbceea352334f45 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="640gAndroidUploader" external.system.module.version="0.2.0" type="JAVA_MODULE" version="4">
+<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="640gAndroidUploader" external.system.module.version="0.2.1" type="JAVA_MODULE" version="4">
   <component name="FacetManager">
     <facet type="android-gradle" name="Android-Gradle">
       <configuration>
@@ -106,6 +106,8 @@
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
       <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/reports" />
+      <excludeFolder url="file://$MODULE_DIR$/build/test-results" />
       <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
     </content>
     <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
diff --git a/app/build.gradle b/app/build.gradle
index 98bf2515554a17c60916fcce4e2cf708cd4d3591..d1bc88b8c7d9d4dcb503b57b3a6ee9c7100da8dc 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -4,14 +4,25 @@ plugins {
 
 apply plugin: 'com.android.application'
 
+def gitVersion() {
+    def process = ['sh', '-c', 'git tag -l | grep -c ".*" -'].execute().text.trim()
+    return process.toInteger() + 1
+}
+
 android {
     compileSdkVersion 21
     buildToolsVersion "23.0.3"
 
+    applicationVariants.all { variant ->
+        variant.resValue "string", "versionName", variant.versionName
+    }
+
     defaultConfig {
         applicationId "info.nightscout.android"
         minSdkVersion 15
         targetSdkVersion 21
+        versionName project.properties['version']
+        versionCode gitVersion()
     }
 
     buildTypes {
@@ -28,8 +39,59 @@ android {
     }
 }
 
+task signRelease << {
+    def command = [
+            'jarsigner',
+            '-verbose',
+            '-sigalg',
+            'SHA1withRSA',
+            '-digestalg',
+            'SHA1',
+            '-keystore',
+            '/Users/lgoedhart/keystores/nightscout_android.jks',
+            'app/build/outputs/apk/app-release-unsigned.apk',
+            'nightscoutandroidkey'
+    ]
+
+    def proc = new ProcessBuilder(command)
+            .redirectOutput(ProcessBuilder.Redirect.INHERIT)
+            .redirectInput(ProcessBuilder.Redirect.INHERIT)
+            .redirectError(ProcessBuilder.Redirect.INHERIT)
+            .start()
+
+    proc.waitFor()
+
+    if (0 != proc.exitValue()) {
+        throw new RuntimeException("Could not sign APK.")
+    }
+}
+
+task zipalignRelease << {
+    def command = [
+            '/Users/lgoedhart/Library/Android/sdk/build-tools/23.0.3/zipalign',
+            '-v',
+            '4',
+            'app/build/outputs/apk/app-release-unsigned.apk',
+            'app/build/outputs/apk/640g-android-uploader.apk'
+    ]
+
+    def proc = new ProcessBuilder(command)
+            .redirectOutput(ProcessBuilder.Redirect.INHERIT)
+            .redirectInput(ProcessBuilder.Redirect.INHERIT)
+            .redirectError(ProcessBuilder.Redirect.INHERIT)
+            .start()
+
+    proc.waitFor()
+
+    if (0 != proc.exitValue()) {
+        throw new RuntimeException("Could not align APK.")
+    }
+}
+
 release {
     tagTemplate = 'v${version}'
+    buildTasks = ['assembleRelease']
+    afterReleaseBuild.dependsOn 'signRelease', 'zipalignRelease'
 }
 
 dependencies {
diff --git a/app/gradle.properties b/app/gradle.properties
index ac7979dd90ee002f07dc5cac9d2ffd51bebde850..632458877ebd68b500cdfeb688d8b59dca8934c2 100644
--- a/app/gradle.properties
+++ b/app/gradle.properties
@@ -1 +1 @@
-version=0.2.1
\ No newline at end of file
+version=0.2.0-SNAPSHOT
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9b3a7d6a6b8a9c6f39777c2d044ea886888dbcaa..1f9b4a4ed20750d7b0f41a3bffec10f7c2d2a1f9 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,8 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="info.nightscout.android"
-    android:versionCode="1"
-    android:versionName="@string/version" >
+    >
 
     <uses-sdk
         android:maxSdkVersion="21"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b629689a66a684f245072f17b061517684dd6e54..a0f180310dcbfa9aa5780bbae904dcb34c6e8746 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -13,7 +13,6 @@
     <string name="eula_title">Disclaimer</string>
     <string name="eula_accept">Accept</string>
     <string name="eula_refuse">Refuse</string>
-    <string name="version">0.2.0</string>
     <style name="ButtonText">
     <item name="android:layout_width">fill_parent</item>
     <item name="android:layout_height">wrap_content</item>
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index 6a7d8a6f18e4337b4cd6662227ef89260042767a..fbbea6a6c9e529538034312e1039909ee03f9843 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -59,7 +59,7 @@
 	<PreferenceCategory android:title="App Version">
 	      <Preference 
 		 android:key="version"
-		 android:title="@string/version" />
+		 android:title="@string/versionName" />
    		 </PreferenceCategory>
     <PreferenceCategory android:title="Debug">
     <ListPreference