Let Gradle – Build your Android app



Let Gradle – Build your Android app

0 1


android-gradle-presentation

Let Gradle build your Android App

On Github weel / android-gradle-presentation

Let Gradle

Build your Android app

Morten Weel Johnsen @mwjohnse - xkcd

Themes

Choose theme to view in: Sky - Beige - Simple - Serif - Night - Default

Motivation

Avoid these..
      make: *** [android] Error 2
        

Why something else? (1)

  • Current way is complex & error prone
  • Avoid make all, mm dependencies
  • Should be easier to run tests
  • Time to first commit should go faster
  • Faster

Why? (2)

  • Integration with IntelliJ/Android Studio
  • Linting
  • Tests
  • Easy to use
  • More control
  • No need to build dependencies (make, mm)
  • Automation
  • Flavours and build variants

Gradle structure

conversation application/
└── build.gradle       # Contains build script
└── gradlew            # Downloads gradle
└── local.properties   # sdk.dir= (Path to sdk)
└── wrapper
    ├── gradle-wrapper.jar
    └── gradle-wrapper.properties

Simple buildscript

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"
}

Specify sourcesets

#file build.gradle

android {

 sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
}

Get started - Demo

$ ./gradlew tasks   # Lists all tasks available

$ ./gradlew fetchDepencencies  # Fetch static dependencies from jenkins

$ ./gradlew installKeystore  # creates java keystore needed to sign apk

$ ./gradlew build

$ ./gradlew installDebug

$ ./gradlew lint

IntelliJ or Android studio

Would go for Android studio as its updated more frequently. Altough it might give some more bugs.

How to setup?

Import project as gradle project. Structure is already defined in gradle.

“I’ve known people who have not mastered their tools who are good programmers, but not a tool master who remained a mediocre programmer.” – Kent Beck

Questions?