filipp.kowalski
filipp.kowalski

Reputation: 5615

Maven top-level exception in Android project

I have an Android project which I want to handle with Maven. I am pretty new to Maven so every step I have another bug to solve. I need to add this is pretty huge project with a lot of libraries. Here is an error :

[

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)

and my pom.xml, some of the libraries come from Maven Central and some of them I added localy to my Maven repo.

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

They say on the internet, that I should add exclusion to these two classes who produce this top-level exception, but have no clue what exclusion I shoud add.

Upvotes: 1

Views: 1700

Answers (4)

jjnunog
jjnunog

Reputation: 181

Maybe it's a bit late for the answer, but I just got into the same problem. I just added this chunk in the pom file:

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

and builds just nice, since the dependency was being included twice :)

Upvotes: 0

saralago
saralago

Reputation: 1

I struggled with a very similar problem. Other found solutions didn't worked for me so I wanted to share my workaraond. My environment: Android 4.3, api 18, plugin Maven Android 3.1.1, maven 3.0.5. I continued getting:

UNEXPECTED TOP-LEVEL EXCEPTION: [INFO] java.lang.IllegalArgumentException: already added:
Lorg/apache/commons/collections/FastHashMap;

I built commenting out other dependencies (all but those indicated by Vogel in http://www.vogella.com/articles/AndroidBuildMaven/article.html), getting BUILD SUCCESS. Then I decommented the rest of my pom and it worked.

Upvotes: 0

filipp.kowalski
filipp.kowalski

Reputation: 5615

ben75 answer is correct. But there is another way to handle it. I've just added by hand all libraries to local repository and no exceptions was needed. Here is how to do this : Installing own jar library for Maven dependency

Upvotes: 0

ben75
ben75

Reputation: 28736

I guess you have a problem with the following dependencies:

1) roboguice and guice. To resolve, I suggest you to exclude com.google.inject:guice from org.roboguice:roboguice dependencies.

2) httpmime have a dependency to httpcore. And I guess this dependency is conflicting with old httpcomponents library embedded in android os. So you can try to exclude org.apache.httpcomponents:httpcore from dependencies of org.apache.httpcomponents:httpmime

Remark: as an alternative to the first suggested exclusion, you can simply try to remove the com.google.inject:guice dependency from your pom since a newer version (3.0) will be present as a transitive dependency of org.roboguice:roboguice

Tip: you can use the command line mvn dependency:tree to have a good vision of all libraries and transitive dependencies of your project.

Upvotes: 4

Related Questions