continuous integration with maven for android apps

25
Continuous Integration (CI) with Maven for Android applications Hugo Josefson @ GTUG Malmö 2011

Upload: hugojosefson

Post on 13-May-2015

7.336 views

Category:

Technology


3 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Continuous Integration with Maven for Android apps

Continuous Integration (CI)with Maven

for Android applications

Hugo Josefson @ GTUG Malmö 2011

Page 2: Continuous Integration with Maven for Android apps

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

Page 3: Continuous Integration with Maven for Android apps

What's the problem?

Page 4: Continuous Integration with Maven for Android apps

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

Page 5: Continuous Integration with Maven for Android apps

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

Page 6: Continuous Integration with Maven for Android apps

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?

Page 7: Continuous Integration with Maven for Android apps

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

Page 8: Continuous Integration with Maven for Android apps

Maven

Page 9: Continuous Integration with Maven for Android apps

What is Maven?

• A build tool (and more: bit.ly/whatIsMaven)• Default directory structure – overridable• Plugins

Page 10: Continuous Integration with Maven for Android apps

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)

Page 11: Continuous Integration with Maven for Android apps

MavenDefault Directory Structure

Page 12: Continuous Integration with Maven for Android apps

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

Page 13: Continuous Integration with Maven for Android apps

Maven vsDependency management

• External jars Dependency declaration→

<dependency>

<groupId>commons-lang</groupId>

<artifactid>commons-lang</artifactId>

<version>2.5</version>

</dependency>

Page 14: Continuous Integration with Maven for Android apps

Maven vsDependency management

• Inter-project dependencies Dep. declaration→– Example: morse-lib by Manfred Moser

Page 15: Continuous Integration with Maven for Android apps

Maven vsDeveloper / 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→

Page 16: Continuous Integration with Maven for Android apps

DEMO TIME!

Page 17: Continuous Integration with Maven for Android apps

How to set up

Android apps for Maven

[DEMO]

Page 18: Continuous Integration with Maven for Android apps

How to set up

Android tests for Maven

[DEMO]

Page 19: Continuous Integration with Maven for Android apps

How to set up

Continuous Integration

[DEMO]

Jenkins + Android SDKAndroid Emulator Plugin

Maven project

Page 20: Continuous Integration with Maven for Android apps

Maven Android resources

Getting Started + discussion group:http://code.google.com/p/maven-android-plugin

Google: maven android

Questions?

Page 21: Continuous Integration with Maven for Android apps

Extra stuff

(if time allows)

Page 22: Continuous Integration with Maven for Android apps

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

Page 23: Continuous Integration with Maven for Android apps

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-samplesgit clone --recursive \git://github.com/jayway/robotium-samples.git

Page 24: Continuous Integration with Maven for Android apps

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)

Page 25: Continuous Integration with Maven for Android apps