0

I have a several android library projects that I'm trying to convert to Maven.

I encountered a problem where mvn clean install is successful but in Eclipse there are import issues as if the classes in the project2 apklib is not in the classpath of project1.

First project 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>
<artifactId>android-clientsdk</artifactId>
<packaging>apklib</packaging>

<parent>
    <groupId>com.company.client</groupId>
    <artifactId>company-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>maven-source-plugin</artifactId>
            <configuration>
                <attach>true</attach>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <sdk>
                    <path>${android.sdk.path}</path>
                    <platform>${android.sdk.platform}</platform>
                </sdk>
                <!-- <deleteConflictingFiles>true</deleteConflictingFiles> -->
            </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.7.0,)</versionRange>
                                    <goals>
                                        <goal>generate-sources</goal>
                                        <goal>consume-aar</goal>
                                        <goal>proguard</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-dependency-plugin</artifactId>
                                    <versionRange>[2.1,)</versionRange>
                                    <goals>
                                        <goal>copy-dependencies</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

<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>
<artifactId>android-clientelement</artifactId>
<packaging>apklib</packaging>

<parent>
    <groupId>com.company.client</groupId>
    <artifactId>company-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>maven-source-plugin</artifactId>
            <configuration>
                <attach>true</attach>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <sdk>
                    <path>${android.sdk.path}</path>
                    <platform>${android.sdk.platform}</platform>
                </sdk>
                <!-- <deleteConflictingFiles>true</deleteConflictingFiles> -->
            </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.7.0,)</versionRange>
                                    <goals>
                                        <goal>generate-sources</goal>
                                        <goal>consume-aar</goal>
                                        <goal>proguard</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-dependency-plugin</artifactId>
                                    <versionRange>[2.1,)</versionRange>
                                    <goals>
                                        <goal>copy-dependencies</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.company.client</groupId>
        <artifactId>android-clientsdk</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <type>apklib</type>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.0.1</version>
    </dependency>
</dependencies>

Technical's:

  • I'm using Eclipse Kepler.
  • I'm using the latest Android Configurator for M2E (Taken from the eclipse marketplace)

My question:

  1. When depending on apklib should we see any evidence for this dependencies in Eclipse (like .class that are compiled from this library)?
  2. Why Eclipse can't find the import from the packages in the depended apklib?
Ika
  • 1,456
  • 1
  • 15
  • 24
  • I have a similar problem: while in eclipse everything looks fine (imports can be resolved etc. -> go to project properties -> android -> add lib, and make sure the lib is open in eclipse in the same workspace), the produced apk does not contain the apklib contents........... – user1050755 Jun 27 '14 at 12:17

1 Answers1

0

You must import your APKlib in your Eclipse workspace and then link it to your main application project (Project properties > Android > Add library and choose your APKLib project)

Sometimes, if you perform a clean or an update of your maven project, Eclipse loses the link of your apklib and you must add it again..

nbe_42
  • 1,212
  • 1
  • 14
  • 22
  • I tried this solution but it did not solve the problem. It might be due to the fact that the APKLib is a Maven project and it's not a standard Android file structure. (bin does not contain the class). – Ika Jan 14 '14 at 09:50
  • Your APKlib is not recognized as a maven and an android project in your workspace ? Anyway, in my case, I added my APKLib module as a dependency in my POM file.. Can you try to add it ? – nbe_42 Jan 14 '14 at 09:59
  • The APKLib is a dependency in my POM.xml not only that, Maven does successfully build this project using mvn clean install. But when I want to code in Eclipse I see that the imports fails. Did you manage to use class from the APKLib in your Eclipse? – Ika Jan 14 '14 at 10:04
  • Yes I did it. But in my case, APKLib maven module is also recognized as an Android module. So when I link it as a an Android Library, Eclipse works fine. In the Package Explorer of Eclipse, can you see a small "M" and a small "A" in the module icon ? – nbe_42 Jan 14 '14 at 10:17
  • I have all projects marked with both "A" and "M". When I go to project properties > Java build path > Libraries tab > Android Dependencies I see the jar. it points to the jar located under the APKLib project bin folder. As we know, when our projects are defined as maven all class are created in classes and the jar we should refer to is the one under Target folder. I opened the jar that I was depended on and the required classes were missing. – Ika Jan 14 '14 at 11:21
  • Some clarification to the above comment: In a regular Android project the bin contains the classes, APK and jar files. If another project is depended on it (assuming that the first project is a library project) than the dependency is translated to adding the jar from the bin folder and putting it in the classpath. If we have a Mavnen (android) project than bin does not contain the required data. If we would try to depend on the jar files in target we would soon find that there are only classes and no resources or R file. I would expect that the e2m android plugin would solve this issue. – Ika Jan 14 '14 at 11:57