5

我读了很多关于 actionbarsherlock、maven、android 的东西,但我见过的解决方案都没有为我工作:(

我确定我非常接近解决方案,但我不明白,我需要一些帮助:)

所以这是我的问题,我尝试创建一个依赖于 Actionbarsherlock 的 android maven 项目......看起来很简单,但我总是有这些错误

[2013-01-16 18:10:28 - Dex Loader] Unable to execute dex: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
[2013-01-16 18:10:28 - greennfc-samples] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
[2013-01-16 18:10:50 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/hamcrest/Description;
[2013-01-16 18:10:50 - greennfc-samples] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/hamcrest/Description;

这是我的配置:

Eclipse Juno M2e 1.2.0 ADT 21 Maven 3.0.4

这是父 pom :

<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>
<parent>
    <groupId>org.sonatype.oss</groupId>
    <artifactId>oss-parent</artifactId>
    <version>7</version>
</parent>

<groupId>com.greennfc.tools</groupId>
<artifactId>greennfc</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Green NFC - Parent</name>
<description>Android Nfc library for an easer management of NFC features</description>
<packaging>pom</packaging>
<url>https://github.com/binomed/greennfc</url>
<inceptionYear>2013</inceptionYear>

<!-- 
<scm>
    <connection>scm:git:ssh://git@github.com/octo-online/robospice.git</connection>
    <url>git:ssh://git@github.com/octo-online/robospice.git</url>
    <developerConnection>scm:git:ssh://git@github.com/octo-online/robospice.git</developerConnection>
    <tag>HEAD</tag>
</scm>
 -->

<licenses>
    <license>
        <name>Apache 2</name>
        <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    </license>
</licenses>

<issueManagement>
    <system>Github Issue Tracker</system>
    <url>https://github.com/octo-online/robospice/issues</url>
</issueManagement>

<developers>
    <developer>
        <id>JFG</id>
        <name>Jean-Francois Garreau</name>
        <email>jean.francois.garreau@binomed.fr</email>
    </developer>
</developers>

<!-- 
<mailingLists>
    <mailingList>
        <name>RoboSpice Forum/Mailinglist</name>
        <post>http://groups.google.com/group/robospice</post>
        <subscribe>http://groups.google.com/group/robospice/subscribe</subscribe>
        <unsubscribe>https://groups.google.com/group/robospice/subscribe</unsubscribe>
    </mailingList>
</mailingLists>

<ciManagement>
    <system>jenkins</system>
    <url>https://robospice.ci.cloudbees.com/job/Build%20RoboSpice/</url>
</ciManagement>
 -->

<modules>
    <!-- core library -->
    <module>greennfc-core</module>

    <!-- Base librairies elements -->
    <module>greennfc-filters</module>

    <!-- extensions -->

    <!-- Demo -->
    <module>greennfc-samples</module>
</modules>

<properties>
    <android.version>4.1.1.4</android.version>
    <android-platform.version>14</android-platform.version>
    <android-annotations.version>4.1.1.4</android-annotations.version>
    <android-support.version>r7</android-support.version>
    <android-maven-plugin.version>3.5.0</android-maven-plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <github.global.server>github</github.global.server>
    <maven.javadoc.skip>true</maven.javadoc.skip>
</properties>

<!-- TODO : remove this when android maven plugin 3.4.2 is out -->
<pluginRepositories>
    <pluginRepository>
        <id>oss.sonatype.org-jayway-snapshots</id>
        <name>Jayway OpenSource SNAPSHOTs on Sonatype.org</name>
        <url>http://oss.sonatype.org/content/repositories/jayway-snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>annotations</artifactId>
            <version>${android-annotations.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${android.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android-test</artifactId>
            <version>${android.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://stackoverflow.com/questions/5591811/ignoring-innerclasses-attribute-warning-is-killing-eclipse -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <pluginManagement>
        <plugins>
            <!-- https://stackoverflow.com/questions/13040788/how-to-elimate-the-maven-enforcer-plugin-goal-enforce-is-ignored-by-m2e-wa -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-enforcer-plugin</artifactId>
                                    <versionRange>[1.0.0,)</versionRange>
                                    <goals>
                                        <goal>enforce</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-dependency-plugin</artifactId>
                                    <versionRange>[1.0.0,)</versionRange>
                                    <goals>
                                        <goal>copy-dependencies</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>${android-maven-plugin.version}</version>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.7</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <links>
                        <link>http://commons.apache.org/lang/api</link>
                        <link>http://java.sun.com/j2se/1.5.0/docs/api</link>
                    </links>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1.2</version>
            </plugin>

            <!-- deploy artifacts to github for downloads -->
            <plugin>
                <groupId>com.github.github</groupId>
                <artifactId>downloads-maven-plugin</artifactId>
                <version>0.6</version>
                <configuration>
                    <description>${project.version} release of ${project.name}</description>
                    <override>true</override>
                    <includeAttached>true</includeAttached>
                    <includes>
                        <include>${project.artifactId}-${project.version}.jar</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>upload</goal>
                        </goals>
                        <phase>deploy</phase>
                    </execution>
                </executions>
            </plugin>

            <!-- deploy javadoc and maven site to github -->
            <plugin>
                <groupId>com.github.github</groupId>
                <artifactId>site-maven-plugin</artifactId>
                <version>0.7</version>
                <configuration>
                    <message>Creating site for ${project.version}</message>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>site</goal>
                        </goals>
                        <phase>site</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <reportPlugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-project-info-reports-plugin</artifactId>
                            <version>2.2</version>
                            <configuration>
                                <dependencyDetailsEnabled>true</dependencyDetailsEnabled>
                                <dependencyLocationsEnabled>true</dependencyLocationsEnabled>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-javadoc-plugin</artifactId>
                            <version>2.7</version>
                        </plugin>
                    </reportPlugins>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<profiles>
    <profile>
        <id>sign</id>
        <activation>
            <property>
                <name>performRelease</name>
                <value>true</value>
            </property>
        </activation>
        <properties>
            <maven.javadoc.skip>false</maven.javadoc.skip>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

这是我项目的 pom

<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>

<parent>
    <groupId>com.greennfc.tools</groupId>
    <artifactId>greennfc</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>

 <artifactId>greennfc-samples</artifactId>
  <packaging>apk</packaging>
 <name>Green Nfc - Samples</name>
 <properties>
    <notificationcompat2.version>1.1.2</notificationcompat2.version>
    <actionbarsherlock.version>4.2.0</actionbarsherlock.version>
    <roboguice.version>2.0</roboguice.version>
    <robosherlock.version>1.4</robosherlock.version>
    <google.http.client.version>1.12.0-beta</google.http.client.version>
    <simplexmlserializer.version>2.6.6</simplexmlserializer.version>
    <jackson.version>1.9.9</jackson.version>
</properties>

<dependencies>
    <!-- Green Nfc dependencies -->
    <dependency>
        <groupId>com.greennfc.tools</groupId>
        <artifactId>greennfc-core</artifactId>
        <version>${project.version}</version>
    </dependency>

    <!-- Other libs -->
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.android</groupId>
      <artifactId>support-v4</artifactId>
        <version>${android-support.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.actionbarsherlock</groupId>
      <artifactId>actionbarsherlock</artifactId>
      <version>${actionbarsherlock.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.actionbarsherlock</groupId>
        <artifactId>actionbarsherlock</artifactId>
        <version>${actionbarsherlock.version}</version>
        <type>apklib</type>
        <scope>provided</scope>
    </dependency>
</dependencies>  

<build>
    <sourceDirectory>src/</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <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>${android-platform.version}</platform>
                </sdk>
                <undeployBeforeDeploy>true</undeployBeforeDeploy>
            </configuration>
            <extensions>true</extensions>
        </plugin>

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

我在这里尝试:

带有测试套件的 Maven Android 项目 http://v.zasadnyy.com/blog/abs-maven-eclipse-integration/

作为actionbarsherlock项目,我使用的是git仓库的head,我复制了库目录,粘贴到和我的父项目相同的文件夹中,并根据{groupId}-{artifactId}-{version}重命名

我真的很愿意从头开始重新开始并找到一种正确的方法,因为我不明白为什么它不起作用...... :(

在此先感谢您的帮助

4

5 回答 5

15

这是我修复它的方法。这是由于 Maven 在 Eclipse 也在导出其 Android 依赖项时尝试导出其依赖项:

  1. 项目->属性->Java构建路径
  2. 转到“订购和导出”选项卡。
  3. 取消选中“Maven Dependencies”,这样它们就不会被双重导出。
  4. 清理并尝试运行它。
  5. 如果它仍然不起作用,请取消选中“Android Dependencies”。
于 2013-01-31T20:31:33.423 回答
4

我在使用MavenEclipseActionBarSherlock时遇到了非常相似的问题。问题是支持库被两次放入构建路径,使 dexopt 对多个声明感到困惑。

通过更改pom.xmlfor ActionBarSherlock从_

<dependency>
    <groupId>com.google.android</groupId>
    <artifactId>support-v4</artifactId>
</dependency>

<dependency>
    <groupId>com.google.android</groupId>
    <artifactId>support-v4</artifactId>
    <scope>provided</scope>
</dependency>

确保在保存此更改后清理项目。

于 2013-03-06T13:23:01.313 回答
3

您需要确定 pom.xml 中的哪些依赖项包含 Dalvik 编译器抱怨的类。

  1. 在 Eclipse 中,您可以通过 Open Type(在 mac Command-T 上)识别有问题的类属于哪个 jar。

  2. 然后,通过在maven central中查找每个直接依赖项来确定对这些 jar 的传递依赖项。并查看项目 pom.xml。

  3. 一旦确定,您需要将排除子句添加到项目 pom.xml 中的相应依赖项配置中。

项目 pom.xml:

<dependencies>
<dependency>
        <groupId>...</groupId>
        <artifactId>...</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>org.hamcrest</artifactId>
                <groupId>hamcrest</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

还有一种蛮力的方法可以做到这一点。只需在 Eclipse 中打开项目,在项目查看器中展开“Maven 依赖项”,然后将排除子句一一添加到项目 pom 中的每个直接依赖项,每次点击保存。android maven 配置插件将重新计算“Maven Dependencies”下的依赖关系,您会看到有问题的 jar 消失了。一旦你得到所有这些,你的 Dalvik 错误也会消失。

于 2013-01-17T23:17:23.290 回答
2

我努力让 ActionBarSherlock lib 项目与 Maven 一起工作,但我失败了。类似的问题。所以我删除了 lib 项目中的 maven 依赖项,改用 libs/android-support-v4.jar 。顺便说一句,测试文件夹也被删除了。然后我运行我自己的项目,并引用 lib 项目。事情进展顺利。

于 2013-01-29T13:46:14.533 回答
0

好的,谢谢大家的回答,对我有用的是:

  1. 从 actionbarsherlock 中删除 supportv4 库
  2. 注释actionbarsherlock项目中junit的导入,以避免产生这一代
于 2013-03-18T13:12:59.600 回答