Post on 02-Jul-2015
description
Dominik Helleberg | inovex GmbH
Moderne Android Builds mit Gradle
„Gradle is the most advanced, next generation build system“ Hans Dockter
„You should really give it a try (not only for android)“ Dominik Helleberg
Dominik Helleberg
Mobile Development
Android / Embedded
Tools
http://dominik-helleberg.de/+
Android Studio !!!
Gradle + !Android Plugin!
or !„The new build system“
The new Dream Team !
new? !Oktober !2012
Mai !2013
https://plus.google.com/u/0/+XavierDucrohet/posts/XnW7t9XJCMJ !
ready? !Version !0.10.+
Version !0.5.8
Android PlugIn
Android Designer
Android PlugIn
Android DDMS
Android Builder .properties
build.xml
Android PlugIn
Android Designer
Android PlugIn
Android Gradle Adapter .properties
build.gradle
Best of ANT / Maven / GANT / Ivy !Based on Groovy Scripts !Expressive DSL !(Flexible) Convention over Configuration!Easy to extend!!„Make the impossible possible, make the possible easy and make the easy elegant.” !!!!
„hello groovy & gradle“ !!
Code !
dist compile
compileTest test
3 Phasen: !Initialization!Configuration!Execution!
!
apply plugin: 'android' !!android { ! compileSdkVersion 19 ! buildToolsVersion "19.0.3" !! defaultConfig { ! minSdkVersion 7 ! targetSdkVersion 19 ! versionCode 1 ! versionName "1.0" ! } ! buildTypes { ! release { ! runProguard false! proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' ! } ! } !} !!dependencies { ! compile 'com.android.support:appcompat-v7:+' ! compile fileTree(dir: 'libs', include: ['*.jar', '*.aar']) !} !!!!!
Android PlugIn 0.10.+ !
Core Features !!• Konfigurierbare Manifest Attribute !• Build Varianten !• Tests integriert !• BuildConfig konfigurierbar !• Signierung konfigurierbar !• Tools versioniert!• Multiproject-Support !• Dependency Management !• Binary Lib Format (AAR) !• Lint integration!• Dex + AAPT Options !
apply plugin: 'android' !!android { ! compileSdkVersion 19 ! buildToolsVersion "19.0.3" !! defaultConfig { ! minSdkVersion 7 ! targetSdkVersion 19 ! versionCode 1 ! versionName "1.0" ! } ! buildTypes { ! release { ! runProguard false! proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' ! } ! } !} !!dependencies { ! compile 'com.android.support:appcompat-v7:+' ! compile fileTree(dir: 'libs', include: ['*.jar', '*.aar']) !} !!!!!
Demo PlugIn!
Build targets!Variants!
!Code !
Android PlugIn 0.10.+ !
Extension: !Automatische Versions-Verwaltung !
Ziel: !"Version Code !"Version Name !"- einfach konfigurierbar halten !"- aus git-tags extrahieren und in gradle setzen !"!"Build-Informationen in der App verfügbar machen: !" "- Build-HOST !" "- Build-TIME !
!!
Android PlugIn 0.10.+ !
Automatische Versions-Verwaltung !
Schritt 1: !!Build-Informationen in App anzeigen !!
" "Build-Time !" "Build-Host !"!
über BuildConfig!
Android PlugIn 0.10.+ !
Automatische Versions-Verwaltung !
Schritt 2: !!Konfiguration von !!
" "Version Code !"!
über eine Property-Datei !
Android PlugIn 0.10.+ !
Automatische Versions-Verwaltung !
Schritt 3: !!Berechnung von versionCode und versionName!!
"version=2.1.3 !!
"versionCode=2130 !"VersionName=2.1.3 !
Android PlugIn 0.10.+ !
Automatische Versions-Verwaltung !
Schritt 4: !!Versionsnummer aus git Tag auslesen !!
" "git-Tag „2.1.3“ !!
Android PlugIn 0.10.+ !
Automatische Versions-Verwaltung !
Schritt 5: !!Versionsnummer + App Name dem APK hinzufügen !!<name>-<sub-name>-<buildType>-<version>.apk!
Android PlugIn 0.10.+ !
Automatische Versions-Verwaltung !
Modularisieren: !!inside build-scripts!!buildSrc/ !!external build-scripts (local file or http) !apply from:'https://raw.github.com/../all-jars.gradle‘ !apply from:'~/.gradle/RobertFischer/gradle-scripts/all-jars.gradle‘ !!via dependencies / Repository !
Android PlugIn 0.10.+ !
Key Features !!• Build!• runTests (emulator / device / cloud) !• Code Coverage!• Lint!• Monkey!• ... !
Key Features !Build Variants!
BuildTypes!ProductFlavour!
debug!
UAT !
release!
int!
ext !
Builds!int-debug!ext-debug!
int-UAT !ext-UAT !
int-release !ext-release !
Key Features !Build Variants!
Demo Android Studio !
Key Features !The „old“ World !
Key Features !Build Variants Directory structure!
src/
int/ java/ res/ ext/ java/ res/ main/ java/ res/
androidTest/ java/
Key Features !
• Layout Editor !
• IntelliJ Features !
• Improved Checks !
• Improved UI !
• ... !!!!
Status Quo !
• Mostly stable but expect breaking changes!
• Documentation poor!
• Many examples might not work (old versions) !
• Features are worth considering it
• Mostly stable!
• Unpredictable updates!
• Tools & Features missing!
• IntelliJ EAP Release
Empfehlung !
• „I‘m feeling lucky“ !
• Multiproject-Builds!
• Safe side: stay with eclipse (but maybe use gradle) !
• Gradle will be mandatory / Android Studio is optional !
!!
Tipps + Tricks !
http://www.manning.com/muschko/
Tipps + Tricks !Gradle daemon
$> cat .gradle/gradle.properties
org.gradle.daemon=true
org.gradle.jvmargs=-‐Xmx2048m
-‐XX:MaxPermSize=512m
-‐Dfile.encoding=UTF-‐8
Show dependencies
$> gradle dependencies
Tipps + Tricks !Gradle Init Scripts $> cat .gradle/init.gradle initscript { allprojects {
apply plugin: 'maven’ repositories { maven { url = "http://archiva.inovex.de:8080/archiva/repository/snapshots/" } } } }
Tipps + Tricks !Gradle Wrapper
./gradlew Instead of gradle Initialize with: task wrapper (type: Wrapper) {
gradleVersion = “1.11” }
Tipps + Tricks !Android-SDK-PlugIn - Like the wrapper but for the SDK
dependencies { classpath 'com.android.tools.build:gradle:0.10.+' classpath 'com.jakewharton.sdkmanager:gradle-‐plugin:0.9.1‘ } apply plugin: 'android-‐sdk-‐manager’ apply plugin: 'android'
$> gradle assembleDebug -‐-‐profile
DANKE!
„Gradle is the most advanced, next generation build system“ Hans Dockter
„You should really give it a try (not only for android)“ Dominik Helleberg