Maven & Android: complete pom.xml files contents

17 11 2012

The complete pom.xml file I use for Android projects is as follows.

1. Main Android application’s pom.xml

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>pl.looksok</groupId>
	<artifactId>ColCalc</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>apk</packaging>

	<build>
		<sourceDirectory>${project.basedir}/src</sourceDirectory>
		<plugins>
			<plugin>
				<groupId>com.jayway.maven.plugins.android.generation2</groupId>
				<artifactId>android-maven-plugin</artifactId>
				<version>3.3.2</version>
				<configuration>
					<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
					<assetsDirectory>${project.basedir}/assets</assetsDirectory>
					<resourceDirectory>${project.basedir}/res</resourceDirectory>
					<genDirectory>${project.basedir}/gen</genDirectory>
					<deleteConflictingFiles>true</deleteConflictingFiles>
					<undeployBeforeDeploy>true</undeployBeforeDeploy>
					<sdk>
						<platform>7</platform>
					</sdk>
				</configuration>
				<extensions>true</extensions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.5.1</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<!-- java project dependency -->
		<dependency>
			<groupId>pl.looksok.logic</groupId>
			<artifactId>ColCalcLogic</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>

		<!-- android apklib project dependency -->
		<dependency>
			<groupId>pl.looksok.currencyedittext</groupId>
			<artifactId>CurrencyEditText</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<type>apklib</type>
		</dependency>
	</dependencies>
</project>

Please remember to set target Android SDK and java version in file above. In my case Java version is 1.6, and SDK is 7. Keep the same config in AndroidManifest.xml.

2. apklib – Android library project pom.xml file

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>pl.looksok.currencyedittext</groupId>
  <artifactId>CurrencyEditText</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <!-- set up packaging -->
  <packaging>apklib</packaging>
  <build>
    <sourceDirectory>${project.basedir}/src</sourceDirectory>
            <plugins>
                <plugin>
			<groupId>com.jayway.maven.plugins.android.generation2</groupId>
			<artifactId>android-maven-plugin</artifactId>
			<version>3.1.1</version>
			<configuration>
				<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
				<assetsDirectory>${project.basedir}/assets</assetsDirectory>
				<resourceDirectory>${project.basedir}/res</resourceDirectory>
				<genDirectory>${project.basedir}/gen</genDirectory>
				<deleteConflictingFiles>true</deleteConflictingFiles>
				<undeployBeforeDeploy>true</undeployBeforeDeploy>
				<sdk>
					<platform>7</platform>
				</sdk>
			</configuration>
			<extensions>true</extensions>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>2.5.1</version>
			<configuration>
				<source>1.6</source>
				<target>1.6</target>
			</configuration>
		</plugin>

        </plugins>

        <pluginManagement>
		<plugins>
		<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
		<plugin>
			<groupId>org.eclipse.m2e</groupId>
			<artifactId>lifecycle-mapping</artifactId>
			<version>1.0.0</version>
			<configuration>
				<lifecycleMappingMetadata>
				<pluginExecutions>
				<pluginExecution>
				<pluginExecutionFilter>
					<groupId>com.jayway.maven.plugins.android.generation2</groupId>
		  			<artifactId>android-maven-plugin</artifactId>
		  			<versionRange>[3.3.0,)</versionRange>
		  			<goals>
		  				<goal>proguard</goal>
		  			</goals>
		  		</pluginExecutionFilter>
		  		</pluginExecution>
		  		</pluginExecutions>
		  		</lifecycleMappingMetadata>
		  	</configuration>
		  </plugin>
		</plugins>
	</pluginManagement>
  </build>
</project>

The most important change to notice is the packaging tag at the beginning – set it to apklib.

Note that eclipse does not read maven apklib dependencies from pom.xml automatically. If you want your android project to use apklib project in eclipse, you have to manually add library in your main project’s settings:

Please note also, that your apklib project has to be marked as Android Library in its properties (check it in the same project properties window as shown above). Maven plugin however should automatically mark this project as library, based on its pom.xml file.

3. jar – standard java library’s pom.xml

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>pl.looksok.logic</groupId>
  <artifactId>ColCalcLogic</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Just as a remainder – this is standard pom.xml for jar library

Summary

These files are operational, after performing all maven, m2eclipse and maven for android plugin configurations

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!

Advertisements

Actions

Information

Give Your feedback:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: