Сборка проекта Android с Maven - dexer терпит неудачу из-за зависимости simple-xml - PullRequest
3 голосов
/ 13 декабря 2011

У меня абсолютно пустой проект Android, сгенерированный с помощью

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

Он прекрасно работает, хорошо разворачивается и работает нормально.Проблема в том, что когда я добавляю

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

к зависимостям, сборка завершается неудачно с

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

. Удаление этой зависимости исправляет сборку.Вот мой 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"

Вот мой 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>

Пробовал Maven 2 и Maven-android-plugin 2. * before - результат тот же.Это не работает только для simple-xml зависимости.Включение codegist-crest с отключенным simple-xml работает нормально.Это происходит только тогда, когда я использую simple-xml.

Я также пытался сделать то же самое без Maven (Eclipse) - в этом случае все работает нормально, даже если у меня есть simple-xml на моем пути сборки.

Есть идеи?

Ответы [ 2 ]

4 голосов
/ 13 декабря 2011

Проблема здесь в том, что simple-xml или, более вероятно, одна из его зависимостей определила один или несколько классов в зарезервированных пространствах имен java. * Или javax. *.Это не разрешено на платформе Android.Хотя я не уверен, почему это будет работать в Eclipse.Возможно ли, что библиотека находится на пути сборки, но не включена в окончательно скомпилированный APK?

Возможно, вам не нужен simple-xml, поскольку платформа Android предоставляет ряд пакетов, связанных с XML:

Обновление:

В следующем вопросе и ответе SO описано, как включить библиотеку simple-xml, но отключить конфликтующий импорт, от которого она зависит: Android: ошибка при включении / переупаковке зависимостей, которые ссылаются на основные классы javax

0 голосов
/ 05 ноября 2013

Лучший способ - просто использовать этот элемент конфигурации http://jayway.github.io/maven-android-plugin/dex-mojo.html#dexCoreLibrary Android-Maven-плагин

Таким образом, вы можете добавить это в <config> раздел плагина:

<dexCoreLibrary>true</dexCoreLibrary>

Или определить

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

В разделе <properties>.

...