1

我有一个我想用 Maven 处理的 Android 项目。我对 Maven 很陌生,所以每一步我都有另一个错误要解决。我需要补充一下,这是一个非常庞大的项目,有很多库。这是一个错误:

[

INFO] warning: Ignoring InnerClasses attribute for an anonymous inner class
[INFO] (org.apache.commons.logging.LogFactory$6) that doesn't come with an
[INFO] associated EnclosingMethod attribute. This class was probably produced by a
[INFO] compiler that did not target the modern .class file format. The recommended
[INFO] solution is to recompile the class from source, using an up-to-date compiler
[INFO] and without specifying any "-target" type options. The consequence of ignoring
[INFO] this warning is that reflective operations on this class will incorrectly
[INFO] indicate that it is *not* an inner class.
[INFO] 
[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Lorg/apache/http/annotation/NotThreadSafe;
[INFO]  at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[INFO]  at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[INFO]  at com.android.dx.command.dexer.Main.processClass(Main.java:490)
[INFO]  at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
[INFO]  at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[INFO]  at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[INFO]  at com.android.dx.command.dexer.Main.processOne(Main.java:422)
[INFO]  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
[INFO]  at com.android.dx.command.dexer.Main.run(Main.java:209)
[INFO]  at com.android.dx.command.dexer.Main.main(Main.java:174)
[INFO]  at com.android.dx.command.Main.main(Main.java:91)
[INFO] 
[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Lcom/google/inject/AbstractModule;
[INFO]  at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[INFO]  at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[INFO]  at com.android.dx.command.dexer.Main.processClass(Main.java:490)
[INFO]  at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
[INFO]  at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[INFO]  at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[INFO]  at com.android.dx.command.dexer.Main.processOne(Main.java:422)
[INFO]  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
[INFO]  at com.android.dx.command.dexer.Main.run(Main.java:209)
[INFO]  at com.android.dx.command.dexer.Main.main(Main.java:174)
[INFO]  at com.android.dx.command.Main.main(Main.java:91)

还有我的 pom.xml,其中一些库来自 Maven Central,其中一些库是我在本地添加到我的 Maven 存储库的。

<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>4.1.1.4</version>
        <scope>provided</scope>

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

    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>20030203.000550</version>

    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.4</version>

    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>12.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>2.0-no_aop</version>
    </dependency>
    <dependency>
        <groupId>http-client</groupId>
        <artifactId>http-client-android</artifactId>
        <version>1.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.2.5</version>
    </dependency>
    <dependency>
        <groupId>local.admobsdk</groupId>
        <artifactId>admobsdk</artifactId>
        <version>6.4.1</version>
    </dependency>
    <dependency>
        <groupId>local.kicalls</groupId>
        <artifactId>kicalls</artifactId>
        <version>1</version>
    </dependency>
    <dependency>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java</artifactId>
        <version>2.4.1</version>
    </dependency>
    <dependency>
        <groupId>org.roboguice</groupId>
        <artifactId>roboguice</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>oauth.signpost</groupId>
        <artifactId>signpost-commonshttp4</artifactId>
        <version>1.2.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.twitter4j</groupId>
        <artifactId>twitter4j-core</artifactId>
        <version>2.1.11</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>3.6.1</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>
                    <path>/Users/asd/Desktop/sdk</path>
                    <platform>14</platform>
                </sdk>
                <deleteConflictingFiles>true</deleteConflictingFiles>
                <undeployBeforeDeploy>true</undeployBeforeDeploy>
                <attachSources>false</attachSources>
                <proguard>
                    <skip>true</skip>
                </proguard>

            </configuration>
            <extensions>true</extensions>
        </plugin>

他们在互联网上说,我应该为这两个产生这个顶级异常的类添加排除,但不知道我应该添加什么排除。

4

4 回答 4

4

我猜您对以下依赖项有疑问:

1)roboguice和guice。要解决,我建议您com.google.inject:guiceorg.roboguice:roboguice依赖项中排除。

2) httpmime 对 httpcore 有依赖。而且我猜这种依赖与嵌入在 android os 中的旧 httpcomponents 库冲突。所以你可以尝试org.apache.httpcomponents:httpcore从依赖项中排除org.apache.httpcomponents:httpmime

备注:作为第一个建议排除的替代方案,您可以简单地尝试com.google.inject:guice从您的 pom 中删除依赖项,因为较新的版本(3.0)将作为传递依赖项出现org.roboguice:roboguice

提示:您可以使用命令行mvn dependency:tree很好地了解项目的所有库和传递依赖项。

于 2013-08-22T15:28:10.837 回答
0

我在一个非常相似的问题上苦苦挣扎。其他找到的解决方案对我不起作用,所以我想分享我的工作。我的环境:Android 4.3,api 18,插件 Maven Android 3.1.1,maven 3.0.5。我继续得到:

意外的顶级异常:[INFO] java.lang.IllegalArgumentException:已添加:
Lorg/apache/commons/collections/FastHashMap;

我构建了注释掉其他依赖项(除了 Vogel 在http://www.vogella.com/articles/AndroidBuildMaven/article.html中指出的那些),获得了构建成功。然后我对我的 pom 的其余部分进行了注释,它起作用了。

于 2013-12-03T11:24:03.873 回答
0

ben75 答案是正确的。但还有另一种处理方式。我刚刚手动将所有库添加到本地存储库,不需要任何例外。以下是如何做到这一点:为 Maven 依赖安装自己的 jar 库

于 2013-08-28T10:26:10.323 回答
0

也许答案有点晚了,但我遇到了同样的问题。我刚刚在 pom 文件中添加了这个块:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpmime</artifactId>
    <version>4.3.5</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </exclusion>
    </exclusions>
</dependency>

并且构建得很好,因为依赖项被包含了两次:)

于 2014-09-01T09:51:08.910 回答