gradle & android studio - introduction

27
An introduction Gradle & Android Studio

Upload: kevin-pelgrims

Post on 06-May-2015

1.865 views

Category:

Technology


3 download

DESCRIPTION

This is a very high level overview of Gradle. Android Studio tips and tricks were shown during demos, so the slides themselves don't really contain any info on Android Studio.

TRANSCRIPT

An introduction

Gradle & Android Studio

FIRSTDRIVRdrivr.com@drivr

Schedule

● Why Gradle?● Converting an existing project● Build types and product flavors● Custom tasks● Testing● Continuous integration

Why Gradle?

Pros

● Not Ant

● Groovy-based

● Gradle wrapper

● Multi-project builds

● Dependency management

Cons

● Slower than Ant

● Documentation

● Android plugin under development

● Dependency management

Demo - New project

Convert a project

How to convert

● Project structure

● Gradle wrapper

● Dependencies

Good resource:http://ryanharter.com/blog/2013/07/17/migrating-android-projects-to-gradle

Types & flavors

Build types

● E.g. debug, staging, production

● Separate packages

● Different resources

Build types - ExamplebuildTypes {

staging {

packageNameSuffix ".staging"

versionNameSuffix "-staging"

signingConfig signingConfigs.staging

}

}

Build types - ExamplesigningConfigs {

staging {

storeFile file("staging.keystore")

storePassword "storepwd"

keyAlias "alias"

keyPassword "keypwd"

}

}

Build types - Example\module

\src

\staging

\java\

\res\

\AndroidManifest.xml

Product flavors

● E.g. free, pro

● Multi APK (e.g. <= 2.2 & > 2.2)

● Combination

Setup: same as build types

Build variants

Build type + Product flavor = Build variant

● Pro Debug & Free Debug

● Pro Staging & Free Staging

● ...

Custom tasks

Custom tasks - Exampletask keyStorePassword << {

def keystorePw = new String(

System.console().readPassword("Password?"))

android.signingConfigs.release

.storePassword = keystorePw

}

Custom tasks - Exampletasks.whenTaskAdded { task ->

if (task.name.equals("packageRelease")) {

task.dependsOn "keyStorePassword"

}

}

Testing

Instrumentation tests

● No separate project○ \src\instrumentTest\

● Own dependencies

○ dependencies { instrumentTestCompile x

}

● gradlew connectedInstrumentTest

Unit tests (JUnit & Robolectric)

● No official support

● Add custom task

● Some hacking required

Continuous integration

CI with Jenkins

● Android SDK on build server

● Gradle plugin - “Invoke Gradle script”

● Emulator support

Good resource:http://blog.zuehlke.com/configure-your-android-project-on-jenkins/

Want to get started?