Android Gradle: What is javaMaxHeapSize “4g”?

后端 未结 4 1900
春和景丽
春和景丽 2020-12-01 11:39

In an android project, build.gradle file, I have been through this line

dexOptions{
    javaMaxHeapSize \"4g\"
}

4条回答
  •  感情败类
    2020-12-01 12:20

    As it mentioned in the answer above, it is just an option to specify the maximum memory allocation pool for a Java Virtual Machine (JVM) for dex operation. And it's the same, as to provide to java the -xmx argument. Due to it's source codes from here, it's setter look like:

    if (theJavaMaxHeapSize.matches("\\d+[kKmMgGtT]?")) {
        javaMaxHeapSize = theJavaMaxHeapSize
    } else {
        throw new IllegalArgumentException(
                "Invalid max heap size DexOption. See `man java` for valid -Xmx arguments.")
    }
    

    So, you can see, that the accepted value should match the \d+[kKmMgGtT]? pattern, and hence not, it even refers to the man java to get to know, how to set the -xmx. You can read the man page here. And it says, that this flag:

    Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is chosen at runtime based on system configuration.

    In your example, 4g is 4 Gigabytes and this is a maximum heap size for dex operation.

提交回复
热议问题