1

I have an Android project in Eclipse managed by Maven. Yesterday I upgraded Eclipse and some plugins by the "Checked for Updated" function within Eclipse. After the update has finished, my Android project was defective. First I thought that it's just a "Clean/Update Project/Maven Rebuild" issue or maybe the order of the includes of the libraries didn't fit anymore (for example, Maven dependencies are not on top or something similar), but I was able to build by Maven, so no project or Maven problems, but an Eclipse problem. To get it working again I had to add Hamcrest, Junit and Mockito from the Maven repo to the build path manually. I didn't had to do that before in this project (except android-4.1.1.4.jar). I would like to understand when and why I suddenly have to do that? (In an earlier project I also had to add some external libraries manually).

(I always build and my project by clean install android:deploy android:run.)

Eclipse

Here are some important plugins I have currently installed... enter image description here

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>com.mydomain</groupId>
    <artifactId>myapp</artifactId>
    <packaging>apk</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>My App</name>
    <url>http://maven.apache.org</url>

    <properties>
        <platform.version>2.2.1</platform.version>
        <android.sdk.path>/opt/android-sdk-linux</android.sdk.path>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <junit.version>4.8.2</junit.version>
        <mockito.version>1.9.5</mockito.version>
        <jackson.version>1.9.13</jackson.version>
        <hamcrest.version>1.3</hamcrest.version>
        <android.version>4.1.1.4</android.version>
        <annotations.version>4.1.1.4</annotations.version>
        <supportv4.version>r13</supportv4.version>
    </properties>

    <repositories>
        <repository>
            <id>codehaus</id>
            <url>http://repository.codehaus.org/org/codehaus</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${android.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>support-v4</artifactId>
            <version>${supportv4.version}</version>
        </dependency>
        <!-- LInt Annotations -->
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>annotations</artifactId>
            <version>${annotations.version}</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <!-- Non Android Tests --><!-- hamcrest must be before JUnit due to build errors -->
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>${hamcrest.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>1.5.1</version>
        </dependency>

        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.5.1</version>
        </dependency>


    </dependencies>

    <build>
        <outputDirectory>bin/classes</outputDirectory>
        <testOutputDirectory>bin/test-classes</testOutputDirectory>

        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-jarsigner-plugin</artifactId>
                <version>1.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.5.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>
                    <sign>
                        <debug>true</debug>
                    </sign>
                    <sdk>
                        <platform>13</platform>
                        <path>${android.sdk.path}</path>
                    </sdk>
                    <undeployBeforeDeploy>false</undeployBeforeDeploy>
                </configuration>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.5</version>
            </plugin>
            <!--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.2.0,)</versionRange>
                                    <goals>
                                        <goal>manifest-update</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

This is the output of the error log
enter image description here

**The problem is that it doesn't find the classes (until I import it manually, but Maven and Eclipse should handle that) If I try to import for example org.junit.Test, org.junit.runner.RunWith or org.mockito.Mock I get in Eclipse

The import xxxxx cannot be resolved

Problems tab in Eclipse:

The project was not built since its build path is incomplete. Cannot find the class file for org.mockito.verification.VerificationMode. Fix the build path then try building this project com.mygame-TRUNK Unknown Java Problem The type org.mockito.verification.VerificationMode cannot be resolved. It is indirectly referenced from required .class files GameProcessorTest.java /com.mygame-TRUNK/src/test/java/com/mygam/game line 1 Java Problem

9
  • Are you using m2e-android? Commented Jun 1, 2014 at 9:58
  • Yes, I updated the question to show the versions. Commented Jun 1, 2014 at 11:58
  • Can you post your POM? You might also want to break up the initial paragraph, its a little dense. Commented Jun 2, 2014 at 10:53
  • Just installed the POM locally and its clearly erroring because of a missing support library dependency. Are you using the Maven Android SDK Deployer depedencies? github.com/mosabua/maven-android-sdk-deployer Commented Jun 4, 2014 at 10:45
  • This is because the latest version in Maven central is from 2012. So I took the latest version at this time from SDK and installed it into the local repository by Maven's install:install-file. Commented Jun 4, 2014 at 15:43

1 Answer 1

1

As of version 1.0.0 Android for Maven Eclipse has changed the way it manages the Maven classpaths. Non-runtime dependencies (effectively, anything not in the compile scope) are now loaded into a new Maven, non-runtime classpath container. Are you seeing these libraries appear in this new classpath container?

If not, please try deleting the project from your workspace, deleting the IDE-specific .* metadata files and trying re-importing as a Maven project.

Sign up to request clarification or add additional context in comments.

6 Comments

I removed .project, .settings, .classpath, reimported the project as Maven project and I see 'Non-Runtime Maven Dependencies' in Build Path now. But this folder is empty. The problem still persists, even after Project clean, Maven clean, Update Project. There is an option to add a 'Native library location', but I can't image that I manually have to add there something. Moreover the non compile scope libs are in different folders within the Maven repository. I don't think I should add the Maven repository there. Btw: All libs are still referenced in the 'Maven dependencies'.
Are you seeing any other workspace errors? Are there any relevant exceptions in your workspace log file?
No, I don't have any other errors and the Maven build itself works. It's only an Eclipse problem. When I add the libraries manually to the build path, the errors are gone.
Sorry, its not clear for your last response: Are there any relevant exceptions in your workspace log file? Also your remarks about Eclipse are not helpful, and repeat information elsewhere.
Yes, sorry, there are error in error log, but I don't think this has anything to do with the problem, that it doesn't find the Classes I try to import (See the updated question). `
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.