3

I tried different goals. mvn package results in package R does not exist, mvn android:generate-sources results in BUILD SUCCESS but no R.java will be created.

I would like to pack my classes into a jar container (not apk) because I would like to use it as a library in other projects.

AndroidManifest.xml: (minimal setup, because there are no Activities)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example">

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />

</manifest>

default.properties:

android.library=true
target=android-8

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>com.example</groupId>
    <artifactId>mylib</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>2.2.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <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>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.4.0</version>
                <extensions>true</extensions>
            </plugin>
        </plugins>

    </build>

</project>

The only resource is ./res/layout/example.xml.

dtrunk
  • 4,685
  • 17
  • 65
  • 109

1 Answers1

0

android-maven-plugin has no capability to generate a fully functional jar (contains all compiled class file, resources, manifest and etc) from Android library project.

The solution given by android-maven-plugin is apklib, which is simply a zip of the library project (has same directory structure contains raw java file, resource, manifest and etc). I have explained a bit more about how apklib works in this answer, for some sample projects, check out maven-android-plugin-samples/libraryprojects.

The furthest android-maven-plugin can go is a jar that contains only compiled class file, no resource, this is covered by the default <packaging>apklib<packaging> build life cycle and generated along with the .apklib file.

Community
  • 1
  • 1
yorkw
  • 40,926
  • 10
  • 117
  • 130