Gradle

Laptop

Gradle is an automated build system built on the principles of Apache Ant and Apache Maven. The Ant system was used in Eclipse, but most developers didn’t even notice its work. Mostly the system’s capabilities were used in offices to automate various tasks. In Android Studio, this will not be the case. Gradle accompanies you during development all the time. At first, if you have switched from Eclipse, Gradle is very annoying with its actions. But later you will appreciate its convenience and maybe even love it.

Gradle is not an invention for Android Studio, the system has been developed before and used in applications for Java, Scala and other languages.

The Gradle build system is very powerful and complex to talk about in a nutshell. There are whole books about it. The commands themselves in Gradle are plain text using Groove syntax for configuration. But we don’t need to know everything. Let’s get to know the system and learn how to use it.

Create a new project or open any existing project from Android Studio and look at the project structure.

In the latest versions of Studio, Gradle files have been separated into a separate folder Gradle Script. Expand it. You should mainly be interested in the build.gradle file, which refers to the module. Next to this file, it will say Module: app in brackets. Double click to open it, you will see that the file is a text file.

There is also a build.gradle file that refers to a project. But it is less often worked with. This is where the settings for repositories and Gradle itself are located.

Back to the module file, you will see a lot of interesting information. For example, you can see there the settings that you could previously see in the manifest – version numbers, SDK numbers, and so on. Looking ahead, I will say that you can add just one magic line here and the required library will be downloaded from the Internet and installed in the project. Beautiful!

But let’s return to the root folder. Besides build.gradle files, we can notice gradle.properties, settings.gradle and other files. There is no need to touch them.

The root folder also contains gradlew and gradlew.bat files for working with Gradle Wrapper. In principle you don’t need to know anything about them. But for the paranoid, here’s some information – if you often import projects from unknown sources, they contain a file gradle/wrapper/gradle-wrapper.properties. Open it with a text editor and look at the distributionUrl address. The path should lead to the official //services.gradle.org site or to an internal corporate server. Other addresses should raise an alarm.

You may have noticed that the file structure has changed compared to Eclipse. The app folder contains the src folder and the main folder, which contain the java, res and manifest file folders. The new structure better meets Gradle’s requirements for file management.