Moderne Android Builds mit Gradle

709 views

Published on

Das neue Android Build System ist angetreten, um viele Probleme der Vergangenheit zu lösen. Mit Gradle als Basis, einem komplexen Plug-in speziell für Android und einer tiefen Integration in Android Studio kann man schon von einem "Next Generation" Build-System sprechen. Doch was bringt die neue Technologie in der Praxis, und wie kann ich die neuen Features in meinem Entwicklungsprozess nutzen?

Wir zeigen praktische Beispiele vom Projekt-Setup über den Build-Prozess und Konfigurationsmanagement bis hin zur CI-Integration sowie Erfahrungen mit der Migration existierender Projekte. Source Code: https://github.com/dhelleberg/androidgradlesample

Published in: Software
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
709
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Moderne Android Builds mit Gradle

  1. 1. Dominik Helleberg | inovex GmbH Moderne Android Builds mit Gradle
  2. 2. „Gradle is the most advanced, next generation build system“ Hans Dockter „You should really give it a try (not only for android)“ Dominik Helleberg
  3. 3. Dominik Helleberg Mobile Development Android / Embedded Tools http://dominik-helleberg.de/+
  4. 4. Android Studio! ! ! Gradle +! Android Plugin! or! „The new build system“ The new Dream Team!
  5. 5. new?! Oktober ! 2012 Mai! 2013 https://plus.google.com/u/0/+XavierDucrohet/posts/XnW7t9XJCMJ!
  6. 6. ready?! Version! 0.10.+ Version! 0.5.8
  7. 7. Android PlugIn Android Designer Android PlugIn Android DDMS Android Builder .properties build.xml
  8. 8. Android PlugIn Android Designer Android PlugIn Android Gradle Adapter .properties build.gradle
  9. 9. 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.” ! ! !
  10. 10. „hello groovy & gradle“! ! Code!
  11. 11. distcompile compileTest test 3 Phasen:! Initialization! Configuration! Execution! !
  12. 12. 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'])! }!
  13. 13. 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'])! }!
  14. 14. Demo PlugIn! Build targets! Variants! ! Code! Android PlugIn 0.10.+!
  15. 15. 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.+!
  16. 16. Automatische Versions-Verwaltung! Schritt 1:! ! Build-Informationen in App anzeigen ! ! " "Build-Time! " "Build-Host! "! über BuildConfig! Android PlugIn 0.10.+!
  17. 17. Automatische Versions-Verwaltung! Schritt 2:! ! Konfiguration von ! ! " "Version Code! "! über eine Property-Datei! Android PlugIn 0.10.+!
  18. 18. Automatische Versions-Verwaltung! Schritt 3:! ! Berechnung von versionCode und versionName! ! "version=2.1.3! ! "versionCode=2130! "VersionName=2.1.3! Android PlugIn 0.10.+!
  19. 19. Automatische Versions-Verwaltung! Schritt 4:! ! Versionsnummer aus git Tag auslesen! ! " "git-Tag „2.1.3“! ! Android PlugIn 0.10.+!
  20. 20. Automatische Versions-Verwaltung! Schritt 5:! ! Versionsnummer + App Name dem APK hinzufügen! ! <name>-<sub-name>-<buildType>-<version>.apk! Android PlugIn 0.10.+!
  21. 21. 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.+!
  22. 22. Key Features! ! •  Build! •  runTests (emulator / device / cloud)! •  Code Coverage! •  Lint! •  Monkey! •  ...!
  23. 23. Key Features! Build Variants! BuildTypes!ProductFlavour! debug! UAT! release! int! ext! Builds! int-debug! ext-debug! int-UAT! ext-UAT! int-release! ext-release!
  24. 24. Key Features! Build Variants! Demo Android Studio!
  25. 25. Key Features! The „old“ World!
  26. 26. Key Features! Build Variants Directory structure!     src/    int/      java/      res/    ext/      java/      res/    main/      java/      res/      androidTest/                java/  
  27. 27. Key Features! •  Layout Editor! •  IntelliJ Features! •  Improved Checks! •  Improved UI! •  ...! ! ! !
  28. 28. 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
  29. 29. Empfehlung! •  „I‘m feeling lucky“! •  Multiproject-Builds! •  Safe side: stay with eclipse (but maybe use gradle)! •  Gradle will be mandatory / Android Studio is optional! ! !
  30. 30. Tipps + Tricks! http://www.manning.com/muschko/
  31. 31. 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    
  32. 32. 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/"                          }                  }          }   }  
  33. 33. Tipps + Tricks! Gradle Wrapper    ./gradlew     Instead of    gradle       Initialize with: task  wrapper  (type:  Wrapper)  {    gradleVersion  =  “1.11”   }    
  34. 34. 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'    
  35. 35. $>  gradle  assembleDebug  -­‐-­‐profile  
  36. 36. DANKE!
  37. 37. „Gradle is the most advanced, next generation build system“ Hans Dockter „You should really give it a try (not only for android)“ Dominik Helleberg

×