迁移安卓项目到AndroidX报错:Duplicate class android.support.v4.app.INotificationSideChannel found in modules..

本文记录了在将Android项目从旧版支持库迁移到AndroidX过程中遇到的编译错误,提供了详细的错误日志,并分享了解决方案,即在gradle.properties文件中配置特定属性以确保项目正确编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

趁周末,把安卓项目的代码迁移到AndroidX,有些项目是引用了第三库,有些是全部使用AndroidX的支持库,然后编译报错日志如下:

 

Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-27.1.1-runtime.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-27.1.1-runtime.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-27.1.1-runtime.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-27.1.1-runtime.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-27.1.1-runtime.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-27.1.1-runtime.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-27.1.1-runtime.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-27.1.1-runtime.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-27.1.1-runtime.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-27.1.1-runtime.jar (com.android.support:support-compat:27.1.1)

Go to the documentation to learn how to Fix dependency resolution errors.

 

 

我的解决办法是:在项目根目录下的gradle.properties文件中加上如下属性来解决:

 
# 需要在gradle.properties中添加下面两行代码
# 这是因为混合支持库。通过添加这些行选择androidX作为您的支持库
 
android.useAndroidX=true
android.enableJetifier=true

 这里做个记录,防止以后忘记。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

andrew_style

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值