This is my third article on getting started.

preface

Gradle is an open source tool for project automation. Android projects can’t be built without it, and starting today we will do a series of Gradle articles to learn about it.


A, definitions,

Gradle is a project automation build tool based on Apache and Apache Maven concepts. Instead of traditional XML, it uses a Groovy-based domain-specific language to declare project Settings.

The development cycle of an application should go from development -> build -> test -> release. The build process is done by Gradle.

APK is built by packaging resources -> compiling code -> compression -> signing -> alignment. (Here is a rough introduction to the steps, and another article details the APK packaging process.)

Install Gradle

1. Install the JDK

Gradle tools run on a Java virtual machine, so you need to install Jdk1.8 or later. The INSTALLATION of the JDK will not be described here. To check the version of the Jdk installed, open the command line and type Java -version:

2. Install global Gradle: available in all directories (not recommended)

Download it at gradle.org/releases/

When opened, you can see the update record:

Versions of these:

  • Binary-only: sufficient for use

  • Complete: Contains the source code and documentation

After downloading, unzip the zip to ~/gradle/

Execute the export PATH = $PATH: ~ / gradle/gradle – 7.0 – bin

Enter gradle -v on the terminal. If the gradle version number is displayed, the configuration is correct.

Note ⚠️ : this scheme is not recommended:

  • Installation trouble. Environment variables need to be downloaded and configured.
  • The GradleWrapper that Android automatically generates when creating a project runs a specific version of Gradle. If not locally available. I’m going to download it locally. More convenient
3. Gradle installation for project dimension – GradleWrapper

AndroidStudio creates a project with a Gradle-wrapper. Gradle-wrapper helps developers run a particular version of Gradle in their project. You can go to the Project directory from the command line and run gradle warpper to build a gradleWrapper. Build once, upload version control and others can use it without building again.

Run./gradlew -v in the root directory of the project to view the version:

Gradle basic execution statements

1. Gralde command format

Gradle execution statements can be executed directly from the command line:

Command format:./gradlew [task-name…] [-option-name]

Such as:

  • Clean up the artifacts of the last mission:./gradlew clean
  • Project Construction:./gradlew build
  • View all subprojects:./gradle projects
Gradle version Management:

/gradlew wrapper –gradle-version + version number

For example:./gradlew wrapper –gradle-version 6.3

2. Directly modify the version number in the ~/gradle/wrapper/gradle-wrapper.properties file. Then rebuild the Gradle Wrapper.

At the end


So much for the basics of Gradle. In the next installment we will introduce Groovy, Gradle’s basic syntax. Looking forward to seeing you next time!