[Deprecated] migrated to notion
Open or create a file called gradle.properties in .gradle
directory. Inside the file, add following
org.gradle.parallel=true
: Allow you to build multiple modules in the same project at the same timeorg.gradle.daemon=true
will turn on daemon so that every time we build the application, it doesn’t need to rerun the entire Gradle application every time.
By default, Android Studio detects your installed RAM and configure the memory allocation automatically. However, the default value usually is too small to handle Android Studio. We can override it by opening it inside the Android Studio. Click Help > Edit Custom VM Options.
There are 4 config values you need to change:
-
-Xms1G
: Specifying the initial size of the memory allocation pool for JVM. For PC with 8GB of RAM, start specifying with -Xms1G is a sweet spot. -
-Xms2G
: Specifying the maximum size of the memory allocation pool for JVM. For PC with 8GB of RAM, -Xmx2G is a good value to start. -
-XX:MaxPermSize=1G
: Specifying the permanent generation. This allocated memory holds compiled class pages. If it’s already full, then it triggers a full garbage collection to clean the old unreferenced classes. I would say start with -XX:MaxPermSize=1G for a PC with 8GB of RAM. Some people said it’s not necessary anymore in Java 8, but I do still configure it anyway. -
-XX:ReservedCodeCacheSize=512m
: Specifying the reserved code cache size. I don’t really understand what this config affects. But, still configure it anyway. In a PC with 8GB of RAM we can start with -XX:ReservedCodeCacheSize=512m.
./gradlew android:assembleDebug --profile
--profile
flag will tell gradle to measure the time taken to execute each task and dump that data into HTML file. You can find that report under /projectDir/build/reports/profile directory.