Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ......

34
Apache Maven and Android at Manfred Moser simpligility technologies inc. http://www.simpligility.com @simpligility http://creativecommons.org/licenses/by-sa/3.0/legalcode

Transcript of Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ......

Page 1: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Apache Maven and Androidat

Manfred Moser

simpligility technologies inc.http://www.simpligility.com

@simpligility

http://creativecommons.org/licenses/by-sa/3.0/legalcode

Page 2: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

So let us find out about your background a bit..

Android development?

Other mobile/embedded development?

Java (SE, EE, ME...)?

Linux?

Apache Maven, Apache Ant?

Page 3: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

3

.. and now a bit about Manfred●Long time Linux user and Java developer currently working as Android application developer

●Author of the chapter “Android Application Development with Apache Maven” in the book Maven: The Complete Reference

●Committer on Maven Android Plugin and author of Maven Android SDK Deployer

●Maintainer of the ksoap2-android project

●Vancouver Island Java User Group Leader

Page 4: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

4

Agenda

Motivation

Brief Maven Introduction

Maven Android Tool Chain with examples

Discussion, Feedback

Page 5: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

5

Building Android Apps Currently

Eclipse ADT

Or

Default Apache Ant based build

Page 6: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

6

Whats wrong with that?

You don't like Eclipse or Ant or don't want to depend on it for build.

You need additional features in the build.

You want command line and continuous integration server usage.

You need to work with multiple dependencies.

You want to reuse code from another project.

Page 7: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

7

Example Dependencies

Make lib folder and copy jars files into it.

Check them into svn.

Upgrade means replace jar file and transitive dependencies.

Page 8: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

8

Example Dependencies

Known to be a hazzle from years of Apache Ant usage on Java projects:

●Unknown dependencies●Transitive dependencies

●No documentation ●No collision detection

Led to Maven, Ivy ...

Page 9: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

9

Introduction to Apache Maven

“Software project management and comprehension tool”

Builds your software and much more

De-facto standard for Java software builds

Convention over Configuration

Page 10: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

10

Maven and Android

Maven Android SDK Deployer, Android4Maven, Android SDK Tool

Maven Android Plugin

M2Eclipse

M2Eclipse Android Integration

Page 11: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

11

Hello Flash Example

Packaging apk

Android dependency

Java source folder

Maven Android Plugin configuration

Maven Compiler Plugin

Page 12: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

12

Using the plugin

Build mvn clean install

Start emulator mvn android:emulator-start

Deploy applicationmvn android:deploy

Page 13: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

13

Couple of Things to Know About

pom.xml

Default Build Life Cycle

Plugins

Repository (local and remote)

Page 14: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

14

Maven Invocation

mvn [options] [<goal(s)>] [<phase(s)>]

●Options – get list with mvn -h

●Goals – with syntax Plugin:PluginGoal ● e.g. mvn android:deploy

●Phases – e.g. clean compile test install package● e.g. mvn clean install

Page 15: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

15

Goals

different per plugin behaviour can be defined in pom

e.g. mvn install:install

but does not have to be

mvn archetype:create ... mvn install:file ....pass parameters in with -Dparameter=value

Page 16: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

16

Phases

●predefined order of things that need to be done●what happens is defined in pom and default settings (super-pom)●additional plugins can be bound to lifecycle phases pre-clean, clean, post-cleanvalidate, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test- sources, process-test-sources, generate-test-resources, process- test-resources, test-compile, test, prepare-package, package, pre- integration-test, integration-test, post-integration-test, verify, install, deploy

Page 17: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

17

Plugins, Plugins, Plugins

Maven itself does nearly nothing – just a container (M2 - Plexus, M3 - Guice)

Super POM defines standard configuration which can do a LOT

Lots of plugins available at apache, codehaus and beyond

Page 18: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

18

Other plugin goals

●android:deploy●android:undeploy●android:emulator-start●android:emulator-stop●android:apk●android:dex●android:pull●android:push●android:zipalign

Page 19: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

19

Using external dependencies

Add dependency

Everthing else happens automagically

Roboguice – Astroboy example

Page 20: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

20

Maps Extension

<dependency> <groupId>com.google.android.maps</groupId> <artifactId>maps</artifactId> <version>7_r1</version> <scope>provided</scope></dependency>

Page 21: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

21

Unit tests

With testng or junit, also e.g. Cobertura, Emma,

MorseFlash example

Page 22: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

22

Instrumentation tests

Separate module with instrumentation test

MorseFlash example

Page 23: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

23

Better Integration Testing

Robotium

Like Selenium for Android

Add dependency to pom.xml and start coding tests

Page 24: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

24

Releasing Application

Sign apk with jarsigner plugin

Zipalign release apk

Update version number and other things

MorseFlash Example

Page 25: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

25

Advanced Usage

Obfuscate and shrink APK

Use Scala programming language

Scala Example

Reuse Android projects – dependency type “apksource”

Page 26: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

26

Other Things You Can Do

Reuse e.g. Pojo's from server side application

Testing code coverage

Produce JavaDoc and more on website

Page 27: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

27

Other Things You Can Do

Continuous integration builds - Hudson

Static analysis, test coverage, trending – Sonar

Ensure License Header in all files

Upload and download files to and from emulator

Site build and more ...

Page 28: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

28

Related Tools

● Android4Maven – builds jars in Maven central● Maven Android SDK Deployer – maps jars into

repo● Android SDK Tool – install SDK headless

Page 29: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

29

What would you like to do?

Might be possible already..

Looking to improve plugin and tools ..

Give us feedback, give it all a spin, create issues and more

Page 30: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

30

Examples

Samples from Maven Android Plugin http://github.com/mosabua/maven-android-plugin-samples

Roboguice Samplehttp://code.google.com/r/mosabua-roboguice/source/browse

Page 31: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

31

Maven Resources

Apache Mavenhttp://maven.apache.org

Maven: The Complete Referenceand other books and resources

http://www.sonatype.com/book

M2 Eclipsehttp://m2eclipse.sonatype.org/

Page 32: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

32

Maven Android Resources

Maven Android Developers Mailing Listhttp://groups.google.com/group/maven-android-developers

Maven Android Pluginhttp://code.google.com/p/maven-android-plugin/

M2 Eclipsehttp://m2eclipse.sonatype.org/

M2 Eclipse Android Integration linkhttp://code.google.com/p/m2eclipse-android-integration/

Page 33: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

33

Summary

Proven, ready alternative

More flexibility

More power

Page 34: Apache Maven and Android at - simpligility · Apache Maven and Android at ... apk android:dex ... Robotium Like Selenium for Android Add dependency to pom.xml and start coding tests.

Manfred Mosersimpligility.com

34

The End

Questions?

Ideas?

Any feedback welcome!

Contact me at

[email protected]