Gradle - Orange168/NotesOnReading GitHub Wiki

加速Android Studio/Gradle构建

OS configuration path

  • Linux: /home/<username>/.gradle/
  • Mac : /Users/<username>/.gradle/
  • Windows: C:\Users<username>.gradle

Gradle.properties Performance

Under .gradle directory for example Linux ~/.gradle/gradle.properties,if not exits make it .

org.gradle.jvmargs=-Xmx768m
org.gradle.java.home=/path/to/jvm
# 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

[1] JVM系列三:JVM参数设置、分析

Android studio Gradle settings

Setting --> compiler --> VM Options

-Xmx1024m
-XX:MaxPermSize=128m
-XX:+HeapDumpOnOutOfMemoryError
-Dfile.encoding=UTF-8

Command performance

gradle --daemon --parallel --offline

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME #<usrname>/.gradle
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip

Intent

  • support diff OS
  • guarantee the version of Gradle that the build was designed to work with.
  • use the project gradle eviroment without needing to install gradle beforehand.

gradlew file The gradlew command can be used exactly the same way as the gradle command.

  • run gradlew, the wrapper checks if a Gradle distribution for the wrapper is available (checks GRADLE_USER_HOME/wrapper/dists have the specified gradle version)
  • If it didn't find a Gradle distribution, it will use download distributionUrl to it first.

Verification of downloaded Gradle distributions

> shasum -a 256 gradle-2.4-all.zip
371cb9fbebbe9880d147f59bab36d61eee122854ef8c9ee1ecf12b82368bcf10  gradle-2.4-all.zip
#configuration  gradle-wrapper.properties
distributionSha256Sum=371cb9fbebbe9880d147f59bab36d61eee122854ef8c9ee1ecf12b82368bcf10

Similar the wrapper download the specify distribution and verify it:

.gradle/wrapper/dists/gradle-2.3-all/4frmts9dq8ier673ls7ki38n97/gradle-2.3-all.zip

Tips

  • Specify a local distribution file (gradle-2.8-all.zip) relative to the location of gradle-wrapper.properties distributionUrl=file\:/work/Environment/gradle/gradle-2.3-all.zip
⚠️ **GitHub.com Fallback** ⚠️