4. What is gradle
• Gradle is a JVM based project build automation tool that
builds upon the concepts of Apache Ant and Apache
Maven and introduces a Groovy based domain-specific-
language (DSL) instead of the more traditional XML form of
declaring the project configuration.
5. Installation
• Download the latest android plugin supported Gradle version
• Extract the downloaded zip “gradle-1.10-all.zip” to any
directory
• Configure the GRADLE_HOME environment variable
• set GRADLE_HOME=<installed directoy>gradle-1.10
• set PATH=%PATH%%GRADLE_HOME%bin
• C:> gradle
6. Gradle Task
• C:> gradle tasks
• Applying the plugin’s to the build file will automatically add set of
build task to run
• assemble
The task to assemble the output(s) of the project
• check
The task to run all the checks.
• build
This task does both assemble and check
• clean
This task cleans the output of the project
9. Convention Over Configuration
src
└── main
l └── java
l
└── instrumentTest
└── java
sourceSets {
main{
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
10. Usecase : 1
I have project with multiple library projects, one of which is
required to be shared with one of my colleague who's working
in a another project.
11. Dependency Management
• dependencies DSL element is part of the standard Gradle
• Can add dependencies on local and remote libraries
• To add a dependency have to provide library on the compile
configuration under dependencies DSL
• Everything added to the compile configuration get packaged in
to the final APK
• Gradle will follow all dependencies transitively
12. Dependencies On Multiple Projects
• Each projects will have its own build.gradle declaring how it
gets built
• There will be a file called settings.gradle at the root, which
define which folder is a Gradle project
• If there are more than one library, importing order should be
considered on dependencies on each other
13. Publish Library To Artifact Repo
• Publish artifacts to local artifact repository
Maven Central
● Proper release and
snapshot release
management
14. Usecase :2
• I want to make a digitally signed and secured release
version of my app
15. Build types
• This is achieved by buildTypes DSL
• By default, the android plugin automatically sets up the
project to build both a debug and a release version of the
application
• Difference is that the ability to enable debug and how the APK
is signed
• It allows to customize both debug and release versions, as
well as creating other build types
16. Build Types…
• Build Types can contribute to the build with code and
resources.
• For each Build Type, a new matching sourceSet is created,
under src directory
src/<buildtypename>/
• This means the Build Type names cannot be main or
instrumentTest
17. Signing APK
• Android system will not install or run an application that is not
signed appropriately.
• To sign an APK have to make use of signingConfigs DSL
18. Obfuscating
• Tool ProGuard is used automatically to obfuscate the APK
• It will rename classes, fields, and methods with semantically
obscure names to make it difficult to reverse engineer.
• Android plugin support proguard version is 4.10
• ProGuard will shrinks, optimizes, and remove unused code
which will result smaller APK
19. Usecase : 3
• I want to make a free version of my application with less
features and commercial version with all features.
20. Build Variants
– Different versions of the same application or Same
application packaged differently or combination of both.
• Have to occupy productFlavors DSL
• Build Type + Product Flavor = Build Variant
• Product flavor will generate APK’s for all possible
combinations of Build Types and Product Flavors
Debug Release
Free Free-Debug Free-Release
Commercial Commercial-Debug Commercial-Release
21. Usecase : 4
I want to unit test my project with a testing framework,
22. Testing
• No need to have a separate test project any more it is
integrated to the application project
• Default location for the instrument test cases are located in
src/instrumentTest
• Test APK is built to test the app under test using the Android
instrumentation framework
• No need to have a AndroidManifest.xml for the app, cause it
will get generated automatically
• Test app manifest is automatically get filled with the package
name and the instrument test runner
23. Usecase : 5
• I want to measure the quality of my source code continuously
with some quality tools by Integrate it with a Continuous
Integration System