title: Android studio 2.0 Preview 8 with gradle plugin 2.0.0-alhpa8, memory warning despite heap size to 4Gb
body: <p>I just updated to Android Studio version 2.0 Preview 8 and gradle plugin 2.0.0-alpha8. I noticed that now there's a warning in case the heap space is not big enough for dexing.</p>
  
  <p>As they say in the proper page (<a href="http://tools.android.com/recent">http://tools.android.com/recent</a>)</p>
  
  <blockquote>
    <p>In 2.0.0-alpha8 we've added some automatic diagnostics for this: if
    the build process is too small, we switch back to out-of-memory dexing
    and emit a build warning explaining how to bump up the Gradle daemon
    size. (We're also working on some additional related improvements for
    the next build after alpha8.)</p>
  </blockquote>
  
  <p>When I went building my project I got the following error:</p>
  
  <blockquote>
    <p>To run dex in process, the Gradle daemon needs a larger heap. It
    currently has 3641 MB. For faster builds, increase the maximum heap
    size for the Gradle daemon to more than 4g as specified in
    dexOptions.javaMaxHeapSize. To do this, set org.gradle.jvmargs=-Xmx4g
    as specified in dexOptions.javaMaxHeapSize in the project
    gradle.properties. For more information see
    <a href="https://docs.gradle.org/current/userguide/build_environment.html">https://docs.gradle.org/current/userguide/build_environment.html</a></p>
  </blockquote>
  
  <p>actually, I get a lot of these in a row. Which surprises me because that's what I see in my gradle.properties file (in my project home dir)</p>
  
  <pre><code>ANDROID_BUILD_TARGET_SDK_VERSION=23
  ANDROID_BUILD_TOOLS_VERSION=23
  ANDROID_BUILD_SDK_VERSION=23
  ANDROID_BUILD_MIN_SDK_VERSION=16
  org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
  </code></pre>
  
  <p>also, in the build.gradle of my main module, I put</p>
  
  <pre><code>android {
      dexOptions {
          incremental true
          javaMaxHeapSize "4g"
      }
  }
  </code></pre>
  
  <p>so I don't understand where the builder/dexer/compiler is getting that 3641MB value.</p>
  
  <p>Builds are extremely slow </p>
  
  <p>I Disabled instant run and now things are faster. 48-50 seconds for a build. I still get the same error but just once and not many times in a row.</p>
  
  <p>I'm on Linux, my ulimit -a is the following:</p>
  
  <pre><code>core file size          (blocks, -c) 0
  data seg size           (kbytes, -d) unlimited
  scheduling priority             (-e) 0
  file size               (blocks, -f) unlimited
  pending signals                 (-i) 31483
  max locked memory       (kbytes, -l) 64
  max memory size         (kbytes, -m) unlimited
  open files                      (-n) 1024
  pipe size            (512 bytes, -p) 8
  POSIX message queues     (bytes, -q) 819200
  real-time priority              (-r) 0
  stack size              (kbytes, -s) 8192
  cpu time               (seconds, -t) unlimited
  max user processes              (-u) 31483
  virtual memory          (kbytes, -v) unlimited
  file locks                      (-x) unlimited
  </code></pre>
  
  <p>Also, this is my studio.vmoptions file: <a href="https://gist.github.com/MarKco/1ae7918daf867a378a2f">https://gist.github.com/MarKco/1ae7918daf867a378a2f</a> I guess it's unedited. I could have a custom one, but I don't know where it could be.</p>