This document discusses building Android apps with Gradle. It introduces the motivation for moving to Gradle from Ant and the Eclipse ADT plugin by describing requirements for customization and support across IDEs and CI servers. Key aspects of Gradle covered include the Android plugin, build variants, product flavors, and customizing the build configuration. Demos show how to manipulate tasks and work with variants. The document also briefly outlines testing, dependencies, and ongoing work.
6. OLD ANDROID BUILDSOLD ANDROID BUILDS
Two (official) build mechanism
ADT (Eclipse based)
Ant
Maven
Customization?
Nothing in ADT
Manually hacking xml in ant scripts
7. REQUIREMENTS OF THEREQUIREMENTS OF THE
NEW BUILD SYSTEMNEW BUILD SYSTEM
Use same system for
CommandLine
CI Server
IDE
Support for application/library variants
Dependency Management
Provide a plugin ecosystem
8. WHY GRADLEWHY GRADLE
Allows custom DSL to express build logic
Very flexible for customization
Well integrated with CI ecosystem (Ant, Maven, Ivy, CI
server)
Allow User / 3Party tools to configure, extend and
customize the build process
Tooling API for IDE integration
...
9. GRADLE IN A NUTSHELLGRADLE IN A NUTSHELL
apply plugin:'java'
version = file("version.txt").text
task helloWorld << {
println "Hello World - version '$version'!"
}
14. PRODUCT FLAVORSPRODUCT FLAVORS
"a way to generate several versions of the same app"
Customize app parameters
package name
min/targetSdkVersion
versionCodeName
signing info
Source code + resources overlay
Custom dependencies
15. BUILD VARIANTSBUILD VARIANTS
"a variant is always a flavor + a type"
debug release
free free-debug free-release
payed payed-debug payed-release
16. BUILD VARIANTS IIBUILD VARIANTS II
PRODUCT FLAVOR GROUPSPRODUCT FLAVOR GROUPS
debug release
free x86 free-x86-debug free-x86-release
ARM free-ARM-debug free-ARM-release
payed x86 payed-x86-debug payed-x86-release
ARM payed-ARM-debug payed-ARM-release
17. FLAVOR GROUPSFLAVOR GROUPS
flavorDimensions "group1", "group2"
productFlavors {
arm {
flavorDimension "group1"
}
x86 {
flavorDimension "group1"
}
free {
flavorDimension "group2"
}
pro {
flavorDimension "group2"
}
}
24. TESTINGTESTING
no separate test project needed
variant aware tests
run against (all) connected devices
experimental unit test support (android build tools 1.1)
android {
// ...
testOptions {
unitTests.returnDefaultValues = true
}
}
25. PLENTY OF MORE THINGSPLENTY OF MORE THINGS
android libraries (aar)
vivid plugin ecosystem
crashlytics
roboelectrics
testfairy
instabug
...