13 March 2015 at 17:17 #730
Moving around Android Studio and port XMTV Player on it, I faced optimizing Android Studio and Gradle. Nevertheless, it can be annoyingly slow at times. Especially after version 1.0 was released, random lags occur more often than ever, to such an extent that typing a single line of code can make the whole program freeze several times.
Here I will share what I have done to speed up development and compilation process. Hope this will help you too!
It’s hard to say which one is better – Android Studio or Eclipse. Both of them have their pros and cons.
After fresh install and import of whole project in Android Studio I started to experience inability to move my mouse, no matter where it is when project is open. Started googling and trying many options.. After hours ov heavy googling and trying I was able to make it work flawlessly by applying the following settings :
This sluggishness hindered our workflow a lot, so each of us set out to find ways to deal with it. Here are a few tricks we’ve come across:
Increasing Android Studio’s Memory Heap:
Android Studio, like other Java applications, is known for hogging an insane amount of memory while running. Unless enough memory is allocated to the IDE at launch, disk swapping will start kicking in and if you’re not using a SSD, God bless you.
Open the file [AS Installation Folder]\studio64.exe.vmoptions or studio.exe.vmoptions, depending on which version you’re using.
For Mac die-hard you can find the file at /Applications/Android Studio.app/Contents/bin/studio.vmoptions. Thanks Yonatan and Kent for pointing that out.
In it you’re likely to find these two lines at the top:
Increase the two values to something reasonable, e.g. -Xms256 and -Xmx1024. You can boost the second value to 2048 if you like; my coworker whose computer has 8G of RAM doesn’t find any issue with -Xmx2048 either.
After you’re done, restart AS and if you’ve checked Show memory indicator in Settings/Appearance, you’ll see something like this at the bottom-right corner.
Android Studio’s Allocated Memory Heap
In my case, this works like a charm. No more stutters while typing.
Speeding up Gradle build time
One of the reasons developers are still hesistant to ditch Eclipse is because of Gradle.
Although it’s indeed a nice build system and there are many benefits to using it, even the simplest Gradle calls are pretty slow and time-consuming. As a consequence, our workflow includes a lot of unavoidable waiting, and sometimes we even forget what needs to be tested after AS finishes its laborious building processes.
There are a few things we do to boost Gradle’s speed.
First, go to Settings/Compiler and check everything, except for the 2nd option Make project automatically. For VM Options, we use these configurations:
-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Next, add the following lines to gradle.properties in your project directory:
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Refer to this blog post for a detailed explanation for these settings.
You must be logged in to reply to this topic.