LoginSignup
18
15

More than 5 years have passed since last update.

androidでXMLをパースするライブラリ「Simple」をgradleで入れるとビルドエラーになる

Last updated at Posted at 2015-02-20

忙しい人のための、簡単な回答

  • SimpleがAndroid標準で入っているライブラリとは別のバージョンのライブラリを入れようとして競合しているのが原因です
  • build.gradleのsimpleを読み込んでいる部分を下記のように書き換えることにより、Simpleが入れようとしてくる競合ライブラリを除外することができます。
dependencies {
    ...
    compile('org.simpleframework:simple-xml:2.7.1'){
        exclude module: 'stax-api'
        exclude module: 'xpp3'
    }
}

概要

はじめまして。
新人プログラマの、らべねこです。

Qiitaで記事を書くのは初めてです。

最近、業務でAndroid開発を始めましたので、開発をする上でハマったことをqiitaに記録していこうと思います。よろしくお願いします。

今日記録することは、androidでXMLをパースするライブラリ「Simple」をgradleで入れるとビルドエラーになる件です。

確認

  • appのbuild.gradleに下記のようなコードで入れてビルドします
dependencies {
    ...
    compile 'org.simpleframework:simple-xml:2.7.1'
}
  • ビルドしてみます
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Applications/android-sdk-macosx/build-tools/21.1.2/dx --dex --output /Users/labeneko/AndroidStudioProjects/TestApp/app/build/intermediates/pre-dexed/debug/stax-api-1.0.1-274b7d75adc0b395e6751c495dd2fd3492053aea.jar /Users/labeneko/.gradle/caches/modules-2/files-2.1/stax/stax-api/1.0.1/49c100caf72d658aca8e58bd74a4ba90fa2b0d70/stax-api-1.0.1.jar
  Error Code:

(中略)

BUILD FAILED

検証

  • 原因はSimpleが入れようとしているstax-apiというライブラリがAndroid標準のライブラリと競合しているからです。
  • エラー文中にある、stax-apiをSimpleのライブラリを読み込む時に除外してしまいます
WARNING: Dependency xpp3:xpp3:1.1.3.3 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency xpp3:xpp3:1.1.3.3 is ignored for release as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages

(中略)

BUILD SUCCESSFUL

Total time: 10.609 secs
  • ビルドは通りました!
  • しかし、warningが2件出ているのが気になります。
  • Dependency xpp3:xpp3:1.1.3.3と書いてあるように、xpp3も競合しているようです
  • そこで、xpp3も除外します
dependencies {
    ...
    compile('org.simpleframework:simple-xml:2.7.1'){
        exclude module: 'stax-api'
        exclude module: 'xpp3'
    }
}
  • これでもう一度ビルドします
BUILD SUCCESSFUL

Total time: 10.023 secs
  • ビルドが無事通りました!
  • これでエラーもwarningも無しにSimpleを使うことができます
18
15
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
15