30 seconds to accelerate Android Studio/Gradle Construction

Source: Internet
Author: User

30 seconds to accelerate Android Studio/Gradle Construction

Android Studio has been used for development for more than a year. As the project grows and the dependent libraries increase, the build speed slows down. Now, it takes six minutes to build a release installation package, search for information on the Internet and find that you can use some configurations to speed up the process. I would like to share with you here.

Enable separate daemon of gradle

Create the gradle. properties file under the following directory:

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

Add the following content to the file:

  1. org.gradle.daemon=true 

You can also modify the gradle. properties file under the project to optimize it:

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

At the same time, these parameters can be configured in the gradle. properties file in the preceding user directory. This will not take effect for a project, but for all projects.

The above configuration file is mainly used to increase the size of the Java virtual machine running gradle, so that gradle can use an independent process during compilation, so that gradle can run in parallel.

Modify android studio configurations

In the configuration of android studio, enable the offline mode and modify the configuration. In fact, the configuration is the same as the previous section. The configuration in this section will only take effect during ide build, and the command line build will not take effect.

Command Line Construction

Based on the preceding configuration, you can add this parameter after the command when constructing a command line.--daemon --parallel --offline.

Use aar when introducing dependency Libraries

When using third-party dependent libraries on the internet, try to use aar. You can search by using mavenhttp: // gradleplease.appspot.com/?githuhttps://github.com/goddchen/mvn-reposearch.

You can also package your own library modules into aar. For more information, see stormzhang's article http://www.stormzhang.com/android/2015/03/01/android-reference-local /.


After such a hard job, it took me four or five minutes to build the project. Now it takes about 30 seconds to build the project. Of course, if you still cannot do this, you should replace the computer, ssd hard disk, and larger memory.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.