Speed up your builds… without upgrading your hardware

I wish every build could look like this :) Often the only way to (really) speed up slow builds is to add more RAM, replace the old HDD with an SSD or buy a complete new PC (or Laptop). All those solutions requires investing (a lot of) money. What if we can just keep current hardware and delegate the build to another, more powerful, machine? I usually develop for Android, and everyone knows that Android builds are slow....

April 27, 2018 · 3 min

Migrate to Android Studio 2.3

New features Android Studio 2.3 has finally been released in the Stable Channel. There are many improvements compared to version 2.2, including: Instant run: now there are two different icons, one for restart the app and another one for apply changes without restart. Build cache: it’s used to have faster clean builds by caching exploded AARs and pre-dexed external libraries. App Links Assistant (Tools → App Link Assistant): it allows you to create new intent filters for your URLs, declare your app’s website association through a Digital Asset Links file, and test your Android App Links support....

March 8, 2017 · 2 min

Android - Enable app features at compile time

Sometimes some fetaures of your app must behave differently for different flavors o build type. Think about when you need to enable logging for a specific flavor only, or you have to disable crash reporting for your “dev build”. All this behaviours can be configured at compile time, insted of using many if/else blocks that are evaluated at runtime. In the following example I’ll use Gradle and Dagger. Use case: enable crash reporting only for production flavor....

January 28, 2016 · 3 min

OutOfMemoryError while compiling Android projects

Have you ever got a OutOfMemoryError while compiling an Android project, just like this? {% raw %} :app:dexDebug Unknown source file : Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space Unknown source file : 1 error; aborting :app:dexDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1 {% endraw %} The quick solution is: add javaMaxHeapSize to dexOptions in your build....

November 15, 2015 · 1 min

Auto-increment versionCode in build.gradle file

Starting from this blog post by Bryan Rosenbaum, here is a gradle task to auto increment versionCode inside your build.gradle file. import java.util.regex.Pattern ... task incrementVersionCode << { println(":incrementVersionCode - Incrementing Version Code...") def buildGradleFile = file("build.gradle") def patternVersionCode = Pattern.compile("versionCode (\\d+)") def buildGradleFileText = buildGradleFile.getText() def matcherVersionCode = patternVersionCode.matcher(buildGradleFileText) matcherVersionCode.find() def mVersionCode = Integer.parseInt(matcherVersionCode.group(1)) def mNextVersionCode = mVersionCode + 1 def manifestContent = matcherVersionCode.replaceAll("versionCode " + mNextVersionCode) println(":incrementVersionCode - current versionCode=" + mVersionCode); println(":incrementVersionCode - next versionCode=" + mNextVersionCode); buildGradleFile....

November 4, 2014 · 1 min