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
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
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. 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. 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. 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...
9. What is Maven?
• A build tool (and more: bit.ly/whatIsMaven)
• Default directory structure – overridable
• Plugins
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)
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
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→
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. 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. 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)
Editor's Notes
Yes, there are notes for some slides :)
You find+download jars, what are they named? Sometimes/Usually not w/ version numbers. Git/Svn not designed for multi-MB binary blobs. The history becomes heavy. (affects backups for svn,git; clone for git) Where can I find dependency information? Hopefully in “some documentation” on each jar's website.
How do you keep track of which version of the common lib you are using? (in each of the apk projects)
Customer says: “Doesn't work!” Developer says: “Works for me!” How do you know what each person is using, if the build server built the app one way and the developer some other way?
Let me show you what Maven and a Continuous Integration server can bring to the table, addressing each of these issues... But first, what is Maven?...
- It's more than a build tool, because it lets you define the project in terms of /what it is/ rather than defining /all the build steps/ needed to arrive at the output artifact. – You define your project in a project object model (pom file), where you tell Maven what the packaging type of your application is: jar, war, apk. It then knows what build steps are needed to build your project and where your code and resources are located by default.
– You can override the defaults if you want.
– Plugins contain the functionality: built-in core plugins for default things such as compiling a jar, and 3:rd party such as maven-android-plugin for building Android apk:s.
Maven downloads this from a Central OpenSource repository. - cached locally - If what you need is not already there, you can have your own repository where you store 3:rd party jars.
– In this case, the Library is a simple jar project, containing the main functionality. It's not tied to a particular platform, and is unit-testable. – The App project is an apk, and uses the Library via Maven dependency declaration.