Android 开发问题:项目同时引入了两个包含相同类文件的库(AndroidX 库、旧版本支持库),导致了重复类错误

groovy 复制代码
implementation 'com.pes.materialcolorpicker:library:1.2.5'
java 复制代码
ColorPicker colorPicker = new ColorPicker(this);

colorPicker.setColor(Color.RED);

colorPicker.setCallback(color -> {
    colorPicker.dismiss();
    Log.i(TAG, "color = " + color);
});

colorPicker.show();
  • 在 Android 开发中,引入 ColorPicker 后,构建项目时,出现如下错误信息

    Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
    Duplicate class android.support.v4.app.INotificationSideChannelStub found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.app.INotificationSideChannelStubProxy found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.os.IResultReceiverStub found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
    Duplicate class android.support.v4.os.IResultReceiverStubProxy found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
    Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
    Duplicate class android.support.v4.os.ResultReceiver1 found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.os.ResultReceiverMyResultReceiver found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
    Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)

    解读

    在模块 core-1.9.0-runtime(androidx.core:core:1.9.0)
    和 support-compat-25.3.1-runtime(com.android.support:support-compat:25.3.1)
    中发现重复的类 android.support.v4.app.INotificationSideChannel

    ...

问题原因
  • 项目同时引入了两个包含相同类文件的库,导致了重复类错误,冲突双方如下
  1. AndroidX 库(新版本支持库):androidx.core:core:1.9.0

  2. 旧版本支持库:com.android.support:support-compat:25.3.1

处理策略
  • gradle.properties 文件中添加如下内容
properties 复制代码
android.useAndroidX=true
android.enableJetifier=true
  1. android.useAndroidX=true:表示项目使用 AndroidX 库

  2. android.enableJetifier=true:表示允许 Gradle 自动重写旧的第三方库的二进制文件,将其中的旧支持库引用转换为 AndroidX 引用

相关推荐
IKUN家族4 小时前
Spring MVC(一)
java·spring·mvc
老马识途2.06 小时前
关于跨域问题的总结
java·前端
都叫我大帅哥6 小时前
Java日期时间三十年战争:从Date考古到LocalDateTime革命,以及数据库与前端的那点事儿
java
Muscleheng6 小时前
SpringBoot 集成 DeepSeek 实现 RAG 文档问答
java·spring boot·ai·springai
2501_936415697 小时前
可变参数&综合练习&斗地主游戏
java·windows·游戏
solo_998 小时前
用 LSPosed 模拟录屏音频编码器卡顿:从思路到落地
android
极客先躯8 小时前
高级java每日一道面试题-2026年05月03日-实战篇[Docker]-如何实现容器化环境的数据加密?
java·运维·docker·容器·金融·加解密·高级面试
zzq77978 小时前
别把大模型 API Key 写进 APK:移动 AI 应用接口防盗刷实践
android·人工智能·安全·app加固·御盾安全·安卓加固
xqqxqxxq9 小时前
Java Socket 多人聊天室(私聊+群聊)技术笔记(V4版本)
java·网络·笔记
wang09079 小时前
自己动手写一个spring之aop_1
java·后端·spring