Using maven-android-plugin to build android apps by maven commands.

 

 

android

 

We have the option to build jar files from a Java IDE project by running ‘mvn clean install’ etc, but the build type of android projects is apk which is problematic to generate with maven commands from cmd. So to over come this problem we have a plugin available that can be declared in the pom.xml file of the android project which facilitates to compile and build the apk version of the project.

maven-android-plugin homepage: https://code.google.com/p/maven-android-plugin/

Configuring maven-android-plugin in pom.xml of android project:

configure a plugin in pom file like below:

<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<!– <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory> –>
<sdk>
<platform>16</platform>
<path>c:androidsdk</path>
</sdk>
<!– <emulator>
<avd>demodevice</avd>
<wait>100000</wait>
<options>-no-skin</options>
</emulator>
<zipalign>
<verbose>true</verbose>
</zipalign>
<undeployBeforeDeploy>true</undeployBeforeDeploy> –>
</configuration>
<extensions>true</extensions>
</plugin>

 

 

Also we need to add an dependency for android core library files which is needed while build process.

<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.2</version>
<scope>provided</scope>
</dependency>

Note: Currently this plugin is only compatible with Maven version >=3.1.1 . So this version must be installed and environmental setup should be taken care of.

If we are running things on Jenkins then path of android SDK along with path to Maven 3.1.1 must be configured with Jenkins .

Running command “mvn clean install” will compile the code , build the apk .

If project is an android test project, “mvn clean install” command will build the test apk file , install it to all the devices/Emulators connected to android debug bridge and Run the tests on the devices/Emulators. Running it with Jenkins will also generate test run reports in Jenkins.

So this plugin is powerful for users who are using Robotium for android test projects and want to run scripts directly from Jenkins.