How to speed up Android Studio + Gradle?

Asked

Viewed 14,768 times

9

I’m going through the hardest time using Android Studio due to the delay in the project compilation process. What settings improve performance of Android Studio + Gradle?

  • It’s not my area of programming, but as a general rule, it’s nice to provide as much detail as possible setup, so it becomes easier to give a correct diagnosis. You can see more details in [Ask]. Good luck!

  • How many Giga RAM are available on the computer?

1 answer

6


There are some settings that can help to give an accelerated in the process of build of Gradle:

  1. Always use the latest versions of Android Studio, Gradle Plugin and Gradle.
  2. Perform the following settings:

    • Configure your build process using daemon Gradle (decreases startup time of process that makes the build). Since with the deamon the process will not need to be initialized always (only the first time).
    • Enable build in parallel (causes independent modules to be compiled in parallel). This setting is good if your computer has more than one core.
    • Adjust the memory used by Gradle.

    All this through the gradle.properties.

    You can both set up in your gradle.properties from the root of your project or globally at seu_home/.gradle/gradle.properties.

    # Project-wide Gradle settings.
    
    # IDE (e.g. Android Studio) users:
    # Settings specified in this file will override any Gradle settings
    # configured through the IDE.
    
    # For more details on how to configure your build environment visit
    # http://www.gradle.org/docs/current/userguide/build_environment.html
    
    # The Gradle daemon aims to improve the startup and execution time of Gradle.
    # When set to true the Gradle daemon is to run the build.
    # TODO: disable daemon on CI, since builds should be clean and reliable on servers
    org.gradle.daemon=true
    
    # Specifies the JVM arguments used for the daemon process.
    # The setting is particularly useful for tweaking memory settings.
    # Default value: -Xmx10248m -XX:MaxPermSize=256m
    org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    
    # When configured, Gradle will run in incubating parallel mode.
    # This option should only be used with decoupled projects. More details, visit
    # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
    org.gradle.parallel=true
    
    # Enables new incubating mode that makes Gradle selective when configuring     projects. 
    # Only relevant projects are configured which results in faster builds for large multi-projects.
    # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
    org.gradle.configureondemand=true
    

    Or by settings by Settings of Android Studio:

Settings do Android Studio

  1. Do not use the self-importance of Android Studio, there is a unsolved bug that leaves the IDE slower.

  2. Use the mode offline of Android Studio, ignoring dependency update checks:

Localização da configuração de modo offline

References

  1. https://stackoverflow.com/a/19500539/3404639
  2. https://stackoverflow.com/a/23648341/3404639
  • Thanks, Wakim. You went straight to the point and didn’t keep stalling asking how much RAM my machine has. I’ll make these settings. Thank you.

  • @Wakim, it didn’t help the settings :(I think the way will be an upgrade

  • @Wellingtonavelino, really with the amount of libraries we use, the build becomes very heavy. Remembering that each of them needs to go through the build process along with apk to create DEX. A while ago google started a new build tool called Jack and Jill, which is still very experimental (not having many features like note processing) which tends to reduce build time. Another solution that usually helps is to always be with the latest version of Gradle (current 2.6), then just check in your Gradle-wrapper properties..

  • So @Wakim, I use AS every day at work I have no problems, at home I am working on an app I got this doubt, but I played more 8gb and is quiet now haha, thanks for the comment! Go Android!

  • @Wakim thank you very much, great reply!

  • Excellent response. Greatly accelerated Build.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.