Skip to main content

Gradle Tutorial for Android - Getting Started

About 3 minJavaKotlinAndroidGradleArticle(s)blogkodeco.comjavakotilnandroidgradle

Gradle Tutorial for Android - Getting Started 관련

Gradle > Article(s)

Article(s)
Android > Article(s)

Article(s)

Gradle Tutorial for Android - Getting Started
In this Gradle Build Script tutorial you’ll learn the basic syntax in build.gradle files generated by Android Studio. You’ll also learn about gradlew tasks, build types, product flavors, build variants, and how to add additional information such as the date to the APK file name.

In this tutorial, you’ll gain a better understanding of what Gradle is, and how you can use Gradle to supercharge your builds. By the end of this tutorial you should be able to

  1. Build your Android apps from the command-line
  2. Read through a Gradle build file
  3. Create your own Gradle plugin
  4. Create build flavors for profit!

Note

This tutorial assumes you’re already familiar with the basics of Android development. If you are completely new to Android development, read through our Beginning Android Developmentopen in new window tutorials to familiarize yourself with the basics.


What is Gradle?

Gradle is an open source build automation system. It brings the convenience of a Groovy-based DSL along with the advantages of Antopen in new window and Mavenopen in new window. With Gradle, you can easily manipulate the build process and its logic to create multiple versions of your app. It’s much easier to use and a lot more concise and flexible when compared to Ant or Maven alone.

So, there was little wonder why during Google I/O in May 2013, the Android Gradle plugin was introduced as the build tool built into the first preview of Android Studio


Getting Started

Download SocializifyStarteropen in new window the starter project for this tutorial. At minimum, you’ll need Android Studio 3.0 installed on your computer.

Open the project in Android Studio and you’ll be prompted to setup the Gradle wrapper
Open the project in Android Studio and you’ll be prompted to setup the Gradle wrapper

Choose [OK] to configure the wrapper, which you’ll learn more about later in the tutorial.

Depending on which version of Android Studio you’re running, you may also be prompted to update the Gradle plugin
Depending on which version of Android Studio you’re running, you may also be prompted to update the Gradle plugin

Choose [Update] to finish opening the project in Android Studio.

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

Project structure
Project structure

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.

Project-level build.gradle

Module-level build.gradle

Finally, settings.gradle


Groovy vs. Kotlin in Gradle

Why Kotlin


Mastering the build: Gradle Commands

What is gradlew

gradlew tasks

gradlew assemble

gradlew lint


Managing Dependencies

Gradle Dependency Configurations


Ready to Publish: Working with Product Flavors and Build Types

Build Types

Build Signing

Build Flavors

What is a Build Variant


Creating Tasks


Creating Custom Plugins


Where to Go From Here

You can download the final project hereopen in new window.

The Android Gradle plugin 3.0 contains some significant differences from previous versions. So it’s worth reviewing the changelogopen in new window.

Also, if you’re insterested in the Gradle Kotlin DSL, gradle/kotlin-dslopen in new window you can find a list of usage examples to get familiar with it.

I hope you’ve enjoyed this Getting Started with Gradle tutorial! Don’t forget to leave your feedback and feel free to ask any questions in the comments below


이찬희 (MarkiiimarK)
Never Stop Learning.