30

Building android apps with Gradle (GREACH 2015)

Embed Size (px)

Citation preview

Page 1: Building android apps with Gradle (GREACH 2015)
Page 2: Building android apps with Gradle (GREACH 2015)

BUILDING ANDROID APPSBUILDING ANDROID APPSWITH GRADLEWITH GRADLEGREACH 2015, MadridRené GröschkePrincipal Engineer Gradleware

Page 3: Building android apps with Gradle (GREACH 2015)

INTRO, DEMO & FORECASTINTRO, DEMO & FORECAST

Page 4: Building android apps with Gradle (GREACH 2015)

WHY A NEW BUILDWHY A NEW BUILDSYSTEM?SYSTEM?

Page 5: Building android apps with Gradle (GREACH 2015)

GRADLE 2.3GRADLE 2.3RELEASED 16TH FEBRUARY 2015RELEASED 16TH FEBRUARY 2015

Page 6: Building android apps with Gradle (GREACH 2015)

OLD ANDROID BUILDSOLD ANDROID BUILDSTwo (official) build mechanism

ADT (Eclipse based)AntMaven

Customization?

Nothing in ADTManually hacking xml in ant scripts

Page 7: Building android apps with Gradle (GREACH 2015)

REQUIREMENTS OF THEREQUIREMENTS OF THENEW BUILD SYSTEMNEW BUILD SYSTEM

Use same system forCommandLineCI ServerIDE

Support for application/library variantsDependency ManagementProvide a plugin ecosystem

Page 8: Building android apps with Gradle (GREACH 2015)

WHY GRADLEWHY GRADLEAllows custom DSL to express build logicVery flexible for customizationWell integrated with CI ecosystem (Ant, Maven, Ivy, CIserver)Allow User / 3Party tools to configure, extend andcustomize the build processTooling API for IDE integration...

Page 9: Building android apps with Gradle (GREACH 2015)

GRADLE IN A NUTSHELLGRADLE IN A NUTSHELLapply plugin:'java'

version = file("version.txt").text

task helloWorld << { println "Hello World - version '$version'!"}

Page 10: Building android apps with Gradle (GREACH 2015)

THE ANDROID GRADLE PLUGINTHE ANDROID GRADLE PLUGINMINIMAL ANDROID BUILDMINIMAL ANDROID BUILD

plugins { id 'com.android.application' version '1.1.+'}

android { compileSdkVersion 22 buildToolsVersion '22.0.1'}

>gradle check assemble>gradle build

Page 11: Building android apps with Gradle (GREACH 2015)

THE ANDROID GRADLE PLUGINTHE ANDROID GRADLE PLUGINBASIC BUILD CUSTOMIZATIONBASIC BUILD CUSTOMIZATION

android { compileSdkVersion 22 buildToolsVersion '22.0.1'

defaultConfig { versionCode 12 versionName "2.0" minSdkVersion 19 targetSdkVersion 22 multiDexEnabled = true }}

Page 12: Building android apps with Gradle (GREACH 2015)

THE ANDROID GRADLE PLUGINTHE ANDROID GRADLE PLUGINREMEMBER, IT'S GROOVY!REMEMBER, IT'S GROOVY!

def calculateVersionName() { ...}android { compileSdkVersion 22 buildToolsVersion '22.0.1'

defaultConfig { versionName calculateVersionName() }}

Page 13: Building android apps with Gradle (GREACH 2015)

BUILD TYPESBUILD TYPES"controls how an app is built"

Customize app parametersdebuggable flagnative debug compilation flagpackage suffixdebug signingproguard options2 default types (debug + release)

Source code + resources overlayCustom dependencies

Page 14: Building android apps with Gradle (GREACH 2015)

PRODUCT FLAVORSPRODUCT FLAVORS"a way to generate several versions of the same app"

Customize app parameterspackage namemin/targetSdkVersionversionCodeNamesigning info

Source code + resources overlayCustom dependencies

Page 15: Building android apps with Gradle (GREACH 2015)

BUILD VARIANTSBUILD VARIANTS"a variant is always a flavor + a type"

debug releasefree free-debug free-release

payed payed-debug payed-release

Page 16: Building android apps with Gradle (GREACH 2015)

BUILD VARIANTS IIBUILD VARIANTS IIPRODUCT FLAVOR GROUPSPRODUCT FLAVOR GROUPS

debug releasefree 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

Page 17: Building android apps with Gradle (GREACH 2015)

FLAVOR GROUPSFLAVOR GROUPS

flavorDimensions "group1", "group2"

productFlavors { arm { flavorDimension "group1" } x86 { flavorDimension "group1" } free { flavorDimension "group2" } pro { flavorDimension "group2" }}

Page 18: Building android apps with Gradle (GREACH 2015)

SOURCE CODE + RESOURCES OVERLAYSOURCE CODE + RESOURCES OVERLAY

~/dev/androidApp/src>tree |____main | |____java | |____res |____androidTest | |____java | |____res |____free | |____java | |____res |____debug | |____java ~/dev/androidApp/src>

Build Type > Product Flavor > main

Page 19: Building android apps with Gradle (GREACH 2015)

DEMO IDEMO IVARIANTS IN ACTIONVARIANTS IN ACTION

Page 20: Building android apps with Gradle (GREACH 2015)

BUILD CUSTOMIZATION IBUILD CUSTOMIZATION IDEX CONFIGURATIONDEX CONFIGURATION

android { dexOptions { incremental true preDexLibraries = false jumboMode = false }}

Page 21: Building android apps with Gradle (GREACH 2015)

BUILD CUSTOMIZATION IIBUILD CUSTOMIZATION IIAAPT CONFIGURATIONAAPT CONFIGURATION

android { aaptOptions { noCompress 'foo', 'bar' ignoreAssetsPattern "!.svn:!.git:!.ds_store:!*.scc" }}

Page 22: Building android apps with Gradle (GREACH 2015)

BUILD CUSTOMIZATION IIIBUILD CUSTOMIZATION IIIAND MOREAND MORE

lintjava compile optionsproguard

Page 23: Building android apps with Gradle (GREACH 2015)

DEMO IIDEMO IIMANIPULATING TASKSMANIPULATING TASKS

Page 24: Building android apps with Gradle (GREACH 2015)

TESTINGTESTINGno separate test project neededvariant aware testsrun against (all) connected devicesexperimental unit test support (android build tools 1.1)

android { // ... testOptions { unitTests.returnDefaultValues = true }}

Page 25: Building android apps with Gradle (GREACH 2015)

PLENTY OF MORE THINGSPLENTY OF MORE THINGSandroid libraries (aar)vivid plugin ecosystem

crashlyticsroboelectricstestfairyinstabug...

Page 26: Building android apps with Gradle (GREACH 2015)

UNDER CONSTRUCTIONUNDER CONSTRUCTIONNDK supportvariant aware dependency managementsignificant performance improvements

Page 27: Building android apps with Gradle (GREACH 2015)

LINKS AND POINTERSLINKS AND POINTERShttp://tools.android.com/tech-docs/new-build-system/user-guidehttps://groups.google.com/forum/#!forum/adt-devgradle.orggradleware.comhttps://github.com/breskeby/android-demo-app

Page 28: Building android apps with Gradle (GREACH 2015)

Q&AQ&A

Page 29: Building android apps with Gradle (GREACH 2015)
Page 30: Building android apps with Gradle (GREACH 2015)

¡MUCHAS¡MUCHASGRACIAS!GRACIAS!

! @breskeby

" github.com/breskeby

# [email protected]