SlideShare a Scribd company logo
Anton Nurdin T
Senior Software Engineer, Xendit
anton46.com
DEEP UNDERSTANDING ABOUT
What is Gradle?
Android Build System
Android Build System
ant
Maven
Gradle
SBT
buck
Build Process
ID Android TechTalk Series #6 : Google Service and Gradle - Anton Nurdin Tuhadiansyah
Multi-Language
Resource/Code Generation
Platform Diversity
Why Gradle?
1. Powerful Build System
- Declarative, Flexible
- Imperative Customization
- Tooling API
2. Build System Toolkit
- Plugins create own DSL, APIs, IDE integration
3. Free/Open Source
Structure
Settings File
- settings.gradle
Structure
Settings File
- settings.gradle
Top-level Build File
Top-level Build File
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
build.gradle
Structure
Settings File
- settings.gradle
Top-level Build File
Structure
Settings File
- settings.gradle
Top-level Build File
Module-level Build File
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig { ... }
buildTypes { ... }
productFlavors { ... }
}
dependencies { ... }
Module-level Build File
build.gradle
Gradle Tasks
assemble
check
build
clean
assemble + check
assembleDebug + assembleRelease
connectedCheck
deviceCheck
COSTUMIZATION
Basic Customization
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
}
build.gradle
Basic Customization
def getVersionCode() {
def code = ...
return code;
}
android {
defaultConfig {
versionCode getVersionCode()
...
}
}
build.gradle
Basic Customization
android {
defaultConfig {
applicationId “com.example.app”
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
def fileName = file.name.replace(".apk", "-v" + versionName + "-c" + versionCode + ".apk")
output.outputFile = new File(file.parentFile, fileName)
}
}
}
}
build.gradle
Basic Customization
app-debug-v1.0-c1.apk
app-release-v1.0-c1.apk
Build Types
- Build / Packaging customization
• Debuggable flag
• ProGuard
• Signing Configuration
• Source / Resource Overlay

- Debug and release prebuilt
Build Types
android {
buildTypes {
debug {
applicationIdSuffix '.debug'
versionNameSuffix '-DEBUG'
}
beta {
applicationIdSuffix '.beta'
versionNameSuffix '-BETA'
}
}
}
build.gradle
Build Types : Source Folder
src/main/AndroidManifest.xml
src/main/java
src/main/resource
src/main/res
src/main/assets
src/main/aidl
src/main/rs
src/main/jni
src/debug/...
src/release/...
src/beta/...
src/androidTest/java
src/androidTest/resource
src/androidTest/res
src/androidTest/assets
src/androidTest/aidl
src/androidTest/rs
src/androidTest/jni
Gradle Tasks
assemble
check
build
clean
assemble + check
assembleDebug + assembleRelease + assembleBeta
connectedCheck
deviceCheck
Signing Configuration

android {
signingConfigs {
release {
storeFile file('<name>.keystore')
keyAlias 'keyAlias'
keyPassword 'keyPassword'
storePassword 'storePassword'
}
}
}
build.gradle
Debuggable Release Builds

android {
signingConfigs {
debugRelease.intiWith(buildTypes.release)
debugRelease {
debuggable true
applicationIdSuffix '.debugrelease'
signingConfig signingConfigs.debug
}
}
}
build.gradle
DEPENDENCIES
Dependency Scope: Java Projects
compile

runtime
testCompile
testRuntime
Dependency Scope: Android Projects
compile

runtime
testCompile
testRuntime
compile
package
androidTestCompile
androidTestPackage
Local Dependencies

android {
...
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
build.gradle
Remote Dependencies

repositories { jcenter() }
android {
...
}
dependencies {
compile 'com.android.support:appcompat-v7:23.2.1'
}
build.gradle
Multi-Project Setup

settings.gradle
include ':app'
include ':libraries:lib1'
include ':libraries:lib2'
MyProject/
| settings.gradle
+ app/
| build.gradle
+ libraries/
+ lib1/
| build.gradle
+ lib2/
| build.gradle
Project Dependencies

android {
...
}
dependencies {
compile project(‘:libraries:lib1’)
}
build.gradle
Android Library Project

apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
}
build.gradle
Android Library
- Binary Bundle (.aar)
• Uploadable to repositories

- Support for
• assets
• Proguard rules
• Custom Lint rules
• . . .
BUILD VARIANTS
Product Flavors
- Different versions of the same application
• Paid vs Free
• Multi-APK support in Google Play

- Different Dimension(s) than BuildTypes
Android Library Project

android {
productFlavors {
flavour1 {
applicationId "com.example.flavour1"
minSdkVersion 16
}
flavour2 {
applicationId "com.example.flavour2"
}
}
}
build.gradle
Build Types : Source Folder
src/main/AndroidManifest.xml
src/main/java
src/main/resource
src/main/res
src/main/assets
src/main/aidl
src/main/rs
src/main/jni
src/androidTest/java
src/androidTest/resource
src/androidTest/res
src/androidTest/assets
src/androidTest/aidl
src/androidTest/rs
src/androidTest/jni
src/debug/...
src/release/...
src/beta/...
src/flavor1/... src/androidTestFlavor1/...
Variant = Build Type + Product Flavor(s)
No Flavors :

debug release
- debug release
- - -
Variant = Build Type + Product Flavor(s)
No Flavors :

debug release
- debug release
- - -
With Flavors : debug release
Flavor1 Flavor1Debug Flavor1Release
Flavor2 Flavor2Debug Flavor2Release
Build Variants : Source Code
Multiple source folders, single output
src/main/java
src/debug/java
src/free/java
Build Variants : Resource
Overlays
src/main/res
src/debug/res
src/free/res
Build Variants : Signing Configuration
Priority Order
android.defaultConfig.signingConfig
android.buildTypes.release.signingConfig
android.productFlavors.free.signingConfig
Build Variants : Package Name
Overlays + Suffix
android.defaultConfig.packageName
android.productFlavors.free.signingConfig
+ android.buildTypes.debug.packageNameSuffix
src/main/AndroidManifest.xml
Build Variants : Proguard
android {
...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
productFlavors {
flavor2 {
proguardFile 'flavor2-rules.pro'
}
}
}
build.gradle
Res / Code Generation
buildConfigField
resValue
build.gradle
android {
buildTypes {
debug {
buildConfigField "String", "SERVER_URL", '"http://staging.example.co"'
resValue "string", "facebook_app_id", '"12345678910'
...
}
release {
buildConfigField "String", "SERVER_URL", '"https://example.co"'
resValue "string", "facebook_app_id", '"0987654321'
...
}
}
}
Res / Code Generation
PERFORMACE
GRADLE IS FAST
GRADLE IS FAST
200 Projects
grade clean assemble —-parallel 7s
• Android Studio IDE (Android Tooling Team)
• Gradle Android Plugin (Android Tooling Team)
• Gradle Flatform (Gradle Team)
• Android Tooling (Android Platform Team)
Toolchain
BOTLENECK
Clean Install (61.9s)
1%8%
46% 27%
3%
14%
Install (8.89s)
After Dexing (2.06s)
Dex (16.67s)
Pre-Dex (28.54s)
Before Dexing (5.04)
Configuration (0.65)
Install After Code
Change (33.31s)
2%
15%
50%
6%
27% Install (8.89s)
After Dexing (2.06s)
Dex (16.67s)
Before Dexing (5.04s)
Configuration (0.65s)
PRE-DEXING
DEXING
Hint
• Enable the Gradle daemon and parallel build
dexOptions {
incremental true
}
• Incremental dexing
~/.gradle/gradle.properties
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx1024m
org.gradle.java.home=/path/to/jvm
• Offline Mode
• Separate project into modules
https://source.android.com/
source/jack.html
Jack Compiler
http://gradle.org/training/
Anton Nurdin T
Senior Software Engineer, Xendit
anton46.com
THANK YOU

More Related Content

PDF
I/O Extended (GDG Bogor) - Andrew Kurniadi
PPTX
High Performance NodeJS
PDF
Gradle presentation
PPTX
Gradle,the new build system for android
PPTX
Android presentation - Gradle ++
PDF
Gradle by Example
PDF
Gradle 3.0: Unleash the Daemon!
I/O Extended (GDG Bogor) - Andrew Kurniadi
High Performance NodeJS
Gradle presentation
Gradle,the new build system for android
Android presentation - Gradle ++
Gradle by Example
Gradle 3.0: Unleash the Daemon!

What's hot (20)

PDF
How to create an Angular builder
PPTX
Gradle : An introduction
PDF
PuppetConf 2016: Docker, Mesos, Kubernetes and...Puppet? Don't Panic! – Deep...
PDF
PROMAND 2014 project structure
PDF
Introduction to Kubernetes with demo
PDF
Gradle - time for a new build
PDF
Gradle - the Enterprise Automation Tool
PDF
Android Jetpack + Coroutines: To infinity and beyond
PPTX
Vue.js Use Cases
PDF
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
PDF
How we can do Multi-Tenancy on Kubernetes
PDF
Making the Most of Your Gradle Builds
PPTX
React nativebeginner1
ODP
Griffon: Re-imaging Desktop Java Technology
PDF
Overview of Android Infrastructure
PDF
An Introduction to Gradle for Java Developers
PDF
Gradle Introduction
PDF
Introduction to gradle
PPTX
PDF
Get Hip with JHipster - GIDS 2019
How to create an Angular builder
Gradle : An introduction
PuppetConf 2016: Docker, Mesos, Kubernetes and...Puppet? Don't Panic! – Deep...
PROMAND 2014 project structure
Introduction to Kubernetes with demo
Gradle - time for a new build
Gradle - the Enterprise Automation Tool
Android Jetpack + Coroutines: To infinity and beyond
Vue.js Use Cases
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
How we can do Multi-Tenancy on Kubernetes
Making the Most of Your Gradle Builds
React nativebeginner1
Griffon: Re-imaging Desktop Java Technology
Overview of Android Infrastructure
An Introduction to Gradle for Java Developers
Gradle Introduction
Introduction to gradle
Get Hip with JHipster - GIDS 2019
Ad

Viewers also liked (20)

PDF
Continuous Integration & Continuous Delivery on Android - Nur Rendra Toro Sin...
PPTX
Talkshow - Android N & I/O Update
PDF
ID Android TechTalk Series #6 : Google Service and Gradle - Ibnu Sina Wardy
PDF
I/O Extended (GDG Bogor) - Narenda Wicaksono
PPTX
Menjadi Tuan Rumah di Negeri Sendiri - Fauzil Hamdi (CEO The Wali)
PPTX
Produktif dalam Membangun Game - Adam Ardisasmita (Arsakids)
PPTX
Mencari Genre Game yang Sesuai Passion - Cipto Adiguno (Ekuator Games)
PDF
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
PDF
ID Developer Elite
PDF
Sidiq Permana - Building For The Next Billion Users
PPTX
Yoza Aprilio - We must design
PPTX
ID Android Dev Talk - Observer Pattern, Event Bus Usage, Firebase & Geofire
PPT
Agus Hamonangan - Sejarah Android, Penetrasi/Pertumbungan, dan Peluang Smartp...
PPTX
I/O Extended (GDG Bogor) - Sidiq Permana
PDF
Agate Presentation at Gedebuk Coy!
PPT
Develop a Game - And interact with your Community | by Two Pi Team
PDF
About indonesia Game Industry - Agate Studio
PDF
Indonesia Game Ecosystem Outlook 2017
PPTX
Rendra Toro - Model View Presenter
PPTX
Introduction to Android - Seminar
Continuous Integration & Continuous Delivery on Android - Nur Rendra Toro Sin...
Talkshow - Android N & I/O Update
ID Android TechTalk Series #6 : Google Service and Gradle - Ibnu Sina Wardy
I/O Extended (GDG Bogor) - Narenda Wicaksono
Menjadi Tuan Rumah di Negeri Sendiri - Fauzil Hamdi (CEO The Wali)
Produktif dalam Membangun Game - Adam Ardisasmita (Arsakids)
Mencari Genre Game yang Sesuai Passion - Cipto Adiguno (Ekuator Games)
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
ID Developer Elite
Sidiq Permana - Building For The Next Billion Users
Yoza Aprilio - We must design
ID Android Dev Talk - Observer Pattern, Event Bus Usage, Firebase & Geofire
Agus Hamonangan - Sejarah Android, Penetrasi/Pertumbungan, dan Peluang Smartp...
I/O Extended (GDG Bogor) - Sidiq Permana
Agate Presentation at Gedebuk Coy!
Develop a Game - And interact with your Community | by Two Pi Team
About indonesia Game Industry - Agate Studio
Indonesia Game Ecosystem Outlook 2017
Rendra Toro - Model View Presenter
Introduction to Android - Seminar
Ad

Similar to ID Android TechTalk Series #6 : Google Service and Gradle - Anton Nurdin Tuhadiansyah (20)

PPTX
Hands on the gradle
PPTX
Android 101 - Introduction to Android Development
PPTX
Android Applications Development: A Quick Start Guide
PDF
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
PDF
Android gradle-build-system-overview
PDF
lecture-2-android-dev.pdf
PDF
01 02 - introduction - adroid stack
PDF
Deploying artifacts to archiva
PPTX
Android app development lesson 1
PPTX
Android Studio簡介
PDF
Android
PPT
Android Studio Software Installation steps in windows.
PDF
Android Development
PPTX
Android session-1-sajib
PPTX
Mobile Application Slide Chapter 2 - Make First App
PPTX
3. Android Architecture.pptx
PDF
Android dev o_auth
PPTX
Notes Unit2.pptx
PPTX
Android
PPTX
Android Basic
Hands on the gradle
Android 101 - Introduction to Android Development
Android Applications Development: A Quick Start Guide
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
Android gradle-build-system-overview
lecture-2-android-dev.pdf
01 02 - introduction - adroid stack
Deploying artifacts to archiva
Android app development lesson 1
Android Studio簡介
Android
Android Studio Software Installation steps in windows.
Android Development
Android session-1-sajib
Mobile Application Slide Chapter 2 - Make First App
3. Android Architecture.pptx
Android dev o_auth
Notes Unit2.pptx
Android
Android Basic

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
August Patch Tuesday
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
A Presentation on Touch Screen Technology
PDF
Encapsulation theory and applications.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Hybrid model detection and classification of lung cancer
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
Unlocking AI with Model Context Protocol (MCP)
TLE Review Electricity (Electricity).pptx
Group 1 Presentation -Planning and Decision Making .pptx
Enhancing emotion recognition model for a student engagement use case through...
August Patch Tuesday
Assigned Numbers - 2025 - Bluetooth® Document
SOPHOS-XG Firewall Administrator PPT.pptx
Programs and apps: productivity, graphics, security and other tools
1 - Historical Antecedents, Social Consideration.pdf
A Presentation on Touch Screen Technology
Encapsulation theory and applications.pdf
WOOl fibre morphology and structure.pdf for textiles
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Zenith AI: Advanced Artificial Intelligence
Hybrid model detection and classification of lung cancer
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Tartificialntelligence_presentation.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
NewMind AI Weekly Chronicles - August'25-Week II

ID Android TechTalk Series #6 : Google Service and Gradle - Anton Nurdin Tuhadiansyah