Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use android libraries (apklibs) with maven and eclipse?

I am using Eclipse 3.7.2 + Android + Maven + m2e and I have a problem with Android libraries included via Maven as apklibs. I built a test scenario with two projects, mvntest1 (the main project) and mvntest2 (my library project). The pom.xml's are included after this text.

So far so good. I can build mvntest2 via console $ mvn install without any errors. Thus, I have an apklib in my local maven repository (~/.m2/repository/mvntest2/mvntest2/0.0.1-SNAPSHOT/mvntest2-0.0.1-SNAPSHOT.apklib).

But: The including does not work. Eclipse does not include the classes, etc. of mvntest2 in mvntest1. I have cleaned, updated the configuration and dependencies and nothing help.

What am I doing wrong? Please help. If some informations are missing, just ask.

======= mvntest1/pom.xml =====

<?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>mvntest1</groupId>
<artifactId>mvntest1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>apk</packaging>
<name>mvntest1</name>

<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>2.1.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>mvntest2</groupId>
        <artifactId>mvntest2</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>apklib</type>
    </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</version>
            <configuration>
                <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                <resourceDirectory>${project.basedir}/res</resourceDirectory>
                <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
                <sdk>
                    <platform>7</platform>
                </sdk>
                <deleteConflictingFiles>true</deleteConflictingFiles>
                <undeployBeforeDeploy>true</undeployBeforeDeploy>
            </configuration>
            <extensions>true</extensions>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

====== mvntest2/pom.xml =====

<?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>mvntest2</groupId>
    <artifactId>mvntest2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>apklib</packaging>
    <name>mvntest2</name>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>2.1.2</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</version>
                <configuration>
                    <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                    <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                    <resourceDirectory>${project.basedir}/res</resourceDirectory>
                    <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
                    <sdk>
                        <platform>7</platform>
                    </sdk>
                    <deleteConflictingFiles>true</deleteConflictingFiles>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
                <extensions>true</extensions>
            </plugin>
            <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>
like image 750
mogoh Avatar asked Jun 25 '12 14:06

mogoh


1 Answers

Support for apklib dependencies in ADT Eclipse is part of ongoing work for the m2e-android project and is not yet complete. Please comment on this issue to stay updated:

https://github.com/rgladwell/m2e-android/issues/8

UPDATE 26th September 2013: Android Connector for Maven Eclipse (m2e-android) version 0.4.3 now has been released with full support for Android Libraries.

like image 188
Ricardo Gladwell Avatar answered Oct 01 '22 13:10

Ricardo Gladwell