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 引用

相关推荐
梓色系1 小时前
Spring AI 实战:从零搭建 MCP 客户端与服务端,让大模型拥有“手脚“
java·人工智能·spring
anthonyzhu1 小时前
安卓Android studio panda run无法应用更新的问题
android·ide·android studio
秦时星星1 小时前
Spring AI + FastMCP 跨语言集成踩坑实录
java·人工智能·spring
见牛羊2 小时前
docker理解
java·docker·容器
codingPower2 小时前
JAVA后端安全进阶:基于HMAC-SHA256+Nonce+Timestamp的API防重放攻击方案
java·开发语言·spring boot·安全
寂夜了无痕2 小时前
IntelliJ IDEA 高效配置:新建文件自动生成作者与时间注释
java·ide·intellij-idea
leonidZhao2 小时前
Java 25新特性:模块导入申明
java
weixin_489690022 小时前
【IDEA 2025.2.4】 Maven 仅能手动 Reload All Maven Projects 问题解决
java·maven·intellij-idea
雨辰AI2 小时前
MySQL 迁移至达梦 DM9 完整改造指南|99% SQL 零改动
java·开发语言·数据库·sql·mysql·政务