"Multiple dex files define...." exception while building app


#1

Hi,

I’m trying to use in my project nativescript carousel plugin but getting exception while building app. This is full message:

...
Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:591)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:546)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:528)
        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)
    
:transformClassesWithDexForF0F1Debug FAILED
...

I’ve tried to build also demo app provided by plugin creator in repo https://github.com/manijak/nativescript-carousel but I get the same error. Steps to reproduce:

git clone https://github.com/manijak/nativescript-carousel
cd nativescript-carousel/demo
tns build android

Any idea how to prevent this issue? Can it be related to Android SDK versions I have installed?

Kind regards -
Krzysztof Ksiezyk


#2

As can be seen from the log, there is an obvious conflict in plugins downloaded when using the nativescript-carousel native plugin. By default your android app will reference the appcompat dependency based on the latest version installed from the android sdkmanager.

Say you recently updated - the latest available 'com.android.support:support-compat:25.3.1' is 25.3.1, and that’s the version that will be used in the project.

Now here’s what I think is breaking your app - adding the carousel is the tricky part - it depends on a native plugin itself, that has a hardcoded appcompat dependency of 'com.android.support:support-compat:25.3.0' (https://github.com/romandanylyk/PageIndicatorView/blob/master/pageindicatorview/build.gradle). You could go to your app/App_Resources/Android/app.gradle and modify/add compile 'com.android.support:support-compat:25.3.0' so both versions will match and not conflict when building.


#3

Hi,

Thanks for help. Following this idea, I’ve tried to add by hand support compat module but without success. Then I’ve grepped files for AccessibilityServiceInfoVersionImpl string and found modules where it’s defined

> grep -R AccessibilityServiceInfoVersionImpl 
platforms/android/build-tools/android-static-binding-generator/interfaces-names.txt:android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat.AccessibilityServiceInfoVersionImpl
platforms/android/build-tools/android-static-binding-generator/interfaces-names.txt:android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat.AccessibilityServiceInfoVersionImpl
Binary file platforms/android/build/intermediates/exploded-aar/com.android.support/support-compat/25.3.0/jars/classes.jar matches
Binary file platforms/android/build/intermediates/exploded-aar/com.android.support/support-v4/23.4.0/jars/classes.jar matches

Finally I’ve ended up with addting this to app.grandle

configurations {
        all*.exclude group: 'com.android.support', module: 'support-compat'
        all*.exclude group: 'com.android.support', module: 'support-core-ui'
    }

and now it works.