我在Maven管理的Eclipse中有一个Android项目。昨天我通过Eclipse中的“Checked for Updated”功能升级了Eclipse和一些插件。更新完成后,我的Android项目有缺陷。首先我认为它只是一个“清理/更新项目/ Maven重建”问题,或者库的包含顺序不再适合(例如,Maven依赖关系不在顶部或类似的东西),但我是能够通过Maven构建,所以没有项目或Maven问题,而是Eclipse问题。为了让它再次工作,我不得不手动将Maven repo中的Hamcrest,Junit和Mockito添加到构建路径中。在此项目之前我没有这么做(android-4.1.1.4.jar除外)。 我想知道我什么时候以及为什么突然这样做? (在早期的项目中,我还必须手动添加一些外部库。)
(我总是用清理安装android:build android:run 构建和我的项目。)
以下是我目前安装的一些重要插件......
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>
这是错误日志的输出
**问题是它找不到类(直到我手动导入它,但Maven和Eclipse应该处理它)如果我尝试导入例如org.junit.Test
,org.junit.runner.RunWith
或org.mockito.Mock
我进入Eclipse
Eclipse中的导入xxxxx无法解析
Problems选项卡:
项目未构建,因为其构建路径不完整。不能 找到org.mockito.verification.VerificationMode的类文件。固定 构建路径然后尝试构建此 project com.mygame-TRUNK未知Java问题类型 org.mockito.verification.VerificationMode无法解析。它是 间接引用所需的.class 文件GameProcessorTest.java /com.mygame-TRUNK/src/test/java/com/mygam/game line 1 Java问题
答案 0 :(得分:1)
从版本1.0.0 Android for Maven Eclipse开始,它改变了管理Maven类路径的方式。非运行时依赖性(实际上,不在compile
范围内的任何东西)现在被加载到新的Maven,非运行时类路径容器中。您是否看到这些库出现在这个新的类路径容器中?
如果没有,请尝试从工作区删除项目,删除特定于IDE的.*
元数据文件,并尝试重新导入为Maven项目。