Auf Augenhöhe mit Android Studio und Gradle

Post on 09-May-2015

316 views 2 download

description

Mit Android Studio und dem neuen Gradle-Build-System stehen der Community große Veränderungen ins Haus. Neben der Euphorie gibt es allerdings auch Skepsis: Was wird aus den bestehenden Tools? Wie stabil und bugfrei sind die "neuen" schon? Und halten sie auch was sie versprechen? Wir zeigen an praktischen Beispielen die Vorteile und Tücken der neuen Tools im täglichen Entwickeln und im CI-Server Einsatz.

Transcript of Auf Augenhöhe mit Android Studio und Gradle

Dominik Helleberg | inovex GmbH

Auf Augenhöhe mit Android Studio und Gradle

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.9.+

Version !0.5.1

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.2" !! 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.9.+ !

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.2" !! 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.9.+ !

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 !

!!

Android PlugIn 0.9.+ !

Automatische Versions-Verwaltung !

Schritt 1: !!Build-Informationen in App anzeigen !!

" "Build-Time !" "Build-Host !"!

über BuildConfig!

Android PlugIn 0.9.+ !

Automatische Versions-Verwaltung !

Schritt 2: !!Konfiguration von !!

" "Version Code !" "Version Name !"!

über eine Property-Datei !

Android PlugIn 0.9.+ !

Automatische Versions-Verwaltung !

Schritt 3: !!Berechnung von versionCode und versionName!!

"version=2.1.3 !!

"versionCode=2130 !"VersionName=2.1.3 !

Android PlugIn 0.9.+ !

Automatische Versions-Verwaltung !

Schritt 4: !!Versionsnummer aus git Tag auslesen !!

" "git-Tag „2.1.3“ !!

Android PlugIn 0.9.+ !

Automatische Versions-Verwaltung !

Schritt 5: !!Versionsnummer + App Name dem APK hinzufügen !!<name>-<sub-name>-<buildType>-<version>.apk!

Android PlugIn 0.9.+ !

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.9.+ !

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  

 

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/"                          }                  }          }  }  

$>  gradle  assembleDebug  -­‐-­‐profile  

DANKE!