问题
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?
回答1:
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
回答2:
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.
回答3:
You can avoid this gradle build process, on times gradle build is not necessary.
- Use: Run > Edit Configurations.
- In this new window, click the green plus icon > Android App.
- 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.
- 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.
回答4:
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.
回答5:
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.
回答6:
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
来源:https://stackoverflow.com/questions/36861943/any-solution-for-android-studio-slow-gradle-build-and-high-disk-usage