5. 5
Maven's objectives
● Making the build process easy
● Providing a uniform build system
● Providing quality project information
● Providing guidelines for best practices development
● Allowing transparent migration to new features
6. 6
Maven can manage ...
● Builds
● Documentation
● Reporting
● Dependencies
● SCMs
● Releases
● Distribution
7. 7
Maven's concepts
● Project Object Model
● Convention over Configuration (CoC)
● Dependency management
● Plugin-based architecture
20. 20
Maven commands
● mvn clean
– Remove all previous build generated files.
● mvn compile
– Compile the source code of the project.
● mvn test
– Run tests using a suitable unit testing framework.
● mvn package
– Package compiled code to distributable format.
● mvn install
– Install the package into the local repository.
● mvn deploy
– Copy the final package to the remote repository.
36. 36
Step by step
● Install Android SDK
● Run Maven Android SDK Deployer
● Write pom.xml
● Run it
37. 37
Install Android SDK, at least ...
● All versions SDK Platform
● All versions Google APIs
● All Extra items (including obsoleted)
● Glass Development Kit Sneak Peek
39. 39
Run Maven Android SDK Deployer
● Checkout mosabua/maven-android-sdk-deployer
● mvn install
copy all jar files to maven repository
40. 40
Use Android libraries like ...
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.4_r1</version>
<scope>provided</scope>
</dependency>
41. 41
Use Android libraries like ...
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.4_r1</version>
<scope>provided</scope>
</dependency>
"provided" stands for only
compile, not package itself
42. 42
Use Android libraries like ...
<dependency>
<groupId>com.google.android.maps</groupId>
<artifactId>maps</artifactId>
<version>19_r1</version>
<scope>provided</scope>
</dependency>
43. 43
Use Android libraries like ...
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v13</artifactId>
<version>19.0.1</version>
</dependency>
54. 54
android-maven-plugin FAQ
● No Android SDK path could be found.
– no ANDROID_HOME env., or value is incorrect
● set ANDROID_HOME env. to Android SDK path
55. 55
android-maven-plugin FAQ
● No Android SDK path could be found.
– no ANDROID_HOME env., or value is incorrect
● set ANDROID_HOME env. to Android SDK path
● Unknown packaging: apk
56. 56
android-maven-plugin FAQ
● No Android SDK path could be found.
– no ANDROID_HOME env., or value is incorrect
● set ANDROID_HOME env. to Android SDK path
● Unknown packaging: apk
– no extensions tag, or value is not "true"
● <extensions>true</extensions>
57. 57
android-maven-plugin FAQ
● No Android SDK path could be found.
– no ANDROID_HOME env., or value is incorrect
● set ANDROID_HOME env. to Android SDK path
● Unknown packaging: apk
– no extensions tag, or value is not "true"
● <extensions>true</extensions>
● package R does not exist
58. 58
android-maven-plugin FAQ
● No Android SDK path could be found.
– no ANDROID_HOME env., or value is incorrect
● set ANDROID_HOME env. to Android SDK path
● Unknown packaging: apk
– no extensions tag, or value is not "true"
● <extensions>true</extensions>
● package R does not exist
– <packaging>jar</packaging>
● <packaging>apk</packaging>
59. 59
android-maven-plugin FAQ
● No Android SDK path could be found.
– no ANDROID_HOME env., or value is incorrect
● set ANDROID_HOME env.to Android SDK path
● Unknown packaging: apk
– no extensions tag, or value is not "true"
● <extensions>true</extensions>
● package R does not exist
– <packaging>jar</packaging>
● <packaging>apk</packaging>
● Ill-advised or mistaken usage of a core class
60. 60
android-maven-plugin FAQ
● No Android SDK path could be found.
– no ANDROID_HOME env., or value is incorrect
● set ANDROID_HOME env. to Android SDK path
● Unknown packaging: apk
– no extensions tag, or value is not "true"
● <extensions>true</extensions>
● package R does not exist
– <packaging>jar</packaging>
● <packaging>apk</packaging>
● Ill-advised or mistaken usage of a core class
– no scope tag, or value is not "provided"
● <scope>provided</scope>
69. 69
Tips - How to use gen folder ?
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<genDirectory>gen</genDirectory>
</configuration>
</plugin>
70. 70
Tips - How to use gen folder ?
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<genDirectory>gen</genDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>gen</directory>
</fileset>
</filesets>
</configuration>
</plugin>
71. 71
Tips - How to use gen folder ?
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<genDirectory>gen</genDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>gen</directory>
</fileset>
</filesets>
</configuration>
</plugin>
remember clean gen folder
72. 72
Tips - How to clean bin folder ?
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>bin</directory>
</fileset>
</filesets>
</configuration>
</plugin>
74. 74
Tips - How to use library project ?
● Write pom.xml at library project as general
Android project
75. 75
Tips - How to use library project ?
● Write pom.xml at library project as general
Android project
● mvn clean android:apklib
– Apklib file includes src/main/java, libs & res directory
76. 76
Tips - How to use library project ?
● Write pom.xml at library project as general
Android project
● mvn clean android:apklib
– Apklib file includes src/main/java, libs & res directory
● Use install goal to copy apklib to maven repository
77. 77
Tips - How to use library project ?
● Write pom.xml at library project as general
Android project
● mvn clean android:apklib
– Apklib file includes src/main/java, libs & res directory
● Use install goal to copy apklib to maven repository
● Add dependency at main project
<dependency>
<groupId>tw.kewang.ui.captchaview</groupId>
<artifactId>CaptchaView</artifactId>
<version>1.0.0</version>
<type>apklib</type>
</dependency>
78. 78
Tips - How to use non-maven library ?
● Compress non-maven library to zip file
79. 79
Tips - How to use non-maven library ?
● Compress non-maven library to zip file
● Use install goal to copy zip to maven repository
– packaging=apklib
80. 80
Tips - How to use non-maven library ?
● Compress non-maven library to zip file
● Use install goal to copy zip to maven repository
– packaging=apklib
● Add dependency at main project
<dependency>
<groupId>tw.kewang.ui.captchaview</groupId>
<artifactId>CaptchaView</artifactId>
<version>1.0.0</version>
<type>apklib</type>
</dependency>