Continuous Integration with Maven for Android apps

8,095 views

Published on

Why Maven can be relevant for building Android applications, and how a complete Jenkins server can be set up for building and running tests on Android applications.

Installation script for the Jenkins server is at http://github.com/hugojosefson/jenkins-with-android

Published in: Technology
  • Be the first to comment

Continuous Integration with Maven for Android apps

  1. 1. Continuous Integration (CI) with Maven for Android applications Hugo Josefson @ GTUG Malmö 2011
  2. 2. Agenda ● What's the problem? – Dependency management – Developer / Build server mismatch – Running tests ● Maven & CI – Dependency management – Developer / Build server mismatch – Running tests ● DEMO! – How to set up Android apps for Maven – How to set up Android tests for Maven – How to set up Continuous Integration
  3. 3. What's the problem?
  4. 4. What's the problem? - Dependency management • External jars • Hunt down the jars • Where to store them? (svn/git? non-optimal!) • What version was this jar? • What version of other dependency jars does it work with? – all handled manually
  5. 5. What's the problem? - Dependency management • Inter-project dependencies • common library jar – our-common-lib.jar • several apk projects depend on it – MyApp1.apk – MyApp2.apk
  6. 6. What's the problem? - Developer / Build server mismatch • Script vs IDE for building – Is the binary built the same way across developers and build servers? • Script vs IDE for testing – Is the binary tested the same way across developers and build servers?
  7. 7. What's the problem? - Running tests • Common excuses – "I don't have time for tests before commit!" – "I can't be bothered with tests before commit!" – “I forgot...” • Regressions creep in...
  8. 8. Maven
  9. 9. What is Maven? • A build tool (and more: bit.ly/whatIsMaven) • Default directory structure – overridable • Plugins
  10. 10. Maven as Build Tool • Tell Maven: – My project is a jar / war / apk / ... – I need library jar commons-lang:2.5 • Maven knows how to build that • Maven knows how to fetch libraries • (No need to specify directories, nor handle library jars)
  11. 11. Maven Default Directory Structure
  12. 12. Maven Plugins • Built-in for core functionality – Building jar – Building war – JavaDoc – Running Tests – … lots more • Extra for e.g. building / testing / deploying apk – maven-android-plugin
  13. 13. Maven vs Dependency management • External jars Dependency declaration→ <dependency> <groupId>commons-lang</groupId> <artifactid>commons-lang</artifactId> <version>2.5</version> </dependency>
  14. 14. Maven vs Dependency management • Inter-project dependencies Dep. declaration→ – Example: morse-lib by Manfred Moser
  15. 15. Maven vs Developer / Build server mismatch • Solved when both use same build and test tool – Build server can use Maven – Developer can use Maven – Maven builds and runs tests in one go – Reproducible Same build result→
  16. 16. DEMO TIME!
  17. 17. How to set up Android apps for Maven [DEMO]
  18. 18. How to set up Android tests for Maven [DEMO]
  19. 19. How to set up Continuous Integration [DEMO] Jenkins + Android SDK Android Emulator Plugin Maven project
  20. 20. Maven Android resources Getting Started + discussion group: http://code.google.com/p/maven-android-plugin Google: maven android Questions?
  21. 21. Extra stuff (if time allows)
  22. 22. Robotium • Write UI tests for Android easily with Robotium – www.robotium.org – Standalone jar (Apache License 2) – Makes it easier to write instrumentation tests – Handles all the hard stuff: – Toasts, Context menus, Timing issues, following current Activity...
  23. 23. Robotium, cont'd... • Write UI tests for Android easily with Robotium – www.robotium.org – Use normal instrumentation test class, e.g. ActivityInstrumentationTestCase2 – Some Maven-enabled robotium-samples git clone --recursive git://github.com/jayway/robotium-samples.git
  24. 24. Multi-module projects • Share code & resources between Android apps – Share code + Java resources Dependency to jar→ – Share Android resources Dependency to apklib→ » ApkLib on maven-android-plugin wiki » libraryprojects/ in Samples (beta)

×