Accelerate Android Studio/gradle Build
Editor's recommendation: Rare earth nuggets, which is an application for technology developers, you can get the latest and best technical dry goods in the Nuggets, not only Android knowledge, front end, back end so that product and design are covered, want to be a friend of the whole stack of engineers do not miss!
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:
1# project-wide Gradle settings.2 # IDE (e.g. Android Studio) Users:3# Settings specifiedinch ThisFile wouldOverrideAny Gradle settings4 # configured through the IDE.5 # For more details about how to Configure your build environment visit6# http://www.gradle.org/docs/current/userguide/build_environment.html7 # The Gradle daemon aims to improve the startup and execution time of Gradle.8# whenSetTotrueThe Gradle daemon isTo run the build.9 # todo:disable Daemon on CI, since builds should is clean and reliable on serversTenorg.gradle.daemon=true One# Specifies the JVM arguments used forThe daemon process. A# The setting isParticularly useful fortweaking memory settings. -# Default Value:-xmx10248m-xx:maxpermsize=256m -org.gradle.jvmargs=-xmx2048m-xx:maxpermsize=512m-xx:+heapdumponoutofmemoryerror-dfile.encoding=utf-8 the# when configured, Gradle'll runinchincubating 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 +# enablesNewincubating mode, makes Gradle selective when configuring projects. -# only relevant projects is configured which resultsinchFaster builds forLarge multi-projects. +# http://Www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand AOrg.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.
Own library module can also be packaged into AAR, about this can refer to Stormzhang article http://www.stormzhang.com/android/2015/03/01/android-reference-local-aar/.
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.
Original address: http://blog.isming.me/2015/03/18/android-build-speed-up/
Accelerate Android Studio/gradle Build