Ci for-android-apps

Embed Size (px)

Citation preview

Continuous Integration for Android Apps

Continuous Integration for Android Apps

Anthony Dahanne, Eng.

@anthonydahanne

http://blog.dahanne.net

Getting to know each other ...

Work @compuware on a APM software based on OSGi and Equinox

Develop an open source app on Android, ReGalAndroid

Work on Continuous Integration (contribute to tools such as Maven Tycho, m2e-android)

Continuous Integration for Android Apps

A gentle introduction to Continuous Integration

Building an Android app

Testing an Android App

Setting up a CI tool for Android development

Going further than CI...

A gentle introduction to Continuous Integration (CI)

A gentle introduction to CI : what is it ?

the practice of frequently integrating one's new or changed code with the existing code repository Wikipedia

Each code change triggers a new build of the software

Each build should be working (not broken)

CI jobs occur on dedicated machines running CI tools such as Hudson/Jenkins/CruiseControl/Bamboo/TravisCI

Code compiles

Tests pass

Packages build (jar, apk, etc..)

See this as a Cron tableFrom wikipedia : Advantages

when unit tests fail or a bug emerges, developers might revert the codebase to a bug-free state, without wasting time debugging developers detect and fix integration problems continuously - avoiding last-minute chaos at release dates, (when everyone tries to check in their slightly incompatible versions). early warning of broken/incompatible code early warning of conflicting changes immediate unit testing of all changes constant availability of a "current" build for testing, demo, or release purposes immediate feedback to developers on the quality, functionality, or system-wide impact of code they are writing frequent code check-in pushes developers to create modular, less complex code[citation needed] metrics generated from automated testing and CI (such as metrics for code coverage, code complexity, and features complete) focus developers on developing functional, quality code, and help develop momentum in a team[citation needed]

Disadvantages

initial setup time required well-developed test-suite required to achieve automated testing advantages hardware costs for build machines can be significant

Many teams using CI report that the advantages of CI well outweigh the disadvantages.[9] The effect of finding and fixing integration bugs early in the development process saves both time and money over the lifespan of a project.

A gentle introduction to CI : benefits ?

Coding within a team, makes sure no one commits broken code

makes it easy to get the latest good build

And more generallyEases the distribution of your software

Shows the quality and robustness of your code

Building an Android app

Building an Android app

Building an Android app

Building an Android app : outside the IDE

ADT exists for each major platform (Win, Linux, Mac)

The IDE integration is only (officially) provided for Eclipse

For Continuous Integration, we want to :Build outside the IDE,

Build on the command line, so that a CI tool can run the build

Building an Android app : the choices

In the Java world, the main build automation tools are Ant and Maven (equivalent of make in the C world)

Apache AntAppeared in 2000

Very versatile

Still very popular

Apache MavenConvention over configuration

Build lifecycle

Dependencies management

Building an Android app : with Ant

Ant is the official building tool chosen by the ADT team

The Ant script can be generated and used easily from an Android project :

> android update project --path ./Updated local.propertiesAdded file ./build.xmlUpdated file ./proguard.cfg> ant debug install[]BUILD SUCCESSFUL

Demo : generate an ant script to build your project

Hint !> ant -pTo list all available targets

Building an Android app : with Maven

Maven privileges convention over configurationIt is extensible via plugins (eg : android-maven-plugin !)

Project dependencies are fetched and cached

It provides a default execution lifecycle (you can bound a plugin execution to each phase of the lifecycle)

Building an Android app : with Maven

compilerplugin
compile

surefire plugin
test

validate

compile

test

package

integration-test

verify

install

deploy

deploy plugin
deploy

The default lifecycle

This schema is taken from Fabrizio Giudici Building Android Apps with Maven slides

Building an Android app : with Maven

2 ways to get started with a Maven enabled Android project :Start from scratch with android archetypes :

Copy and adapt an existing pom.xml

> mvn archetype:generate \ -DarchetypeArtifactId=android-quickstart \ -DarchetypeGroupId=de.akquinet.android.archetypes \ -DarchetypeVersion=1.0.7 \ -DgroupId=your.company \ -DartifactId=my-android-application> cd my-android-application> mvn install android:deploy android:run

Demo : generate a Maven pom to build your project

Hint ! > mvn help:describe -Dplugin=androidto list all availlable goals

Building an Android app : with Maven

commons-galleryReGalAndroid app

g2-java-clientg3-java-clientjiwigo-ws-api

commons-iohttpclientjsonhttpclienthttpmimecommons-langhttpcorecommons-loggingcommons-codec(transitive)dependencies

Building an Android app : which one to choose ?

The Ant script Is generated by ADT but

Does not deal with dependencies (must copy to lib/)

And is not easily extensible

The Android Maven PluginCovers all android specific build steps (proguard, etc...)

Is integrated in the Eclipse IDE (thanks to m2e-android)

Leverages existing Maven plugins (deploy, replace,etc...)

Testing an Android app

Testing an Android app

Outside an emulator :Externalize your logic in plain jars

Use an Android Mocker (robolectric)

Inside an emulatorIntegration testing : tests run in a real device (robotium helps !)

Testing an Android App

ReGalAndroid app

ReGalAndroid Integration tests

1. Install the app

2. Install the test app

3. run the app and run the test app

Demo : running ReGalAndroid integration tests

Setting up a CI tool for Android development

Setting up a CI tool

As long as the CI tool supports Maven it should work

Environment must be set upPATH + JAVA_HOME, M2_HOME, ANDROID_HOME set

Download the SDK and :

> android update sdk --no-ui --obsolete force (be careful >2GB as of January '12)> android update sdk --no-ui -t platform force(just the Android platforms, no samples, no addons, no extras...)> android update sdk --no-ui -t platform-tools force(Android platform-tools : aadt, adb, etc...)> android create avd -n 23 -t 9 -c 16M -b armeabi(to create an AVD/Emulator)

Hint !Use :> echo no | android create avd -n 23 -t 9 -c 16M -b armeabinot to be promped to create a hardware profile !

Setting up a CI tool : case of a server (not GUI)

Android EmulatorIs needed for the integration tests

But needs an X server !

Hudson/Jenkins Xvnc plugin to the rescue !

Or, even better, Hudson/Jenkins Android Emulator Plugin

Demo : a Jenkins job building an android app

Going further than Continuous Integration

Going further than CI : continuous quality control

At each build, check :The tests run

Code coverage of the tests

Quality metrics of the tests, with Checkstyle, Findbugs, PMD /CPD

Sonar does it all !Quality dashboard of your projects

Provides : timeline, rules, diagrams, high level views, etc.

Going further than CI : continuous deployment

At each build (or milestone / nightly builds)Deploy to a an archive repository (such as Nexus)

Use some tooling to push to devices ?

Thank you
Now please vote
and react on https://joind.in/6032 !

ArtThe template used for this presentation was the LibreOffice Presentation Template 1.0

The Android pictures belong to Google http://tools.android.com/overview

Tools, documentation, useful blogs for Android development and CIDocumentation on the Android Maven Plugin can be found reading the Maven Reference Book

Updating Android SDK from the command line

Manfred Moser's blog

Using Android Maven Artifacts

See a device screen on your computer : Droid@Screen

Use Hudson/Jenkins or try TravisCI out, for CI Sonar, to check on your code quality , and Nexus as an artifact repository manager

All text and image content in this document is licensed under the Creative Commons Attribution-Share Alike 3.0 License (unless otherwise specified). "LibreOffice" and "The Document Foundation" are registered trademarks. Their respective logos and icons are subject to international copyright laws. The use of these therefore is subject to the trademark policy.

@anthonydahanne

@anthonydahanne