Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle: What is javaMaxHeapSize "4g"?

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

dexOptions{     javaMaxHeapSize "4g" } 

I would like to know the exact purpose of this javaMaxHeapSize and what does that 4g means. What are other values I can give ?

like image 551
Kamalakannan J Avatar asked Nov 17 '15 06:11

Kamalakannan J


People also ask

What is Javamaxheapsize Android?

its the maximum Ram that gradle can use while creating the build(apk file).

How much RAM should I allocate to gradle?

You should stay at the sensible level of 2–4 gigabytes for gradle and 1–2 for dex.

What is settings gradle in Android?

The Gradle settings file The settings.gradle file, located in the root project directory, defines project-level repository settings and tells Gradle which modules it should include when building your app. For most projects, the file looks like the following by default: pluginManagement {

What is the use of gradle in Android?

gradle files are the main script files for automating the tasks in an android project and are used by Gradle for generating the APK from the source files.


2 Answers

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.

like image 57
Stanislav Avatar answered Oct 17 '22 05:10

Stanislav


This is an undocumented option to increase the heap size for dex operation: https://groups.google.com/d/msg/adt-dev/P_TLBTyFWVY/4TPJ2YY6khUJ

like image 24
Scadge Avatar answered Oct 17 '22 04:10

Scadge