Apache Maven and Android


Published on

  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Apache Maven and Android

  1. 1. Apache Maven and Android Manfred Moser simpligility technologies inc. http://www.simpligility.com http://creativecommons.org/licenses/by-sa/3.0/legalcode
  2. 2. About Manfred Moser ●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 VIJUG ● 2 Manfred Moser simpligility.com
  3. 3. Now that you know a bit about me.. What about you? Android development? Other mobile/embedded development? Java (SE, EE, ME...)? Linux? Apache Maven? Other
  4. 4. Agenda Motivation Maven Introduction Maven Android Tool Chain with examples Discussion, Feedback Oh .. and feel free to interrupt with questions. 4 Manfred Moser simpligility.com
  5. 5. Building Android Apps Currently Eclipse ADT Or Default Apache Ant based build 5 Manfred Moser simpligility.com
  6. 6. Whats wrong with that? You don't like Eclipse 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. 6 Manfred Moser simpligility.com
  7. 7. Example Dependencies Make lib folder and copy jars files into it. Check them into svn. Upgrade means replace jar file and transitive dependencies. 7 Manfred Moser simpligility.com
  8. 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 ... 8 Manfred Moser simpligility.com
  9. 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 Java based but used for more than just Java 9 Manfred Moser simpligility.com
  10. 10. Couple of Things to Know About pom.xml Default Build Life Cycle Plugins Repository (local and remote) 10 Manfred Moser simpligility.com
  11. 11. 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 11 Manfred Moser simpligility.com
  12. 12. Maven Options -h, --help – Display help information -D,--define <arg> - Define a system property -e,--errors - Produce execution error messages -f,--file - Force the use of an alternate POM file. -N,--non-recursive -Do not recurse into sub- projects -P,--activate-profiles <arg> Comma-delimited list of profiles to activate -X,--debug - Produce execution debug output 12 Manfred Moser simpligility.com
  13. 13. 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 13 Manfred Moser simpligility.com
  14. 14. 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-clean validate, 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 14 Manfred Moser simpligility.com
  15. 15. Plugins, Plugins, Plugins Maven itself does nearly nothing – just a container (M2 - Plexus, M3 - Guice) Super POM defines standard configuration which does a LOT Lots of plugins available at apache, codehaus and beyond 15 Manfred Moser simpligility.com
  16. 16. Maven and Android Maven Android SDK Deployer Maven Android Plugin M2Eclipse M2Eclipse Android Integration 16 Manfred Moser simpligility.com
  17. 17. Maven Android SDK Deployer Dependencies from Android SDK into local or remote repository 17 Manfred Moser simpligility.com
  18. 18. Hello Flash Example Packaging apk Android dependency Java source folder Maven Android Plugin configuration Maven Compiler Plugin 18 Manfred Moser simpligility.com
  19. 19. Using the plugin Build mvn clean install Start emulator mvn android:emulator-start Deploy application mvn android:deploy 19 Manfred Moser simpligility.com
  20. 20. Other plugin goals ●android:deploy ●android:undeploy ●android:emulator-start ●android:emulator-stop ●android:apk ●android:dex ●android:pull ●android:push 20 Manfred Moser simpligility.com
  21. 21. Using external dependencies Add dependency Everthing else happens automagically Roboguice – Astroboy example 21 Manfred Moser simpligility.com
  22. 22. Unit tests With testng or junit, also e.g. Cobertura, Emma, MorseFlash example 22 Manfred Moser simpligility.com
  23. 23. Maps Extension <dependency> <groupId>com.google.android.maps</groupId> <artifactId>maps</artifactId> <version>7_r1</version> <scope>provided</scope> </dependency> 23 Manfred Moser simpligility.com
  24. 24. Instrumentation tests Separate module with instrumentation test Maven-android-plugin-samples apidemos 24 Manfred Moser simpligility.com
  25. 25. Advanced Android Usage Reuse Android projects – dependency type “apksource” Sign apk with jarsigner plugin Zipalign release apk 25 Manfred Moser simpligility.com
  26. 26. Other Things You Can Do Reuse e.g. Pojo's from server side application Testing code coverage Produce JavaDoc and more on website Continuous integration builds Ensure License Header in all files Static analysis, site build and more ... 26 Manfred Moser simpligility.com
  27. 27. 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 27 Manfred Moser simpligility.com
  28. 28. Maven Resources Apache Maven http://maven.apache.org Maven: The Complete Reference and other books and resources http://www.sonatype.com/book M2 Eclipse http://m2eclipse.sonatype.org/ 28 Manfred Moser simpligility.com
  29. 29. Maven Android Resources Maven Android SDK Deployer http://github.com/mosabua/maven-android-sdk-deployer/ Maven Android Plugin http://code.google.com/p/maven-android-plugin/ M2 Eclipse http://m2eclipse.sonatype.org/ M2 Eclipse Android Integration link http://code.google.com/p/m2eclipse-android-integration/ Android Jars into Maven Central http://code.google.com/p/android/issues/detail?id=4577 29 Manfred Moser simpligility.com
  30. 30. Summary Proven, ready alternative More flexibility More power Lets get Google and others to wake up! 30 Manfred Moser simpligility.com
  31. 31. The End Questions? Ideas? Any feedback welcome! 31 Manfred Moser simpligility.com