Out of memory error: Java heap memory on Android Studio

后端 未结 12 862
-上瘾入骨i
-上瘾入骨i 2020-12-24 05:47

How do I fix java.lang.OutOfMemoryError: Java heap space when compiling my Android project?

I get this after I upgraded to version 1 of Android Studio.

12条回答
  •  盖世英雄少女心
    2020-12-24 06:24

    I had a similar issue on Android Studio 2.3.3. APK packaging would fail saying Java heap space when building from Android Studio and trying to process a 300MB .so library. In my case two things were needed to fix it. Your build.gradle should contain something like that:

    android {
        dexOptions {
            javaMaxHeapSize "4G"
        }
    }
    

    At the root of your project you need to have a file named gradle.properties containing the following:

    # That's needed for java to be able the create the APK with our 300MB native  library
    # Basically we grant java a 4GB heap.
    org.gradle.jvmargs=-Xmx4608m
    

提交回复
热议问题