Turn: Android Studio Gradle

Source: Internet
Author: User
Tags jenkins ci

improve Gradle execution efficiency in Android studioCategory: Android Studio2015-06-26 11:54 2374 People read Comments (2) favorite reports Android Studiogradleperformance

Respect the fruits of labor, reproduced please specify the source: http://blog.csdn.net/growth58

Do you feel that Android studio is too slow to build? I have this feeling, too.



Fortunately, there are many tricks that can improve the speed of construction. These techniques are still being experimented and may be unsafe, and if you feel that the build time is too long and painful, it is valuable to try these techniques. I have tried to reduce the build time by 2.5 seconds, as described below, with little code churn. Hope to be of help to you.

Android Studio uses Gradle to build the project. The current version of Gradle is 2.2. The latest version is 2.4, and the performance is much higher than the previous version.

There are two ways to edit the build file manually, and the other is to change the configuration through Android Studio.

For manual editing of the build file, add the following code at the end of the Build.grade file at the root of the project:

[Java]View Plaincopyprint?
    1. Task Wrapper (Type:wrapper) {
    2. gradleversion = ' 2.4 '
    3. }

Open the terminal and run the command:./gradlew wrapper, it will download and set version 2.4 of Gradle for your local gradle wrapper. This is the method described in the official Gradle document (http://gradle.org/docs/ current/userguide/gradle_wrapper.html).


For Android Studio configuration, open the Project Structure dialog box and select Project-〉 to change the Gradle version to 2.4. When you click OK, Android Studio will automatically sync the Gradle configuration and set the new version of wrapper.

Note: This is only when your project is using the Gradle wrapper (default is the project built with Android Studio). If this is not the case, refer to Gradle document http://gradle.org.

The second step is to open the daemon and parallel switch in the project's build file. Using Daemon (daemon) will cause the build to start quickly, and it will not be fully built every time the application starts. Using parallel will build multiple modules at the same time, with projects that are large in engineering or with many modules that make construction fast.

Under the. Gradle folder, add a file named Gradle.properties, and add the following code (for example: ~/.gradle/gradle.properties).

[Java]View Plaincopyprint?
    1. Org.gradle.daemon=True
    2. Org.gradle.parallel=True

Note: Android Studio has turned on the daemon switch and this configuration will ensure that the daemon is turned on when it is built from the terminal.

You can also add this file at the root of your project, and it will open automatically for everyone to build the app, including your integration environment (like Jenkins CI). When you are not using daemon build, see more information from this http://gradle.org/docs/current/userguide/gradle_daemon.html#when_should_i_not_use_the_ Gradle_daemon.

Important notes about parallel: Configuring parallel may make some works unsafe.  This requires that your module must be decoupled (refer to Http://gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects) Otherwise, there may be build failures. Carefully test all the variants you build and you will know all of its work.

You can add additional build parameters, such as increasing the stack size when your project is large, or specifying the JVM:

[Java]View Plaincopyprint?
    1. Org.gradle.jvmargs=-xmx768m
    2. Org.gradle.java.home=/path/to/jvm

For other configurable options in the Gradle.properties file, refer to Http://gradle.org/docs/current/userguide/userguide_single.html#sec:gradle_ Configuration_properties. Some options in Android Studio are available, or they are open by default, but when you open these options in the Gradle.properties file, when you use the Terminal build project, this will ensure that your colleagues have the same configuration.

The last is to change the value of the incremental dexing, which is a function of the experiment and is closed by default. Opening this switch can lead to build failures (especially when running continuously), but I recommend you try it and see if it works for you.

In the main app module, in the Build.gradle file, add the following code:
[Java]View Plaincopyprint?
    1. dexoptions {
    2. Incremental True
    3. }

Hope to help you, if you have any questions or other tips on improving your build execution efficiency, please leave a comment below.

The first translation of the article, the level of limited also hope, if there is distorted the meaning of the original author, but also hope to point out.

Original address: https://medium.com/@erikhellman/boosting-the-performance-for-gradle-in-your-android-projects-6d5f9e4580b6

Turn: Android Studio Gradle

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.