title: Android Studio - Gradle build failing - Java Heap Space
body: <p>Android Studio 2.2.3.  I've been building an APK for android with my current project with success until very recently.  As far as I know, nothing was changed except a data file, and my "Build APK" step mysteriously started failing with this message in the gradle console:</p>
  
  <pre><code>FAILURE: Build failed with an exception.
  * What went wrong:
  Execution failed for task ':VrSamples:Native:myproject:Projects:Android:packageDebug'.
  &gt; Java heap space
  </code></pre>
  
  <p>and in my "messages" window I see this error:</p>
  
  <pre><code>Error:Execution failed for task ':VrSamples:Native:myproject:Projects:Android:packageDebug'.
  &gt; Java heap space
  mple, the following line, in the gradle.properties file, sets the maximum Java heap size to 1,024 MB:
  &lt;em&gt;org.gradle.jvmargs=-Xmx1024m&lt;/em&gt;
  &lt;a href="http://www.gradle.org/docs/current/userguide/build_environment.html"&gt;Read Gradle's configuration guide&lt;/a&gt;&lt;br&gt;&lt;a href="http://docs.oracle.com/javase/7/docs/technotes/guides/vm/gc-ergonomics.html"&gt;Read about Java's heap size&lt;/a&gt;
  </code></pre>
  
  <p>I've tried many things:</p>
  
  <ul>
  <li>Reset version control to previous version I know was generating APK's fine</li>
  <li>Re-clone the entire project in a new location to rule out and intermetiate files that might be pulled in with the .gitignore, to guarantee it's a fresh build</li>
  <li>Rebooted my computer</li>
  <li>re-installed android studio</li>
  <li>Run the clean step, rebuilt, manually deleted intermediate files</li>
  <li>Added org.gradle.jvmargs=-Xmx1024m to my gradle.properties file</li>
  <li>increased the 1024m to 4096m</li>
  <li>manually increased the -Xmx value in both Android Studio\bin\studio.exe.vmoptions and the 64-bit equivalent</li>
  </ul>
  
  <p>I'm puzzled as to why I'm suddenly hitting this issue now, and why I can't seem to be able to re-create the APK's I've been building without problems until recently.  As far as I'm aware, I also haven't updated any libraries either.  </p>
  
  <p>Would appreciate any suggestions to resolve this issue, tips on how to debug this kind of thing down the road, etc.</p>