This Tutorial will take you through a Step by Step approach for building an Android project using Maven. Though an IDE is not necessary but in this tutorial we will use Eclipse-Juno.
Requirements :
Install the follwing plugins into the Eclipse-IDE.- Install m2eclipse plugin. This plugin provides swift integration of Maven into the Eclipse IDE. Follow this link, which shows how to install m2e plugin into Eclipse http://eclipse.org/m2e/download/
- Install ADT (Android Development Toolkit) plugin. Follow this link for installation instructions. http://developer.android.com/sdk/installing/installing-adt.html .
- Install m2e-android plugin. This adds maven support for Android Developer Tools and the Maven Android Plugin. It brings the power of Maven dependency management into the ADT. To install this plugin into Eclipse go to Help -> Eclipse Marketplace and search for "android m2e".
Start a Maven based android project from scratch.
In this approach we will start developing a maven based android project from the scratch.- In eclipse start a new Maven Project.
- Click Next. Now a Select an Archetype dialog appears.
- Click on Add Archetype button. This prompts user with a Add Archetype dialog box. Fill in the Group Id as "de.akquinet.android.archetypes", Artifact Id as "android-quickstart" and Version as "1.0.8" . For now leave Repository URL blank. Click OK.
- Now select this Artifact from the list and click Next.
- In the dialog box fill in the Group Id (e.g. com.mycompany) and Artifact Id (e.g. myproject) for your project. Click Finish.
- Now our boilerplate mavenized android project is ready but it shows an error 'missing required src/test/java'. This is a bug in m2e-android plugin. To fix this issue, manually create folders test/java inside your src folder.
- Now run this project. This will show Hello <your project name>!. In our case this displays Hello myproject!
Cheers .... We have successfully created and ran an Android App integrated with Maven. Now we can also use command line maven tools to resolve dependencies, deploy , run any android project also.
Following above steps sets up a basic Android project integrated with Maven. Let us now examine generated pom.xml.
- First thing to notice is the packaging tag which is set to type apk.
- Next important thing is to let maven compile your android app, maven must have Android SDK into its repository (local/central). In this example required android.jar (android sdk API level 10) is fetched from mavens central repository, which is set as dependency as following Maven coordinates com.google.android / android / 2.3.3 (Group Id / Artifact Id / version ).
- Another important tag is build plugin. Default POM generated already configured "android-maven-plugin" for you. This plugin is the heart of android maven integration. Inside this plugin, notice that platform tag is set to 10. This API level must be same as of used in dependency tag for Android SDK. (set 10 for 2.3.3 jar or set 16 for 4.1)
No comments:
Post a Comment