3

I have a ionic project. The app was build and run in my android phone successfully before. But suddenly from someday, when I run command "ionic cordova run android" I get the build error as below:

Execution failed for task ':transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space

I have tried "cordova clean" to synchronise the cordova plugin. But it doesn't work..

How to solve this problem?

shizhen
  • 12,251
  • 9
  • 52
  • 88
lei lei
  • 1,753
  • 4
  • 19
  • 44

2 Answers2

6

Open gradle.properties under your project root directory and add/modify below line to

org.gradle.jvmargs=-Xmx3536m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError

Specifies the JVM arguments used for the daemon process. The setting is particularly useful for tweaking memory settings. Change -Xmx3536m to a larger value if this still does not meet your requirement.

And, modify your module level build.gradle

android {
    ...
    dexOptions {
        javaMaxHeapSize "2g"
    }
    ...
}
shizhen
  • 12,251
  • 9
  • 52
  • 88
  • Thanks. But I could not find gradle.properties.. where is it? – lei lei Feb 11 '19 at 03:39
  • under your project root directory, there should be a project scope `gradle.properties` which only applies to your current project. If you don't have this file, you can just create it and add the line I said above. – shizhen Feb 11 '19 at 03:40
  • Also, there is a **global** `gradle.properties` which is usually under your computer home directory, e.g. on macOS, it is under `~/.gradle/gradle.properties`, which is applicable to all your projects. – shizhen Feb 11 '19 at 03:43
  • New error is:FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Picked up _JAVA_OPTIONS: -Xmx256M – lei lei Feb 11 '19 at 03:52
2

Add this in your build.gradle file-

dexOptions {
    javaMaxHeapSize "4g"
}

also you could follow - Android Studio Google JAR file causing GC overhead limit exceeded error