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

相关推荐
St_rive11 小时前
Page Object设计模式
java·开发语言·设计模式
风流 少年12 小时前
Spring AI 2.0:SSE
java·人工智能·spring
凤山老林12 小时前
精细化流量治理:Spring Boot 动态特性开关与灰度发布体系
java·spring boot·后端
Aphelios38014 小时前
一次锁内网络IO引发的Tomcat线程池“饿死”事故
java·开发语言·spring boot·elasticsearch·tomcat·网络io阻塞·线程池耗尽
不可求~15 小时前
C++ std::string_view 不是字符串:从悬空引用到安全用法
java·开发语言·c++
Lam Tang15 小时前
APS 系列文章10
java·代理模式
考虑考虑15 小时前
Excel导入时产生特殊字符处理
java·后端·java ee
Scabbards_16 小时前
面试Leetcode - Heap 堆
java·leetcode·面试
程序员清风16 小时前
专业再升级!程序员专属显示器明基RD280UG上手实测!
java·后端·面试
启雀AI17 小时前
培训平台移动端离线学习方案设计与实现:视频缓存、断点续传与进度同步的工程实践
android·学习·缓存·音视频·企业lms