Any solution for Android Studio slow gradle build and high disk usage?
Asked Answered
G

7

26

My 4GB RAM, Intel Core i5 system came down down to its knees with high disk and RAM usage by Android Studio(I can see it in the task manager, nothing else is using the RAM and disk). The gradle build takes about 10-15 mins for a simple project.

Is there any solution?

Goop answered 26/4, 2016 at 10:15 Comment(5)
My PC is 4GB RAM, core i3, it is not that much slow, check if there is any update you need to install, another thing you should try is running Android studio as admin, I feel it is little smooth with admin.Darleen
You need a beefier machine. Yes, its ridiculous. And I think Eclipse, while not great, did a better job of it. But they aren't moving back that way. 8 GB is really the minimum, 16 or more is better. Its pretty fast on my new 64 GB machine.Lamppost
One way you can help- don't use an emulator. That's another big chunk of RAM. Use a real device so more RAM can go to the IDE.Lamppost
yes, Gabe is right, you can consider using a device in place of emulator .Darleen
I don't see why there is a downvote!! Thanks for your solutions, I will buy RAM this weekend.Goop
I
40

You need to upgrade your PC though but there are few things you can do to make it faster

1. Increase the memory size of Android Studio:

Open the file located at /bin/studio.vmoptions and Change the content from

-Xms128m
-Xmx800m

to

-Xms256m
-Xmx1024m

Xms specifies the initial memory allocation pool. Your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory.

Save the studio.vmoptions file and restart Android Studio.

2. Improve Gradle performance:

Create a file named gradle.properties in

/home/<username>/.gradle/ (Linux)
/Users/<username>/.gradle/ (Mac)
C:\Users\<username>\.gradle (Windows)

and add the line:

org.gradle.daemon=true

This helps a lot, with org.gradle.daemon set to true Gradle reuses computations from previous builds and cache information about project structure, files, tasks etc. in memory so it won’t have to start up the entire Gradle application every time.

Source

Iatrochemistry answered 26/4, 2016 at 10:45 Comment(9)
All these steps reduced the build time to 37 seconds. That's great performance improvement. Thanks.Goop
Is it the Gradle Daemon that is making most of the difference?Spirant
yeah it reuses computations from previous builds and cache information about project structure, files, tasks etc. in memory so it won’t have to start up the entire Gradle application every time.Iatrochemistry
I reverted the offline work option and didn't really notice a difference. I'm leaving it stock.Spirant
The last option is not really necessary it just specifies that the build should operate without accessing network resources. which makes the build somewhat faster. I think i will remove that extra step from the answer to make it betterIatrochemistry
none of this stuff works for me, I have mbp 2015 8gb, something's not rightVersicle
studio.exe.vmoptions and studio64.exe.vmoptions showing this folder in my laptop but not able to change the value -Xms256m and -Xmx1024m . always getting this message "please check if this file is opened in another program". how to solve this please guideEnterostomy
@AmitVerma make sure Android Studio is completely close when editing those files.Iatrochemistry
@Max closed everything and restart the laptop, but still getting the same message, could you help me, pleaseEnterostomy
B
3

For me Android Studio slowness has a strong relationship with Task Manager showing a 100% disk usage most of time. I have done three things on my Windows 10:

1 - Disable "Windows Search" service

2 - Disable "Superfetch" service

3 - If you have Google Chrome, go to Settings> Show Advanced Settings ...> Privacy> "Prefetch resources to load pages more quickly" and untick it.

Disk usage is now far lower and Android Studio builds far faster. Hope it will help!

PD: To disable a service pres WindowsKey + R then enter services.msc, find the service > right click > Properties > Init > Disable.

Bregma answered 11/5, 2017 at 18:4 Comment(0)
V
2

You can avoid this gradle build process, on times gradle build is not necessary.

  1. Use: Run > Edit Configurations.
  2. In this new window, click the green plus icon > Android App.
  3. on the right frame, go to "Before launch", mark "gradle-aware Make", and click the red minus icon. Give this configuration a name, and press "OK" button.
  4. From now on, every time you run your app, you can choose your new configuration, and no gradle build process will be generated.

This may not apply your changes in code on runtime, so you highly recommended to leave the original configuration too for times you need the gradle build.

enter image description here

Vapor answered 15/12, 2016 at 9:22 Comment(0)
W
1

My 4GB RAM

Get more RAM. Android Studio takes a bit. JVM takes a bit. OS needs some. 4GB is not going to work really.

build takes about 10-15 mins

because it swaps as hell. Get more RAM.

Whitmer answered 26/4, 2016 at 10:18 Comment(3)
How to get more RAM?According
By purchasing additional memory?Whitmer
Hi, I have been banned from reviewing for 8 months, how may I decrease it? 8 months is too longAccording
D
0

Get expendable RAM upto 8Gb

My laptop has intel i3 processor with 8Gb expendable RAM and I have alloted 4 Gb of RAM to Android Studio only. It runs fast. And one more important thing you may use Genymotion instead of inbuilt Android Studio AVD that is much faster and less system images will be created in your system which will reduce the usage of your hard disk.

Dilley answered 26/4, 2016 at 10:30 Comment(0)
F
0

For Ubuntu

sudo dpkg --add-architecture i386

sudo apt-get update

sudo apt-get install libncurses5:i386 libstdc++6:i386 zlib1g:i386

i found here Android Studio fails to build new project, timed out while wating for slave aapt process

Fluorine answered 17/11, 2016 at 13:40 Comment(0)
D
0

Brother I had same problem with my laptop(i3 second generation 8 gb). I have replaced my 500 gb hdd with 500 gb ssd. Now disk active stays just below 3 percent mostly.

Discard answered 26/2, 2022 at 23:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.