androidgradlegoogle-mlkitdynamic-feature-moduledynamic-delivery

Resolving Duplicate Library Inclusion in Dynamic Feature Modules


I'm working on an Android project with dynamic feature modules and have encountered a build error related to duplicate library inclusions. I have two modules, one is using mlkit face detection -

com.google.android.gms:play-services-mlkit-face-detection:17.1.0

and other is using mlkit barcode scanning -

com.google.android.gms:play-services-mlkit-barcode-scanning:18.3.0

The error is as follows: Execution failed for task ':app:checkDebugLibraries'.

[:dynamicfeature2, :facedetector] all package the same library [androidx.exifinterface:exifinterface;Capability: group='androidx.exifinterface', name='exifinterface'].
    [:dynamicfeature2, :facedetector] all package the same library [com.google.android.odml:image;Capability: group='com.google.android.odml', name='image'].
    [:dynamicfeature2, :facedetector] all package the same library [com.google.mlkit:vision-common;Capability: group='com.google.mlkit', name='vision-common'].
    [:dynamicfeature2, :facedetector] all package the same library [com.google.mlkit:vision-interfaces;Capability: group='com.google.mlkit', name='vision-interfaces'].

What I need - I want to explore solutions.
One solution is creating base module between these modules. I dont want to do it, because I have one module ownership only. Although I tried with medium article for same issue but it has other issues

sample code to show same issue

Second solution, keeping common libs in app module, which is not feasible due to size increase in base apk.

Related google issue tracker link


Solution

  • You can try aar file dependency for both dynamic modules. In aar file, you can add only common dependencies. Make sure to exclude those while compiling dynamic modules like this -

    dependencies {
        compile 'com.android.support:support-v4:13.0.+'
        compile ("com.xxx:xxx-commons:1.+") {
            exclude group: 'junit', module: 'junit'
        }
    }