Over a million developers have joined DZone.

Introduction to Android Gradle

Gradle is simply a software or toolkit used for building software. These kinds of software are also called build automation software or build systems.

· Mobile Zone

Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud, brought to you in partnership with IBM.

What Is Gradle?

Gradle is simply a software or toolkit used for building software. These kinds of software are also called build automation software or build systems. Build automation is the process of automating the creation of a software build and the associated processes including compiling computer source code into binary code, packaging binary code, and running automated tests. Other languages have their own build systems that you might be familiar with, such as make for C/C++, A-A-P, a Python-based build tool, Apache Ant for Java, etc.

These tools, given the rules, can be taught how to determine what needs to be created and how to create it. Also, note that a build system does not compile, link, package, etc. applications directly. They direct other systems such as compilers (computer programs that transform source code written in a programming language—the source language—into another computer language—the target language), linkers (computer programs that take one or more object files generated by a compiler and combines them into a single executable file, library file, or another object file), and packages to do the work.

Gradle makes use of a domain-specific language (DSL) build on top of Groovy to accomplish the tasks specified. Note that DSL is a computer language specialized to a particular application domain (i.e., HTML, CSS for web pages, regular expressions, make, rake, Ant, SQL, etc.). It is different from GPL (General Purpose Language), which is use to write applications in a variety of domains including PHP, Java, C, C++, Assembly language, etc. Martin Fowler is a strong proponent of the idea; he wrote an article on his website.

Groovy is an interpreted language. What does that mean? The difference between a compiled language such as Java, C++, C#, etc., and an interpreted language such as PHP, MATLAB, Javascript, etc. is explained well in this Stack Overflow answer. Ironically, Java JAR is the software designed to support the execution of Groovy. This means that Groovy runtime is a Java JAR that requires JVM in order to operate. One of Groovy’s core strengths is in developing a DSL. Gradle is one of them which is for doing software builds.

Android and Gradle

Google developed the Android Plugin for Gradle. This makes it possible for developers to build Android projects with the Gradle Toolkit. Google is also using Gradle and Gradle for Android as the build system behind Android Studio. "We are working on a new build system to replace both the build system inside ADT (Android Development Tools) and Ant," the project site from Google states.

The goals of the new build system are to make it easy to reuse code and resources, make it easy to create several variants of an application (either for multi-APK distribution or for different flavors of an application), make it easy to configure, extend, and customize the build process, and to have good IDE integration.

Moving to Gradle from the Eclipse Build System

In the past, we were using Eclipse IDE and Ant to build millions of apps, I don’t know why anyone would still be using Eclipse IDE to develop Android apps at all. Ant is not the build tool in the Eclipse IDE but instead a command-line tool. Eclipse IDE has its own build system which is call Eclipse-ADT. These tools still work today, though Ant support is fading fast and is strongly advised to use Android Studio instead.

So why the switch to Gradle?

  • Maintaining two separate build systems (Ant and Eclipse’s native approach) was becoming time-consuming and would become worse with the advent of Android Studio and yet another build system.

  • Getting Ant scripts to do everything that Google needed for builds was getting a bit creaky.

  • Gradle is designed to be integrated into IDEs as a library—much more than Ant is.

  • Ant has no first-class support for “external artifacts” (i.e., libraries) and dependency management of those libraries.

As we all know, Android Studio uses the Gradle-based build system as its own native approach that is integrated into it for building Android apps. This has a big advantage because it allows Google to focus on only one single build system.

References and Further Reading

The Mobile Zone is brought to you in partnership with Strongloop and IBM.  Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud.


Published at DZone with permission of Chike Mgbemena. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}