Android Studio is very slow

2019-04-08 20:41发布

问题:

I have a project with about 20 modules inside. Gradle clean takes about 5min. As ell if i add a new module gradle update projects needs more than 5min.

There are no dependencies to external libraries. Dependencies are only inside the project between several modules.

I had same Project without gradle and it worked fine. I did not convert the old project to gradle. I have created a new project with the file structure recomended by gradle. But with this performance this is not very usefull...

Any idea what's going wrong with gradle?

回答1:

Just create a file named gradle.properties in the following directory:

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

Add this line to the file:

org.gradle.daemon=true

Source: https://www.timroes.de/2013/09/12/speed-up-gradle/



回答2:

My Android studio in Ubuntu was too slow and I have done these things to speed up to very fast. in the welcome screen click (you can also go to it by file>close project)

 >configure>project default>
>code style > compiler > 
  click the following options 
     -make project automatically
     -use in process build
     -configure on demand
then in compiler (below the first one)
     - give build process heap size as 1000 or 1500
       (it will take a lot of RAM but Android studio will be extremely fast)
       give the same heap size for Android build and gradle build in the below tabs

Hope it will help



回答3:

This could help too:

If you notice that Android Studio works slowly, consider the possibility to reduce the number of folders under antivirus protection.

Each antivirus check in your project consumes resources. You can significantly improve the performance, if you exclude certain folders from the antivirus protection.

Source: tip of the day from Android Studio.



回答4:

Set Custom VM options in Help-->EDIT Custom VM options.

-Xms1024m
-Xmx2048m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=256m
-XX:+UseCompressedOops

File-->Setting-->Build Executions

Compiler-->Command-line options set --offline.

Gradle-->check OfflineWork.

Launch SDK Manager--> Download HAXM Installer.

Now Android studio work like charm in Windows. Happy Coding:)



回答5:

On Windows, I have found than my anti-spyware consider the jar files like archive. So I had exclude them from scan, but it's not very secure ....



回答6:

I have a MacBook that I use for Android Studio and when I started out it was completely unusable taking 5 to 10 minutes for a build even for the smallest app. The Android emulator still does not work. Two things made the system usable. More memory added - I originally had 2GB and now have 8GB ... and using actual Android hardware connected via USB.

My MacBook spec is as follows - macOS Sierra Version 10.12.3 MacBook (13-inch, Mid 2010) Processor 2.4 GHz Intel Core 2 Duo Memory 8 GB 1067 MHz DDR3 Graphics NVIDIA GeForce 320M 256 MB Serial Number - oops!

The phone I use for build is an LG Sporty using Android 4.4.2 KitKat

Android Studio has the Intel HAXM extensions loaded and switched on.