接入ARouter踩坑记录

背景:

ARouter的版本号:

implementation'com.alibaba:arouter-api:1.5.2'
annotationProcessor 'com.alibaba:arouter-compiler:1.5.2'

本地引用的androidx的版本

implementation 'androidx.appcompat:appcompat:1.2.0'

问题一:

2 files found with path 'META-INF/androidx.cursoradapter_cursoradapter.version'.

2 files found with path 'META-INF/androidx.cursoradapter_cursoradapter.version'.
Adding a packagingOptions block may help, please refer to
https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html
for more information

ARouter里面用了全部是android.support的包

implementation "com.android.support:support-v4:${SUPPORT_LIB_VERSION}"

报错原因就是support包里面的META-INF文件里面字段和androidx里面的NETA-INF重复了

百度了下解决方案是说在app模块的android下面添加如下代码:

packagingOptions {
        exclude 'META-INF/androidx.viewpager_viewpager.version'
        exclude 'META-INF/androidx.cursoradapter_cursoradapter.version'
        exclude 'META-INF/androidx.drawerlayout_drawerlayout.version'
        ....
    }

但是android添加到一半发现太多冲突了这样写很麻烦于是做了简单改进:

android {
    ....
    packagingOptions {
        exclude 'META-INF/androidx.*'
    }
}

这样只用添加一个排除项即可

问题二:  同一个类在不通版本的包里面导致合并失败

Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)

Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class androidx.core.graphics.drawable.IconCompatParcelizer found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class androidx.core.internal.package-info found in modules core-1.3.1-runtime (androidx.core:core:1.3.1) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Duplicate class androidx.versionedparcelable.CustomVersionedParcelable found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.NonParcelField found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelField found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelImpl found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelImpl$1 found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelUtils found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel$1 found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel$ParcelException found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelParcel found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelStream found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelStream$FieldBuffer found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelable found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelize found in modules versionedparcelable-1.1.0-runtime (androidx.versionedparcelable:versionedparcelable:1.1.0) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0)

Go to the documentation to learn how to Fix dependency resolution errors.

解决方式:  在依赖的时候做一个排除项

dependencies {
    implementation('com.alibaba:arouter-api:1.5.2') {
        exclude group: 'com.android.support', module: 'support-compat'
        exclude group: 'com.android.support', module: 'loader'
        exclude group: 'com.android.support', module: 'versionedparcelable'
    }
    annotationProcessor 'com.alibaba:arouter-compiler:1.5.2'
    ....
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值