3

I have absolutely empty Android project generated with

mvn archetype:generate -DarchetypeArtifactId=android-quickstart .......

It builds fine, it deploys fine and it runs fine. The problem is, when I add

    <dependency>
        <groupId>org.simpleframework</groupId>
        <artifactId>simple-xml</artifactId>
        <version>2.6.2</version>
</dependency>

to dependencies, the build fails with

[INFO] --- android-maven-plugin:3.0.0:dex (default-dex) @ whoops-android-app1 ---
[INFO] C:\Program Files\Java\jdk1.7.0\jre\bin\java [-jar, D:\android-sdk\platform-tools\lib\dx.jar, --dex, --output=D:\whoops\xxx\whoops-android-app1\target\classes.dex, C:\Users\loki2302\.m2\repository\xpp3\xpp3\1.1.4c\xpp3-1.1.4c.jar, C:\Users\loki2302\.m2\repository\org\simpleframework\simple-xml\2.6.2\simple-xml-2.6.2.jar, C:\Users\loki2302\.m2\repository\stax\stax\1.2.0\stax-1.2.0.jar, C:\Users\loki2302\.m2\repository\stax\stax-api\1.0.1\stax-api-1.0.1.jar, D:\whoops\xxx\whoops-android-app1\target\classes]
[INFO] 
[INFO] trouble processing "javax/xml/namespace/QName.class":
[INFO] 
[INFO] Ill-advised or mistaken usage of a core class (java.* or javax.*)
[INFO] when not building a core library.
[INFO] 
[INFO] This is often due to inadvertently including a core library file
[INFO] in your application's project, when using an IDE (such as
[INFO] Eclipse). If you are sure you're not intentionally defining a
[INFO] core class, then this is the most likely explanation of what's
[INFO] going on.
[INFO] 
[INFO] However, you might actually be trying to define a class in a core
[INFO] namespace, the source of which you may have taken, for example,
[INFO] from a non-Android virtual machine project. This will most
[INFO] assuredly not work. At a minimum, it jeopardizes the
[INFO] compatibility of your app with future versions of the platform.
[INFO] It is also often of questionable legality.
[INFO] 
[INFO] If you really intend to build a core library -- which is only
[INFO] appropriate as part of creating a full virtual machine
[INFO] distribution, as opposed to compiling an application -- then use
[INFO] the "--core-library" option to suppress this error message.
[INFO] 
[INFO] If you go ahead and use "--core-library" but are in fact
[INFO] building an application, then be forewarned that your application
[INFO] will still fail to build or run, at some point. Please be
[INFO] prepared for angry customers who find, for example, that your
[INFO] application ceases to function once they upgrade their operating
[INFO] system. You will be to blame for this problem.
[INFO] 
[INFO] If you are legitimately using some code that happens to be in a
[INFO] core package, then the easiest safe alternative you have is to
[INFO] repackage that code. That is, move the classes in question into
[INFO] your own package namespace. This means that they will never be in
[INFO] conflict with core system classes. JarJar is a tool that may help
[INFO] you in this endeavor. If you find that you cannot do this, then
[INFO] that is an indication that the path you are on will ultimately
[INFO] lead to pain, suffering, grief, and lamentation.
[INFO] 
[INFO] 1 error; aborting
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.711s
[INFO] Finished at: Tue Dec 13 12:31:23 MSK 2011
[INFO] Final Memory: 18M/178M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.0.0:dex (default-dex) on project whoops-android-app1: MojoExecutionException: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C ""C:\Program Files\Java\jdk1.7.0\jre\bin\java" -jar D:\android-sdk\platform-tools\lib\dx.jar --dex --output=D:\whoops\xxx\whoops-android-app1\target\classes.dex C:\Users\loki2302\.m2\repository\xpp3\xpp3\1.1.4c\xpp3-1.1.4c.jar C:\Users\loki2302\.m2\repository\org\simpleframework\simple-xml\2.6.2\simple-xml-2.6.2.jar C:\Users\loki2302\.m2\repository\stax\stax\1.2.0\stax-1.2.0.jar C:\Users\loki2302\.m2\repository\stax\stax-api\1.0.1\stax-api-1.0.1.jar D:\whoops\xxx\whoops-android-app1\target\classes", Result = 1 -> [Help 1]

Removing this dependency fixes the build. Here's my mvn --version:

Apache Maven 3.0.3 (r1075438; 2011-02-28 20:31:09+0300)
Maven home: D:\apache-maven-3.0.3\bin\..
Java version: 1.7.0, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0\jre
Default locale: en_US, platform encoding: Cp1251
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

Here's my 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.whoops.android</groupId>
    <artifactId>whoops-android-app1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>whoops-android-app1</name>

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

        <!-- <dependency>        
            <groupId>org.codegist.crest</groupId>
            <artifactId>codegist-crest</artifactId>
            <version>2.0.0-RC1</version>        
        </dependency> -->

        <dependency>
            <groupId>org.simpleframework</groupId>
            <artifactId>simple-xml</artifactId>
            <version>2.6.2</version>
    </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.0.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>
                    <sdk>
                        <platform>7</platform>
                    </sdk>
                    <deleteConflictingFiles>true</deleteConflictingFiles>
                    <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>

Tried Maven 2 and Maven-android-plugin 2.* before - the result is the same. This fails only for simple-xml dependency. Enabling codegist-crest with simple-xml disabled works fine. This happens only when I use simple-xml.

I've also tried making the same without maven (Eclipse) - in this case everything works fine, even if I have simple-xml on my build path.

Any ideas?

Charles
  • 50,943
  • 13
  • 104
  • 142
Andrey Agibalov
  • 7,624
  • 8
  • 66
  • 111

2 Answers2

4

The problem here is that simple-xml or more likely one of it's dependencies has defined one or more classes in the reserved java.* or javax.* namespaces. This isn't allowed on the Android platform. Although, I am not sure why this would work in Eclipse. Is it possible that the library is on the build path but not included with the final compiled APK?

It is possible that you don't need simple-xml as the Android platform provides a number of XML related packages:

Update:

The following SO question and answer describes how to include the simple-xml library but disable the conflicting imports it depends on: Android: error including/repacking dependencies which reference javax core classes

Community
  • 1
  • 1
Charles Harley
  • 7,184
  • 3
  • 32
  • 38
  • It looks like you're absolutely right. The problem is, I use CRest who requires simple-xml to work with the service I have. I'm just confused because "CRest provides out-of-the-box support for the Android platform." (http://crest.codegist.org/deeper/android.html) – Andrey Agibalov Dec 13 '11 at 12:08
  • I've updated my answer with a link to a SO question with the solution you're looking for. Basically you import the `simple-xml` library but exclude the conflicting dependencies it depends on. – Charles Harley Dec 13 '11 at 13:47
0

Best way is simply use this configuration item http://jayway.github.io/maven-android-plugin/dex-mojo.html#dexCoreLibrary of android-maven-plugin

So you can add this to the <config> section of the plugin:

<dexCoreLibrary>true</dexCoreLibrary>

Or define

<android.dex.coreLibrary>true</android.dex.coreLibrary> 

In the <properties> section.

ATom
  • 15,960
  • 6
  • 46
  • 50