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

趁周末,把安卓项目的代码迁移到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

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

你可能感兴趣的:(Android)