Sunday, September 18, 2011

Maven Android Plugin 3.0


Maven build system for Java project management

       This post can give to you a brief introduction about maven build system and also how to setup the development environment.

       So what is Maven ?  Maven is a Java project management and integration build tool. Similar to like Ant build tool. It can work based on the concepts of Project Object Model (POM ) xml file. It  can helps you to generate the reports and so many.Maven intelligence is it can talks to the repositories which are available in online and it can gets that information..that is the beauty of Maven build system

       Maven having a very good project structure for to keep multiple directories and multiple jar files.  If your project is using multiple jars or frameworks, so maven can helps you to pick the all jar files into one place and can deploy it. In order to compile or deploy an application, you may need to take all the jar files. Sometimes some jar files also can dependent on other jar files and jar versions so that point of time it can be help you lot. 

We need to setup environment variables for to run maven build commands like as below:
MVN_HOME = D:\Apps\apache-maven-3.0.3;
Path = %MVN_HOME

1.    Get to know the version of maven
              >>mvn  --version
It can show the maven home variable, java location and along with the OS information…

Apache Maven 3.0.3 (r1075438; 2011-02-28 09:31:09-0800)
Maven home: D:\Apps\apache-maven-3.0.3\bin\..
Java version: 1.6.0_17, vendor: Sun Microsystems Inc.
Java home: D:\Apps\java\jdk\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windo

      2. Maven Project creation step by step:

      archtype:generate command can create a new maven project with directory structure. 
While executing this command it may ask few options to setup the build system for the pom.xml

>>mvn archtype:generate
>> It can download all the repositories which are available from online through internet connection and also it can ask few options for user to creation of project
1.       Choose a number or apply filter (format: [groupId:]artifactId, case sensitive co
ntains): 130:
>> choose a different architect model  number which are available
2.       Choose version:
Choose a number:
>> Enter maven version number
3.       Define value for property 'groupId': :
>>Enter your group ID like: org.obulreddy
4.       Define value for property 'artifactId': :
>>Enter your  application  name: AndroidTesting
5.       Define value for property 'version':  1.0-SNAPSHOT: :
>> Enter version value
6.       Confirm properties configuration:
groupId: org.com.obulreddy
artifactId: AndroidTesting
version: 1.0-SNAPSHOT
package: org.com.obulreddy
 Y: :
>> Enter confirm prosperities configuration say yes “Y” or no “N”
Finally it can create a directory called “AndroidTesting”, which you have given for artifact ID and also pom.xml

Android Project build system by using Maven plugin 3.0

       There are Lot of advantages for Android development, automation testing, test reporting using maven android plugin
       And also easy and quick way to start the multiple emulators for installing the .apk file through targets  from the command prompt
       To get Android build system  to work with Maven, you need to do a couple of extra things…
      Like preparing to set up android SDK and Maven system variables
       ANDROID_HOME = “ ….SDK  directory….”
       MAVEN_HOME = “….Maven directory….”

Followed steps can help you to quick setup for then android maven plugin 

1.       Create a project from command prompt
               >>  android create project --target 1 
                      --name MyAndroidApp
                      --path ./MyAndroidAppProject 
                      -- activity MyAndroidAppActivity
                      --package  com.example.myandroid                                                               

2.       To use Maven, You have to remove unnecessary files - build.xml, build.properties, libs
              >>  del build.xml build.properties libs

3.       Create a pom.xml file and give the values of groupID, artifactID, and name


Set the Android SDK version properties, api level version and emulator information in the build target


4.       >>mvn install
It can take a while time to download Maven repositories from the Internet
Finally it can show the Build successful message and also memory as well
In this step, unit tests will also be done from the “test” folder. But now in this case there are no unit tests. So that it can give test runs as  “0” like as below


5.       >>mvn android:deploy
             This target can try to install your .apk file in to the connected device
              And gives the successful installation message along with .apk file directory and device or emulator 



          You could use directly for the build application like as followed
          >> mvn install android:deploy or mvn clean install android:deploy

The code for the example application is available as part of the maven-android-plugin-samples available at

No comments:

Post a Comment