Optimize Android Studio/gradle Build

Source: Internet
Author: User

optimize Android Studio/gradle build

using Android Studio to open, with the increase of the project, relying on the increase in the library, the construction speed is more and more slow, now the slowest 6 minutes to build a release of the installation package, find information on the Internet, found that can be configured to speed up, here to share with you.

turn on gradle separate daemon

Create the Gradle.properties file under the following directory:

  • /home/<username>/.gradle/(Linux)
  • /users/<username>/.gradle/(MAC)
  • C:\users\<username>\.gradle (Windows)
  • Copying the following configuration Gradle.properties files can also be optimized:
    1. # project-wide Gradle settings.
    2. # IDE (e.g. Android Studio) Users:
    3. # Settings specified in this file would override any Gradle Settings
    4. # configured through the IDE.
    5. # For more details about how to configure your build environment visit
    6. # http://www.gradle.org/docs/current/userguide/build_environment.html
    7. # The Gradle daemon aims to improve the startup and execution time of Gradle.
    8. # When set to True the Gradle daemon are to run the build.
    9. # todo:disable daemon on CI, since builds should is clean and reliable on servers
    10. Org.gradle.daemon=true
    11. # Specifies the JVM arguments used for the daemon process.
    12. # The setting is particularly useful for tweaking memory settings.
    13. # Default Value:-xmx10248m-xx:maxpermsize=256m
    14. Org.gradle.jvmargs=-xmx2048m-xx:maxpermsize=512m-xx:+heapdumponoutofmemoryerror-dfile.encoding=utf-8
    15. # when configured, Gradle'll run in incubating parallel mode.
    16. # This option is should only is used with decoupled projects. More details, visit
    17. # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
    18. Org.gradle.parallel=true
    19. # enables new incubating mode that makes Gradle selective when configuring projects.
    20. # only relevant projects is configured which results in faster builds for large multi-projects.
    21. # Http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
    22. Org.gradle.configureondemand=true
    Copy the code at the same time these parameters can also be configured in the previous user directory in the gradle.properties file, so it is not for a project to take effect, but for all projects to take effect. The above configuration file is mainly to do, increase the size of Gradle running Java Virtual machine, let gradle at compile time use independent process, let Gradle can run parallel.

    1. Request Large Memory

    Installation Path\studio64.exe.vmoptions or Studio.exe.vmoptions

    Open with a text editor and find the starting two lines, as follows

    -xms128m
    -xmx750m


    Modify minimum and maximum values, recommended for

    -xms256m
    -xmx2048m

2 Optimizing compilation

File->setting->compile

Tick other options except for the second item and fill in the VM options:

-xmx2048m-xx:maxpermsize=512m-xx:+heapdumponoutofmemoryerror-dfile.encoding=utf-8


After testing, the compilation speed has been greatly improved, compared to the larger items from the previous 5-8 minutes can be reduced to 1-2 minutes.

Using the command line build

You can refer to this discussion string

Https://plus.google.com/u/0/+RicardoAmaral/posts/e9PG6vSN5w3

Gradle Assembledebug

The measured speed is about 50%, the principle is unclear

Go back and write a script build to complete and then automatically install the run should be good


I think the TMD still threw the company's broken computer for a new ability to fundamentally solve the problem.

Source: >

Second article:

has been developed using Android studio for more than a year, as the project grows, relying on the increase of the library, the construction speed is more and more slow, now the slowest 6 minutes to build a release of the installation package, find information on the Internet, found that can be configured to speed up the pace, Here to share with you.

Turn on gradle separate daemon

Create the file under the following directory gradle.properties :

    • /home/<username>/.gradle/(Linux)
    • /Users/<username>/.gradle/(MAC)
    • C:\Users\<username>\.gradle(Windows)

and add in the file:

Org.gradle. daemon=true

Modifying the files under the project gradle.properties can also be optimized:

# project-wide Gradle settings.

# IDE (e.g. Android Studio) Users:
# Settings specified in this file would override any Gradle Settings
# configured through the IDE.

# For more details about 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 are to run the build.
# todo:disable daemon on CI, since builds should is 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'll run in incubating parallel mode.
# This option is should only is 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 is 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

At the same time, these parameters can also be configured in the previous user directory in the gradle.properties file, so it is not for a project to take effect, but for all projects to take effect.

The above configuration file is mainly to do, increase the size of Gradle running Java Virtual machine, let gradle at compile time use independent process, let Gradle can run parallel.

Modify the Android Studio configuration

In the configuration of Android Studio, turn on offline mode and modify the configuration. The actual configuration is the same as in the above section, where the configuration is only effective when the IDE is built and the command-line build does not take effect.

Command line Build

Based on the above configuration, the command line is built with this parameter appended to the command --daemon --parallel --offline .

Using AAR when importing dependent libraries

Use AAR as much as possible using the Web-based third-party dependency library, which can be searched in mavenhttp://gradleplease.appspot.com/or Githuhttps://github.com/goddchen/mvn-repo.

Your library module can also be packaged into AAR, which can be referenced in http://www.linuxidc.com/Linux/2015-03/115242.htm.

Postscript

After such a toss, I originally need 4, 5 minutes to build the completed project, now only 30 seconds or so can be built to complete. Of course, if you do not do so, then, you should change the computer, SSD hard disk, larger memory, must be on the.

Ubuntu 12.04 (64-bit) installs Android Studio entire process http://www.linuxidc.com/Linux/2013-05/84812.htm

Android Studio v0.1 Early adopters http://www.linuxidc.com/Linux/2013-05/84681.htm

Android Studio Using tutorial http://www.linuxidc.com/Linux/2013-05/84579.htm

Android Studio Development Guide Http://www.linuxidc.com/Linux/2013-05/84543.htm

Android Studio Set themes and problem solving methods that do not support Chinese http://www.linuxidc.com/Linux/2013-05/84488.htm

Android Studio Download Installation and cannot open the workaround http://www.linuxidc.com/Linux/2013-05/84409.htm

Android Studio installation using graphics tutorial http://www.linuxidc.com/Linux/2014-09/106914.htm

Detailed Introduction to Android Studio : please click here
Android Studio : please click here

For more information about Android, see the Android feature page http://www.linuxidc.com/topicnews.aspx?tid=11

This article permanently updates the link address : http://www.linuxidc.com/Linux/2015-03/115241.htm

Optimize Android Studio/gradle build

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.