BoofCV gradle 在 Android 工作室中构建错误

BoofCV gradle building Errors in Android studio

当我将 BoofCV 集成到 Android Studio 时,出现了以下错误,

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

我的build.gradle文件是

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'
}

我在我的一个项目中使用了 BoofCV。您应该添加除 XmlPullParser 之外的所有其他 BoofCV jar,因为这个 jar 与 Android.

中已经存在的 XmlPullParser 冲突

我通过下载所有的 jar 来添加 BoofCV,并且只包括像这样的相关的:

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')
}

尽管这是一种添加 jar 的简单方法,但您可以将相关的 jar 包含在 libs 文件夹中并添加以下行:

dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
}

我是这样处理这个问题的。像您最初那样包含 BoofCV 罐子。然后将以下内容添加到您的 app/build.gradle

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

这将删除有问题的 xmlpull。您可能还想包括 android 模块,它不是 'all'.

的一部分

这是 BoofAndroidDemo 上的示例

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