解决动态功能模块中重复的库包含问题

问题描述 投票:0回答:1

我正在开发一个具有动态功能模块的 Android 项目,并且遇到了与重复的库包含相关的构建错误。 我有两个模块,一个是使用 mlkit 人脸检测 -

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

其他正在使用 mlkit 条形码扫描 -

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

错误如下: 任务“: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'].

我需要什么 - 我想探索解决方案。
一种解决方案是在这些模块之间创建基础模块。我不想这样做,因为我只有一个模块所有权。虽然我尝试使用medium文章来解决同样的问题,但它还有其他问题

显示相同问题的示例代码

第二种解决方案,将通用库保留在应用程序模块中,由于基础 apk 的大小增加,这是不可行的。

android gradle google-mlkit dynamic-feature-module dynamic-delivery
1个回答
0
投票

您可以尝试两个动态模块的

aar
文件依赖关系。在
aar
文件中,您只能添加公共依赖项。确保在编译这样的动态模块时排除这些 -

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile ("com.xxx:xxx-commons:1.+") {
        exclude group: 'junit', module: 'junit'
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.