Gradle Wrapper

Introduction

Gradle Wrapper is a layer of encapsulation for Gradle. A project can be built with a specified gradle version without being affected by the gradle version installed on the current machine, so that multiple projects on one machine can be built with different gradle versions without affecting each other. . When the gradlew command is executed, the wrapper will check the cache to determine whether the corresponding version of gradle has been installed on the current machine. If it is installed, gradlew will entrust gradle to execute the command entered by the user. If it has not been installed, it will automatically help us first. Download from the configured download address. Therefore, the correct way to use gradle is to use gradlew instead of the gradle command . Since the intranet cannot connect to the external network to download the specified gradle version, we need to manually put the corresponding gradle version in the cache directory.

Windows command: gradlew xxx

Linux command: ./gradlew xxx

Wrapper's configuration file is gradle\wrapper\gradle-wrapper.properties

As shown in the figure above, when executing the gradlew command, specify to use the gradle 4.4 version to build the project

PS: Every Android Studio project has a gradle wrapper, which can be viewed in the project root directory

cache

Gradle's default cache directory is ~/.gradle, which is the .gradle directory under the user's home directory. If the environment variable GRADLE_USER_HOME is not set, the cache directory corresponding to wrapper is ~/.gradle/wrapper/dists. If the environment variable GRADLE_USER_HOME is set, then The cache directory corresponding to wrapper is $GRADLE_USER_HOME/wrapper/dists

configure

Here is an example of gradle-4.4-all.zip

1. Put gradle-4.4-all.zip into the following directory:

~/.gradle\wrapper\dists\gradle-4.4-all\9br9xq1tocpiv8o6njlyu5op1, any directory in the path such as gradle-4.4-all can be created if it does not exist, of which 9br9xq1tocpiv8o6njlyu5op1 is a string generated according to certain rules, you can refer to the Gradle cache directory file naming convention

2. Unzip gradle-4.4-all.zip to the current directory

  unzip gradle-4.4-all.zip(Linux)

3. Create empty files gradle-4.4-all.zip.lck and gradle-4.4-all.zip.ok

touch gradle-4.4-all.zip.lck gradle-4.4-all.zip.ok(Linux)

The final directory structure is as follows:

verify

Create a directory such as test, then execute the gradle wrapper command, and then modify the distributionUrl in the configuration file gradle\wrapper\gradle-wrapper.properties, such as the modified file as follows:

At this point, execute gradlew -v in the test directory. If the version information is displayed, the configuration is successful.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325449944&siteId=291194637