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...
问题原因
- 项目同时引入了两个包含相同类文件的库,导致了重复类错误,冲突双方如下
-
AndroidX 库(新版本支持库):
androidx.core:core:1.9.0 -
旧版本支持库:
com.android.support:support-compat:25.3.1
处理策略
- 在
gradle.properties文件中添加如下内容
properties
android.useAndroidX=true
android.enableJetifier=true
-
android.useAndroidX=true:表示项目使用 AndroidX 库 -
android.enableJetifier=true:表示允许 Gradle 自动重写旧的第三方库的二进制文件,将其中的旧支持库引用转换为 AndroidX 引用