Once Gradle has joined Android Development, life is much easier NOW!

Building a Java project doesn’t seem too bad but Android applications on the other hand are beasts. That Java source is not compiled as standard Java bytecode but to custom bytecode for the Android runtime.

Android has three different types of resources that all get packaged differently like below in the image:

  • There is an additional wrinkle in that the resources that you define need to be pooled together with resources coming from your included libraries.
  • And the identifiers of all those resources need to know beforehand before anything else gets compiled.
  • Also, android applications must be cryptographically signed. When…

Sometimes you need your build system to customize the build process in some way.

1. Creating Tasks

You may want Gradle to output an APK file containing the build date in its name. One possible solution to this is to create a custom Gradle task.

Add the following code in your module-level build.gradle file at the same level as android block:

// 1
task addCurrentDate() {
// 2
android.applicationVariants.all { variant ->
// 3
variant.outputs.all { output ->
// 4
def date = new Date().format("dd-MM-yyyy")
// 5
def fileName = variant.name + "_" + date + ".apk"
// 6
output.outputFileName = fileName

Here’s what’s is going on:

  1. You define an addCurrentDate() task.
  2. You iterate…

Your app is ready, and you’re thinking of ways to profit from it.

Product Flavors and Build Types

One solution might be to have multiple versions of your app like the Free Version and Paid Version. Luckily for you, Gradle supports this at the building level, allowing you to define the boundaries of different build types. However, before getting started, you need to understand how Gradle allows you to work with different app versions.

1. Build Types

By default, there are two build types — debug and release. The only difference between them is the value of the debuggable parameter. In other words, you can use the debug version to review logs and to debug the app, while the release one…

Before starting working with the project, let’s review its structure in the Project pane in Android Studio.

Gradle Structure in Android Studio

Pay attention to the files with the green Gradle icon and .gradle extension. These files are generated by Android Studio automatically during project creation. They are responsible for the processing of your project’s build. They contain the necessary info about the project structure, library dependencies, library versions, and the app versions you’ll get as a result of the build process.

I. Project-level build.gradle :

Find the build.gradle file in the root directory of the project. It’s called a top-level (project-level) build.gradle file. It contains the settings which are applied to all modules of the project.

// 1
buildscript {
ext.kotlin_version = '1.2.50'…

Now it’s time to make changes to the application itself. Build and run the starter project.

We will continue with Some different ways of Managing Gradle Dependencies. This blog is a part of Android Tips And Tricks (ATAT) for Building a Robust Android App Series.

Getting Familiar with Gradle Series :

  1. Know more about THE AMAZING Gradle in Android Studio
  2. Gradle Structure and Tasks in Android Studio, Let’s Dig Deeper
  3. Some different ways of Managing Gradle Dependencies <==
  4. Gradle Tasks and Plugins, Something more Customized
  5. Gradle Product Flavors and Build Types

Now, that’s the time for Managing Dependencies!

Multi-module Android projects are now the recommended way to take advantage of performance improvements with Android Gradle Plugin 3+. …

Android App is like a chain, every single part of the app must be well connected to each other to make it ROBUST.

This series is targeting junior android geeks ✋

Building a Robust Android App is a CHALLENGE!

Without Requirements or Design, Programming is the art of adding Bugs to an Empty Text File.

— Louis Srygley

Nowadays, it is going to be hard to build a robust android application, an application that fits the user experience, offline first, not buggy, scalable, maintainable and testable application. So, what we are going to do in this series of articles is to offer you some Tips and Tricks — according to our experience — to how to build a robust android application from scratch.

What we will cover in this series.

Ahmed Adel

Senior Software Engineer @ Zendesk. Co-Founder & Mentor @ EGDroid. Usually, I do Android 📱Photography 📸 and Football ⚽

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store