Using maven-android-plugin to build android apps by maven commands.
|
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.
- Bring the auto Sync magic of Protractor to Selenium with Java - October 23, 2015
- Restarting Appium Server could improve various server freezing issues and may improve execution time - January 20, 2015
- Appium with iOS 8 and XCode 6 : What’s new? - November 5, 2014
- REST API automation testing using Apache HttpClient – The Approach - October 3, 2014
- An Overview of mobile application : Moving forward to automation - October 1, 2014
- An introduction to REST - September 29, 2014
- Run ChromeDriver with Chrome Driver Service to reduce script execution time significantly - September 26, 2014
- Selenium WebDriver – Get Cookies from an existing session and add those to a newly instantiated WebDriver browser instance. - September 26, 2014
- Simulate Copy Paste action using Java Robot and Clipboard class - September 26, 2014
- Android : How to test if Android Application has memory leaks - August 11, 2014