unable to compile Maven project after switching to ADT - android

I've switched from Eclipse Indigo to ADT (version 22.3.0)
I compile a project using Maven through command line:
mvn clean install android:deploy android:run
The project compiled fine on my older system and I haven't changed it at all. Now when I import it to ADT I get the "already added" error during compilation:
...
[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Lcom/sun/activation/registries/LineTokenizer;
[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] 1 error; aborting
...
I don't have X_src files I saw on other replies to this issue. I don't include any library in my lib folder either.
This happens even with basic POM file so I guess that ADT has changed the project somehow so it includes this LineTokenizer twice (I'm not including it anywhere), is this correct?
Does anyone know how to fix this, or to find where the multiple inclusions happen?
Edit:
the POM:
<?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>my.package</groupId>
<artifactId>android-client</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>Name</name>
<dependencies>
<dependency>
<groupId>com.google.android.services</groupId>
<artifactId>google-play-services</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>com.google.android.support</groupId>
<artifactId>android-support-v4</artifactId>
<version>4</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android.analytics</groupId>
<artifactId>analytics</artifactId>
<version>3</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>oauth.signpost</groupId>
<artifactId>signpost-core</artifactId>
<version>1.2.1.1</version>
</dependency>
<dependency>
<groupId>oauth.signpost</groupId>
<artifactId>signpost-commonshttp4</artifactId>
<version>1.2.1.1</version>
</dependency>
<dependency>
<groupId>com.facebook.android</groupId>
<artifactId>facebook-android-sdk</artifactId>
<version>3.5.2</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.flurry</groupId>
<artifactId>FlurryAgent</artifactId>
<version>3.2.2</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.6.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>11</platform>
</sdk>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
</plugins>
</build>
</project>

The ADT will throw that error if its finds more than one instance of the same package but with different version number to them. Looking at your pom one of your dependencies is adding the LineTokenizer which is not up-to-date in comparison to the one supplied by the compiler. I would suggest you go to the Dependency Hierarchy using the maven POM Editor. This will allow you to select the extraneous dependency, which you can then exclude by right-clicking and selecting "Exclude Maven Artifact..." which will automatically add an <exclusions> element to your POM. This will remove the duplicate JAR from your Eclipse classpath and allow you to build you project. Do a mvn clean install after you done editing the POM though.

Related

IllegalArgumentException on Android Maven Install

I am getting the following exception when attempting a "mvn install" on an Android project.
[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl;
[INFO] at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
[INFO] at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
[INFO] at com.android.dx.command.dexer.Main.processClass(Main.java:685)
[INFO] at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
[INFO] at com.android.dx.command.dexer.Main.access$600(Main.java:78)
[INFO] at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
[INFO] at com.android.dx.command.dexer.Main.processOne(Main.java:596)
[INFO] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
[INFO] at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
[INFO] at com.android.dx.command.dexer.Main.run(Main.java:230)
[INFO] at com.android.dx.command.dexer.Main.main(Main.java:199)
[INFO] at com.android.dx.command.Main.main(Main.java:103)
It looks as though there is some kind of dependency conflict. My pom is as follows
<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">
<parent>
<groupId>com.x.y.z</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>android-project</artifactId>
<packaging>apk</packaging>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>19</platform>
<path>${env.ANDROID_HOME}/</path>
</sdk>
<undeployBeforeDeploy>false</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.2</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.4.2_r3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v4</artifactId>
<version>20.0.0</version>
</dependency>
<dependency>
<groupId>org.androidannotations</groupId>
<artifactId>androidannotations</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.mcxiaoke.volley</groupId>
<artifactId>library</artifactId>
<version>1.0.6</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>fr.avianey</groupId>
<artifactId>facebook-android-api</artifactId>
<version>3.17.1</version>
<type>aar</type>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.0.2</version>
</dependency>
</dependencies>
</project>
if I make the android support compatibility-v4 dependency provided scope the install runs successfully, but the app crashes at runtime when I run it from IntelliJ as it is unable to inflate the DrawerLayout view.
Any ideas?
For anyone interested, the Facebook api was causing a conflict as it contains the android support v4. I added an exclusion and it works now.

Android Maven Project in Eclipse with apklib

I am trying to add google play services to existing android maven project using jar and apklib. The project does compile using mvn clean install, but in Eclipse i am getting this error:
Error: No resource found that matches the given name (at 'value' with value '#integer/google_play_services_version'). AndroidManifest.xml /pruebas-bundle-android line 51 Android AAPT Problem
I am new with maven, so i don´t know what could cause this. I have searched for information on the error but have not found anything that could let me solve it. I am using maven 3.2.2 and m2e 1.4. This is my pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pruebas.pruebas</groupId>
<artifactId>pruebas-bundle-android</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.4.2_r3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v4</artifactId>
<version>20.0.0</version>
</dependency>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>19.0.0</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>19.0.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>urbanairship</groupId>
<artifactId>urbanairship-lib</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>com.crittercism</groupId>
<artifactId>crittercism-android-agent</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>local-repository</id>
<url>file:${basedir}/local-repository</url>
</repository>
</repositories>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.9.0-rc.3</version>
<extensions>true</extensions>
<configuration>
<sdk>
<platform>19</platform>
</sdk>
<manifest>
<debuggable>false</debuggable>
</manifest>
</configuration>
</plugin>
</plugins>
</build>
</project>
The problem seems to be due to the apklib. In Eclipse, i can see all my dependencies jar in Maven dependencies, but i don´t know how to make available the google play services apklib in Eclipse. I would appreciate any help with this.
In order to compile a project with an Android Library (APKLIB) dependency in Eclipse you need to have m2e-android installed and a "Mavenised" copy of the Android Library source code checked-out into your local Eclipse workspace.
When I say "Mavenised" I mean that the Android Library project should have a POM with coordinates (group ID, version, etc.) that match the apklib dependency in you application POM.

Eclipse: Why and when to add libraries to build path when using Maven project to not have defective Eclipse project?

I have an Android project in Eclipse managed by Maven. Yesterday I upgraded Eclipse and some plugins by the "Checked for Updated" function within Eclipse. After the update has finished, my Android project was defective. First I thought that it's just a "Clean/Update Project/Maven Rebuild" issue or maybe the order of the includes of the libraries didn't fit anymore (for example, Maven dependencies are not on top or something similar), but I was able to build by Maven, so no project or Maven problems, but an Eclipse problem. To get it working again I had to add Hamcrest, Junit and Mockito from the Maven repo to the build path manually. I didn't had to do that before in this project (except android-4.1.1.4.jar).
I would like to understand when and why I suddenly have to do that? (In an earlier project I also had to add some external libraries manually).
(I always build and my project by clean install android:deploy android:run.)
Here are some important plugins I have currently installed...
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>
This is the output of the error log
**The problem is that it doesn't find the classes (until I import it manually, but Maven and Eclipse should handle that) If I try to import for example org.junit.Test, org.junit.runner.RunWith or org.mockito.Mock I get in Eclipse
The import xxxxx cannot be resolved
Problems tab in Eclipse:
The project was not built since its build path is incomplete. Cannot
find the class file for org.mockito.verification.VerificationMode. Fix
the build path then try building this
project com.mygame-TRUNK Unknown Java Problem The type
org.mockito.verification.VerificationMode cannot be resolved. It is
indirectly referenced from required .class
files GameProcessorTest.java /com.mygame-TRUNK/src/test/java/com/mygam/game line
1 Java Problem
As of version 1.0.0 Android for Maven Eclipse has changed the way it manages the Maven classpaths. Non-runtime dependencies (effectively, anything not in the compile scope) are now loaded into a new Maven, non-runtime classpath container. Are you seeing these libraries appear in this new classpath container?
If not, please try deleting the project from your workspace, deleting the IDE-specific .* metadata files and trying re-importing as a Maven project.

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.
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.
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
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.
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 :)

How to build a JAR for an android project

I am working on a small project to allow cookies to persist. I want to make the project as a JAR so other developers can use it in there project. At the moment I am able to build the project as an APKLIB however this seems unnecessary as the resources are not needed. If I change the packaging to JAR I get the follow error when building
Results :
Tests in error:
shouldAddCookie(com.doward.persistantcookietest.PersistantCookieStoreTest):
java.lang.ClassNotFoundException: caught an exception while obtaining
a class file for com.doward.persistantcookies.R
shouldClearAllCookies(com.doward.persistantcookietest.PersistantCookieStoreTest):
java.lang.ClassNotFoundException: caught an exception while obtaining
a class file for com.doward.persistantcookies.R
shouldClearExpired(com.doward.persistantcookietest.PersistantCookieStoreTest):
java.lang.ClassNotFoundException: caught an exception while obtaining
a class file for com.doward.persistantcookies.R
The POM looks like this
<?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.doward</groupId>
<artifactId>persistantcookiestore</artifactId>
<version>1</version>
<packaging>jar</packaging>
<name>persistantcookies</name>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.2.2_r2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<sdk>
<platform>17</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
If you want to just build a JAR file from .class files and no resources e.g. no XML files releating to layouts, values, colours etc then you can do so from the command line:
jar -cvf <filenameorjar.jar> <files to be included>
Example:
jar -cvf cookiepersist.jar com/*
This will create a jar file in the present working directory and include all the .class files from the directory com in the present working directory.
If you have a andorid project and you wish to use the same in another project you can make the project as a library project and refer the same in another Android project. This can include your resources also.
http://developer.android.com/tools/projects/projects-eclipse.html
You export your utility classes that do not refer to resources in android ie pure java classes. If you use eclipse you can have a look at the tutorial below
http://androiddevelopement.blogspot.in/2011/01/creating-jar-file-in-eclipse.html

Categories

Resources