Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android + eclipse + maven + actionbarsherlock

I read lots of things about actionbarsherlock, maven, android but none of the solution I've seen worked for me :(

I'm sure that I'm pretty close to the solution but I don't understand and I need some help :)

So here is my problem, I try to create an android maven project with a dependency to Actionbarsherlock.... It seems pretty easy but I've always thoses errors

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

Here is my configuration :

Eclipse Juno M2e 1.2.0 ADT 21 Maven 3.0.4

Here is the parent 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://[email protected]/octo-online/robospice.git</connection>
    <url>git:ssh://[email protected]/octo-online/robospice.git</url>
    <developerConnection>scm:git:ssh://[email protected]/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>[email protected]</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>

and here is the pom of my project

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

Here what i try :

Maven Android Project with Test Suite http://v.zasadnyy.com/blog/abs-maven-eclipse-integration/

As actionbarsherlock project, I'm using the head of the git repository, I copied the library directory, pasted it in the same folder as my parent project and rename it according to {groupId}-{artifactId}-{version}

I'm really open to restart from scratch and find a way to do it right because i don't understand why it doesn't work... :(

Thanks in advance for your help

like image 861
jef Avatar asked Jan 16 '13 17:01

jef


3 Answers

Here's how I fixed it. It's due to Maven trying to export its dependencies when Eclipse is also exporting its Android dependencies:

  1. Project->Properties->Java Build Path
  2. Go to the Order and Export tab.
  3. Uncheck "Maven Dependencies" so they don't get double exported.
  4. Clean and try to run it.
  5. If it still doesn't work, also uncheck "Android Dependencies."
like image 184
phreakhead Avatar answered Nov 14 '22 19:11

phreakhead


I had a very similar issue using Maven, Eclipse, and ActionBarSherlock. The problem is that the support library gets put into the build path twice, making the dexopt confused about the multiple declarations.

I was able to get rid of one of the places where dexopt was finding the support library by changing the pom.xml for ActionBarSherlock from

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

to

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

Make sure you clean the project after saving this change.

like image 39
Stephen Wan Avatar answered Nov 14 '22 21:11

Stephen Wan


You need to identify which dependencies in your pom.xml are including the classes that the Dalvik compiler is complaining about.

  1. In eclipse, you can identify what jar the problematic class belongs to by Open Type (on mac Command-T).

  2. Then you determine which transitive dependencies to those jars you have by looking up each direct dependency you have in maven central. And peering into the projects pom.xml.

  3. Once identified you need to add exclusion clauses to the corresponding dependency configuration in your project pom.xml.

project pom.xml:

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

There's a brute force way to do it as well. Just open up the project in eclipse, expand the 'Maven Dependencies' in project viewer, then add the exclusion clause to each direct dependency in your project pom one by one, each time hitting save. The android maven configuration plugin will recalculate the dependencies under 'Maven Dependencies' and you'll see the problematic jar disappear. Once you get all of them your Dalvik errors will disappear as well.

like image 3
m0rganic Avatar answered Nov 14 '22 21:11

m0rganic