3

When I integrated BoofCV into Android Studio, the following error happened,

com.android.dex.DexException: Multiple dex files define Lorg/xmlpull/v1/XmlPullParser; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164) at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334) at com.android.dx.command.dexer.Main.run(Main.java:277) at com.android.dx.command.dexer.Main.main(Main.java:245) at com.android.dx.command.Main.main(Main.java:106) Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/jdk1.8.0_60/bin/java'' finished with non-zero exit value 2

My build.gradle file is

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.example.huayu.boofcvandroidstart"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"

    //multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'

compile group: 'org.boofcv', name: 'all', version: '0.20'
}
Huayu Zhang
  • 207
  • 4
  • 11

2 Answers2

4

Here's how I handled the issue. Include the BoofCV jars as you originally did. Then add the following to your app/build.gradle

configurations {
    all*.exclude group: "xmlpull", module: "xmlpull"
}

That will remove the offending xmlpull. You also might want to include the android module, which isn't part of 'all'.

Here's an example on BoofAndroidDemo

https://github.com/lessthanoptimal/BoofAndroidDemo/blob/master/app/build.gradle

lessthanoptimal
  • 2,722
  • 2
  • 23
  • 25
0

I have used BoofCV in one of my projects. You should add all the other BoofCV jars except the XmlPullParser because this jar conflicts with the already existing XmlPullParser present in Android.

I added BoofCV by downloading all the jars and only including the relevant ones like this:

dependencies {
            compile files('libs/BoofCV-android-0.19.jar')
            compile files('libs/BoofCV-calibration-0.19.jar')
            compile files('libs/BoofCV-feature-0.19.jar')
            compile files('libs/BoofCV-geo-0.19.jar')
            compile files('libs/BoofCV-io-0.19.jar')
            compile files('libs/BoofCV-ip-0.19.jar')
            compile files('libs/BoofCV-recognition-0.19.jar')
            compile files('libs/BoofCV-sfm-0.19.jar')
            compile files('libs/BoofCV-visualize-0.19.jar')
            compile files('libs/BoofCV-xuggler-0.19.jar')
            compile files('libs/core-0.26.jar')
            compile files('libs/ddogleg-0.7.jar')
            compile files('libs/georegression-0.8.jar')
            compile files('libs/xpp3_min-1.1.4c.jar')
            compile files('libs/xstream-1.4.7.jar')
}

Although this is a naive way to add the jars you could just include the relevant jars in the libs folder and add this line:

dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
}
Eric B.
  • 4,622
  • 2
  • 18
  • 33
  • I have removed xmlpull-1.1.3.1.jar but the error still exists. Besides, I don't know why I need to add the files one by one when I can use `compile fileTree(dir: 'libs', include: ['*.jar'])` – Huayu Zhang Dec 03 '15 at 05:40
  • Yes you don't need to add the files one by one. I posted the single file inclusions to show you which jars i use, and they compile without any errors, so only include jars above mentioned in the libs folder and use this line: `compile fileTree(dir: 'libs', include: ['*.jar'])` – Eric B. Dec 03 '15 at 05:44