Duplicate class error,Android support和Androidx库共存的问题
这两天正好遇到这样一个问题,公司项目在引入新的aar库时出现了下面这个错误。除此之外还有一个AndroidManifest.xml文件merge error。
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar
在网上查了下资料,大概了解是因为新引入的包使用的android.support包,而我们的项目工程已经整体迁移到androidx,这两个库在功能上是重叠的,所以导致了上述的报错。
针对这种情况android官方提供了一种方式。在项目根目录下的gradle.properties文件中加入这两行。
android.useAndroidX=true//是否使用

在引入使用android.support的aar库时,Android项目出现Duplicate class错误和AndroidManifest.xml merge error。原因是已有项目使用了androidx库。通过在gradle.properties文件中加入特定配置可以解决大部分问题,但当项目中存在定制过的android.support库时,启用或禁用'android.enableJetifier'都会引发问题。解决方案是使用Android官网未明确提及的配置忽略特定库的转换,从而避免冲突。
最低0.47元/天 解锁文章
7302

被折叠的 条评论
为什么被折叠?



