Android Studio is slow (how to speed up)?
Solution 1:
to sum it up
1) in AndroidStudio's settings > compile
enable checkbox named Compile independent modules in parallel
.
2) Under Help> Edit Custom VM Options
I have:
-Xms1024m
-Xmx4096m # <------ increase this to most of your RAM
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=440m
-XX:+UseCompressedOops
-XX:-HeapDumpOnOutOfMemoryError
-Dfile.encoding=UTF-8
P.S. - Some people say Note, instead of VM options, it's better to combine can be overriden by combining those lines into one line single command in gradle.properties, like this :
org.gradle.jvmargs=-Xms1024m -Xmx4096m ......
3) I have an old dual core with 4GB ram, running ubuntu. Qs command line option I have only --offline
(which specifies that the build should operate without accessing network resources). I also enabled the remaining checkboxes and now it's running ok:
Make project automatically
Use in-process building Configure on demand
Check the AndroidStudio's settings, under compile that the checkbox
Compile independent modules in parallel
is enabled.
Under Vmoptions I have
-Xmx2048m -XX:MaxPermSize=1024
I have an old dual core with 4GB ram, running ubuntu. Qs commandline option I have only --offline
, which specifies that the build should operate without accessing network resources. I enabled also the remaining checkboxes:
- Make project automatically
- Use in-process building
-
Configure on demand
and it is running ok
Edit
It is possible to provide additional options through studio.vmoptions
located at (just replace X.X with version):
Windows: go to
%USERPROFILE%\.AndroidStudioX.X\studio.exe.vmoptions
(orstudio64.exe.vmoptions
)Mac:
~/Library/Preferences/.AndroidStudioX.X/studio.vmoptions
Linux:
~/.AndroidStudioX.X/studio.vmoptions
(and/orstudio64.vmoptions
)
Increasing the value of -Xmx
should help a lot. E.g
-Xms1024m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=256m
-XX:+UseCompressedOops
will assign 4G as max heap, with initial value of 1G
Edit:
On windows the defaults are stored into C:\Program Files\Android\Android Studio\bin\*.vmoptions
. The IDE allows you to tweak those values through Help->Edit Custom VM options
(thanks to @Code-Read
for pointing it out).
EDIT 2:
Android studio 3.5 makes easier to change same of those values. Just go to:
Preferences > Appearance & Behavior > System Settings > Memory Settings
Solution 2:
Tips to make android studio fast:
Enable Offline Work:
- Click File -> Settings. Search for "gradle" and click in
Offline work
box. - Go to Compiler (in same settings dialog just below
Gradle
) and add--offline
toCommand-line Options
text box.
Improve Gradle Performance
gradle can be optimized too. The easy way is to modify the settings in global gradle.properties
(create it if not exists in the following folders: Windows - C:\users\your_name\.gradle\
; Linux- /home/<username>/.gradle/
; Mac- /Users/<username>/.gradle/
; ) and in that file, add these two lines:
org.gradle.daemon=true
org.gradle.parallel=true
For More: http://www.viralandroid.com/2015/08/how-to-make-android-studio-fast.html
Solution 3:
I detected another reason - Thumbs.db, which affected performance badly.
Go to File > Settings > Editor > File Types
and in field Ignore files and folders add this: Thumbs.db;
Now, Android Studio runs like a charm.
Solution 4:
Adding more memory helped me:
- Click "Help"
- Edit Custom VM Options
Android Studio 2.1.2 Edit Custom VM Options:
- Change values
like below:
-Xms512m
-Xmx2560m
-XX:MaxPermSize=700m
-XX:ReservedCodeCacheSize=480m
-XX:+UseCompressedOops
- Restart Android Studio
Solution 5:
Recommendations:
- MUST TO SAY: if you have any chance, spend some money for better PC(cpu), it's Most important ..
Tweaks:
- Some people say, that OS (Operating System) might cause much slowness. For example, XP or LINUX (or etc) was mentioned to perform 70% faster (don't know why..).
Disable VCS by
File > Settings > Plugins
and disable the following things :CVS Integration
;Git Integration
;GitHub
;Google Cloud ...
things;Subversion Integration
;hg4idea
;Editor is a resource eating too (especially on Large Monitors) and slow. Make it much much faster: click
Help > Edit custom VM options
and add these lines :-Dsun.java2d.d3d=false
-Dsun.java2d.opengl=true
save it and Restart Android Studio.- If Android Studio has a proxy server setting and can't reach the server then it takes a long time to build and waiting for a timeout. Removing it helps much.
File > Settings > Appearance & Behavior > System settings > HTTP Proxy
. -
Another Useful quote (from article):
Modules are expensive… On my current project I had to build some libraries from scratch and had to fork some that almost fitted my needs but not quite! If that modules are not constantly modified, it’s important to have this into consideration: the time needed to compile them from scratch, or even to check if the previous individual module build is up-to-date, can be up to almost 4x greater than to simply load that dependency as a binary
.jar/.aar
.Hint: run the
gradle build -profile
for an HTML report showing where the time goes regarding the build process.Note: keep that “unnecessary” modules in your version control system for the eventuallity of a quickfix/improvement in that dependency.
In your Gradle build script, use only
specific Google Service, like:compile 'com.google.android.gms:play-services-maps:...'
Instead of full Google Library:compile 'com.google.android.gms:play-services:...'
(Compile time goes from 2 minutes to around 25 seconds).Gradle configures every project before executing tasks, regardless of whether the project is actually needed for the particular build. In global
gradle.properties
adding this will help much:org.gradle.configureondemand=true
Surprisingly, some people say , they solved problem by reducing: 1) heapsizes to
-Xmx256m
(instead of higher values); 2) Emulator Ram-size (fromEdit AVD > Advanced Settings
);
Everyday Recommendations:
- Don't run multiple projects simultaneously.
- Don't close emulator after using once (use same emulator for running app each time; If you test large apps, better to use a real mobile phone instead of emulator).
- clean your project every time after running your app in emulator - click
Build > Clean Project
(orRebuild
), you can use keyboard shortcut.