How to reduce memory consumption when building in Android Studio?

The problem is that on my laptop all 4Gb operatives and to buy will not work (the laptop is old).
So you have to shamanism with the settings gradle. Basically, I have free about 2.5 GB, swap do not want to use.

Tried to set the following build settings in Studio in dialog for Gradle-Android Compiler:
--parallel --max-workers=2 --no-rebuild-Dorg.gradle.jvmargs=-Xmx1536m


Also tried to set the settings in the file $HOME_DIRECTORY/.gradle/
org.gradle.jvmargs=-Xms1024m -Xmx1024m -XX:MaxPermSize=512m

Also tried to set the settings in the gradle in the draft:
org.gradle.jvmargs=-Xms1024m -Xmx1024m -XX:MaxPermSize=512m

Environment variables are also tried to install:

In any case, it did not help, the process was trying to eat all available system resources and even more.

where you should change the project settings?
July 8th 19 at 16:39
1 answer
July 8th 19 at 16:41
In General, if someone is interesting in my experience.
Cut memory the gradle daemon because it is not too much, and by default, eats well.

A major role in the Assembly process packaging plays, though perhaps not properly named. Here, the memory consumption can be adjusted as follows:
android {
dexOptions {
maxProcessCount 1
javaMaxHeapSize '1200m'
Figure 1200Мб achieved empirically, will depend on the application.

I am also the resources idea cut, she was not offended:

Find more questions by tags AndroidAndroid StudioGradle