Easy Ways to Speed Up Android Studio

Yeah, I know it’s an iPhone, not an Android

Android Studio is famous for a thing, it eats so much memory. I have been working with Android Studio with only 4GB of RAM for quite some time. But, right now I’ve already upgraded my memory. However, before I decided to upgrade my memory I notice there are several improvements in configuration to speed things up a little bit. Even though if we only have 4GB of RAM (or maybe less).

Gradle Tweaks

Open or create a file called gradle.properties in C:\Users\<username>\.gradle (Mac and Linux users can adjust the value). Inside the file, add these lines. The org.gradle.parallel will allow you to build multiple modules in the same project at the same time. Meanwhile, the org.gradle.daemon will turn on daemon so that every time we build the application, it doesn’t need to rerun the entire Gradle application every time.

Memory Allocation Tweaks

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 only 4 configs you need to change here:

  • -Xms: 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.
  • -Xmx: 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: 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: 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.

Wrap Up

That’s all of the main things you need to change to speed up the IDE and the build time of Android Studio. You can experiment the value a bit, by adding more and more allocation after you think that it’s stable enough and fast enough to use. If you have 4GB of RAM, you can turn that config down a little bit. In my experience, PC with 4GB of RAM are more affected by this tweak compared to PC with 8GB of RAM. Hopefully, it will help you to build Android applications faster and thank you for reading.

Half Data Engineer, Half Software Engineer