About 1 time in 3 when doing a build with Gradle I get:
A failure occurred while executing com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable
... a thousand lines later...
Caused by: java.lang.OutOfMemoryError: Java heap space
And then the next time it works. So that's exactly the level of quality I've come to expect from Gradle in particular and everything about Android in general.