0

So, my scheme is this: I've got my app A project which uses the Java OpenCV library, and a module B which is a library module that uses Java OpenCV library as well.

My settings of modules is this one: In the app A I compile the module B and the B modules compiles de Java OpenCV library, but I get:

Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.internal.LoggedErrorException: Failed to run command: /Users/rafaelruizmunoz/Library/Android/sdk/build-tools/21.1.2/dx --dex --no-optimize --output /Users/rafaelruizmunoz/crossproject/Android/demoapp/app/build/intermediates/dex/debug --input-list=/Users/rafaelruizmunoz/crossproject/Android/demoapp/app/build/intermediates/tmp/dex/debug/inputList.txt Error Code: 2 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lorg/opencv/BuildConfig; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303) at com.android.dx.command.dexer.Main.run(Main.java:246) at com.android.dx.command.dexer.Main.main(Main.java:215) at com.android.dx.command.Main.main(Main.java:106)

enter image description here

Gradle scripts:

(App - A)

 dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:21.0.3'
        compile project(':ReaderLib_OpenCVBased')
    }

(Module - B)

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

So my main problem is that I can't use the OpenCV library with a module which compiles the OpenCV library, how should I do it?

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
Rafael Ruiz Muñoz
  • 5,333
  • 6
  • 46
  • 92

2 Answers2

2

You have problem of multidex file so please add below dependency to your app Gradle file.

 compile 'com.android.support:multidex:1.0.1'

Also add this line:

defaultConfig {

    applicationId 'pkg'
    minSdkVersion 
    targetSdkVersion 
    versionCode 
    versionName 

    // Enable MultiDexing:  https://developer.android.com/tools/building/multidex.html
    multiDexEnabled true
}

Thanks..!!

AndiGeeky
  • 11,266
  • 6
  • 50
  • 66
  • Good one, but now it's saying: > java.util.zip.ZipException: duplicate entry: org/opencv/BuildConfig.class , why? – Rafael Ruiz Muñoz Oct 01 '15 at 12:46
  • @ Rafael Ruiz : Can you please post full error in your question? Please refer this answer also you getting this error -> http://stackoverflow.com/a/32581498/4018207 – AndiGeeky Oct 01 '15 at 16:12
0

You can use

 compile 'com.android.support:multidex:1.0.1'
androidTestCompile 'com.android.support:multidex-instrumentation:1.0.1'

And below unchanged

    defaultConfig {

    applicationId 'pkg'
    minSdkVersion 
    targetSdkVersion 
    versionCode 
    versionName 

    // Enable MultiDexing:  https://developer.android.com/tools/building/multidex.html
    multiDexEnabled true
}

Have a look here

https://code.google.com/p/android/issues/detail?id=81804

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • 1
    Same error: Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry: org/opencv/BuildConfig.class – Rafael Ruiz Muñoz Oct 01 '15 at 13:07
  • 1
    @RafaelRuiz Okay .Check this Url http://stackoverflow.com/questions/26718825/how-to-resolve-java-util-zip-zipexception and https://developer.android.com/intl/ja/tools/building/multidex.html#testing – IntelliJ Amiya Oct 01 '15 at 13:11