封装同一个库的多个APK可能仅在AGP 4.0.1上使用一个动态模块就导致运行时错误?

问题描述

我的项目中只有一个动态功能模块,称为搜索,但是当我尝试构建项目时,出现该错误:

    [:search,:search] all package the same library [androidx.recyclerview:recyclerview].
    
    Multiple APKs packaging the same library can cause runtime errors.
    Placing each of the above libraries in its own dynamic feature and adding that
    feature as a dependency of modules requiring it will resolve this issue.
    Libraries that are always used together can be combined into a single feature
    module to be imported by their dependents. If a library is required by all
    feature modules it can be added to the base module instead.

当然,我要做的第一件事是研究有相同问题的人,然后我发现:

1- This Question 2- This medium article

两者都引入了相同的解决方案(使用Android Gradle Plugin 4.0),而我的项目使用了AGP 4.0.1,但是问题是我只有一个动态模块,称为搜索。我没有任何其他动态模块,甚至我的搜索gradle文件中都没有RecyclerView的依赖项:androidx.recyclerview:recyclerview,所以这可能是可传递的依赖项。

此外,您可以通过以下两种方式之一找到重复的依赖项:

1-导航至:PROJECT_NAME / module_name(在我的情况下:搜索)/ build / intermediates /

然后在该目录中搜索“ deps.txt”文件,打开该文件,您将看到所有模块依赖项直接和传递。

2-运行./gradlew:module_name:dependencies任务

如果您尝试从“ deps.txt”文件中删除重复的行:androidx.recyclerview:recyclerview,则在每次构建后都会再次生成它。

话虽如此,我需要在packagingOptions {}中使用一些规则,例如exclude,以防止search.aar与任何其他search.*格式之间的冲突

有人可以帮忙吗?

解决方法

就我而言,我从其中一个模块中删除了以下内容

注意:不是来自基础模块

implementation 'androidx.legacy:legacy-support-v4:1.0.0'

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...