When I add PubNub to my Android app, why do I get an "Excecution failed for task" error when I try to build?

The full error may look some like this:

Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/jdk1.8.0_05.jdk/Contents/Home/bin/java'' finished with non-zero exit value 3

The solution should be add the following to your gradle file:

dexOptions {
    javaMaxHeapSize "4g"