Wednesday, August 17, 2011

Android Maven Integration

Android does not hosts the dependent jars on Maven repositories. There are some very old versions in the repository which are not useful for current android development. The best way to do is to install the dependencies locally. Let's follow the step for the development for maven.
  • Make sure the Android SDK is installed locally. Takes the latest stable one.
  • Define ANDROID_HOME environment variable pointing to the path of android SDK installation. Do as per your platform. In windows m/c it might look like as follows:
ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
<pluginGroups>  
   <pluginGroup>
       com.jayway.maven.plugins.android.generation2
   </pluginGroup> 
</pluginGroups>
  • It's better to create a project of android using android plugin of eclipse. Once the android plugin for eclipse is installed, create a project inside the eclipse.
  • Now create a pom.xml in the root directory of the project.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.lalit</groupId>
 <artifactId>LalitAndroid</artifactId>
 <version>3.0</version>
 <packaging>apk</packaging>
 <name>LalitAndroid</name>

 <dependencies>
  <dependency>
   <groupId>android</groupId>
   <artifactId>android</artifactId>
   <version>3.2_r1</version>
   <scope>provided</scope>
  </dependency>
 </dependencies>

 <build>
  <finalName>${project.artifactId}</finalName>
  <sourceDirectory>src</sourceDirectory>
  <plugins>
   <plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <version>3.0.0-alpha-13</version>
    <configuration>
     <sdk>
      <!-- platform or api level  -->
      <platform>13</platform>
     </sdk>
     <emulator>
      <!-- name of avd device, make sure you have created a device -->
      <avd>android-emulator</avd>
     </emulator>
     <undeployBeforeDeploy>true</undeployBeforeDeploy>
    </configuration>
    <extensions>true</extensions>
   </plugin>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
   </plugin>
  </plugins>
 </build>
</project>

No comments:

Post a Comment