错误:程序类型已存在:androidx.asynclayoutinflater.R

时间:2019-07-18 12:20:37

标签: android androidx

我尝试将我的应用程序所使用的facebook sdk升级到最新版本(5.1.1),这使我不知疲倦地将项目迁移到AndroidX。完成迁移并解决了一些问题之后,我现在遇到了构建问题Error: Program type already present: androidx.asynclayoutinflater.R

我一直在尝试使用this answer及其其他变体来解决我的问题,但是我发现很难找到哪些库正在使用androidx.asynclayoutinflater.R

当我放弃依赖时,我会得到这个

+--- androidx.databinding:databinding-adapters:3.4.2@aar
+--- androidx.databinding:databinding-runtime:3.4.2@aar
+--- androidx.databinding:databinding-common:3.4.2@jar
+--- androidx.emoji:emoji-appcompat:1.0.0@aar
+--- com.codewaves.stickyheadergrid:stickyheadergrid:0.9.6@aar
+--- com.google.android.material:material:1.0.0@aar
+--- com.kishan.askpermission:askpermission:1.0.3@aar
+--- com.theartofdev.edmodo:android-image-cropper:2.8.0@aar
+--- uk.co.chrisjenx:calligraphy:2.3.0@aar
+--- com.facebook.android:facebook-android-sdk:5.1.1@aar
+--- com.facebook.android:facebook-login:5.1.1@aar
+--- com.facebook.android:facebook-share:5.1.1@aar
+--- com.facebook.android:facebook-common:5.1.1@aar
+--- androidx.appcompat:appcompat:1.0.2@aar
+--- androidx.browser:browser:1.0.0@aar
+--- androidx.cardview:cardview:1.0.0@aar
+--- androidx.constraintlayout:constraintlayout:1.1.3@aar
+--- androidx.gridlayout:gridlayout:1.0.0@aar
+--- androidx.legacy:legacy-support-v13:1.0.0@aar
+--- androidx.legacy:legacy-support-v4:1.0.0@aar
+--- com.andkulikov:transitionseverywhere:1.8.0@aar
+--- com.google.firebase:firebase-messaging:19.0.1@aar
+--- com.google.firebase:firebase-perf:18.0.1@aar
+--- com.github.bumptech.glide:glide:4.8.0@aar
+--- com.google.firebase:firebase-config:18.0.0@aar
+--- com.segment.analytics.android.integrations:firebase:1.3.1@jar
+--- com.google.firebase:firebase-core:17.0.1@aar
+--- com.google.firebase:firebase-analytics:17.0.0@aar
+--- com.google.android.gms:play-services-measurement-api:17.0.0@aar
+--- com.google.firebase:firebase-iid:19.0.1@aar
+--- com.google.firebase:firebase-abt:18.0.0@aar
+--- com.google.firebase:firebase-common:18.0.0@aar
+--- com.google.android.gms:play-services-clearcut:17.0.0@aar
+--- com.google.android.gms:play-services-phenotype:17.0.0@aar
+--- com.google.firebase:firebase-iid-interop:17.0.0@aar
+--- com.google.android.gms:play-services-base:17.0.0@aar
+--- com.google.android.gms:play-services-tasks:17.0.0@aar
+--- com.google.firebase:firebase-measurement-connector:18.0.0@aar
+--- com.google.android.gms:play-services-measurement:17.0.0@aar
+--- com.google.android.gms:play-services-measurement-sdk:17.0.0@aar
+--- com.google.android.gms:play-services-measurement-impl:17.0.0@aar
+--- com.google.android.gms:play-services-stats:17.0.0@aar
+--- com.google.android.gms:play-services-measurement-sdk-api:17.0.0@aar
+--- com.google.android.gms:play-services-measurement-base:17.0.0@aar
+--- com.google.android.gms:play-services-ads-identifier:17.0.0@aar
+--- com.google.android.gms:play-services-basement:17.0.0@aar
+--- androidx.fragment:fragment:1.0.0@aar
+--- androidx.vectordrawable:vectordrawable-animated:1.0.0@aar
+--- ca.barrenechea.header-decor:header-decor:0.2.8@aar
+--- androidx.recyclerview:recyclerview:1.0.0@aar
+--- androidx.legacy:legacy-support-core-ui:1.0.0@aar
+--- com.facebook.android:facebook-places:5.1.1@aar
+--- com.facebook.android:facebook-applinks:5.1.1@aar
+--- com.facebook.android:facebook-messenger:5.1.1@aar
+--- com.facebook.android:facebook-core:5.1.1@aar
+--- androidx.legacy:legacy-support-core-utils:1.0.0@aar
+--- androidx.vectordrawable:vectordrawable:1.0.1@aar
+--- androidx.emoji:emoji-bundled:1.0.0@aar
+--- androidx.emoji:emoji:1.0.0@aar
+--- androidx.media:media:1.0.0@aar
+--- androidx.transition:transition:1.0.0@aar
+--- androidx.loader:loader:1.0.0@aar
+--- androidx.viewpager:viewpager:1.0.0@aar
+--- androidx.coordinatorlayout:coordinatorlayout:1.0.0@aar
+--- androidx.drawerlayout:drawerlayout:1.0.0@aar
+--- androidx.slidingpanelayout:slidingpanelayout:1.0.0@aar
+--- androidx.customview:customview:1.0.0@aar
+--- androidx.swiperefreshlayout:swiperefreshlayout:1.0.0@aar
+--- androidx.asynclayoutinflater:asynclayoutinflater:1.0.0@aar
+--- androidx.core:core:1.0.2@aar
+--- androidx.multidex:multidex:2.0.1@aar
+--- com.anjlab.android.iab.v3:library:1.0.44@jar
+--- com.appsflyer:segment-android-integration:1.18@aar
+--- com.segment.analytics.android.integrations:mixpanel:2.1.0@jar
+--- com.segment.analytics.android:analytics:4.4.0-beta1@jar
+--- com.squareup.okhttp3:logging-interceptor:3.12.0@jar
+--- com.squareup.retrofit2:converter-gson:2.5.0@jar
+--- com.squareup.retrofit2:retrofit:2.5.0@jar
+--- io.branch.sdk.android:library:2.19.5@aar
+--- joda-time:joda-time:2.10.1@jar
+--- me.leolin:ShortcutBadger:1.1.21@aar
+--- me.relex:circleindicator:1.2.2@aar
+--- org.greenrobot:eventbus:3.1.1@jar
+--- se.emilsjolander:StickyScrollViewItems:1.1.0@aar
+--- com.crashlytics.sdk.android:crashlytics:2.7.1@aar
+--- androidx.test.espresso:espresso-idling-resource:3.2.0@aar
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31@jar
+--- com.jakewharton.rxbinding:rxbinding:0.3.0@aar
+--- androidx.lifecycle:lifecycle-runtime:2.0.0@aar
+--- androidx.versionedparcelable:versionedparcelable:1.0.0@aar
+--- androidx.collection:collection:1.0.0@jar
+--- androidx.cursoradapter:cursoradapter:1.0.0@aar
+--- androidx.interpolator:interpolator:1.0.0@aar
+--- com.github.bumptech.glide:gifdecoder:4.8.0@aar
+--- androidx.exifinterface:exifinterface:1.0.0@aar
+--- androidx.lifecycle:lifecycle-livedata:2.0.0@aar
+--- androidx.lifecycle:lifecycle-livedata-core:2.0.0@aar
+--- androidx.lifecycle:lifecycle-common:2.0.0@jar
+--- androidx.arch.core:core-runtime:2.0.0@aar
+--- androidx.arch.core:core-common:2.0.0@jar
+--- androidx.documentfile:documentfile:1.0.0@aar
+--- androidx.localbroadcastmanager:localbroadcastmanager:1.0.0@aar
+--- androidx.print:print:1.0.0@aar
+--- androidx.lifecycle:lifecycle-viewmodel:2.0.0@aar
+--- androidx.annotation:annotation:1.0.2@jar
+--- androidx.constraintlayout:constraintlayout-solver:1.1.3@jar
+--- com.appsflyer:af-android-sdk:4.10.0@aar
+--- com.github.bumptech.glide:disklrucache:4.8.0@jar
+--- com.github.bumptech.glide:annotations:4.8.0@jar
+--- com.squareup.okhttp3:okhttp:3.12.0@jar
+--- com.mixpanel.android:mixpanel-android:5.6.2@aar
+--- com.google.code.gson:gson:2.8.2@jar
+--- com.crashlytics.sdk.android:answers-shim:0.0.6@aar
+--- com.crashlytics.sdk.android:beta:1.2.7@aar
+--- com.crashlytics.sdk.android:crashlytics-core:2.4.1@aar
+--- com.crashlytics.sdk.android:answers:1.4.1@aar
+--- io.fabric.sdk.android:fabric:1.4.1@aar
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.31@jar
+--- io.reactivex:rxjava:1.0.14@jar
+--- com.parse.bolts:bolts-android:1.4.0@jar
+--- com.google.zxing:core:3.3.3@jar
+--- com.google.auto.value:auto-value-annotations:1.6.3@jar
+--- com.squareup.okio:okio:1.15.0@jar
+--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.31@jar
+--- org.jetbrains:annotations:13.0@jar
+--- com.parse.bolts:bolts-applinks:1.4.0@jar
\--- com.parse.bolts:bolts-tasks:1.4.0@jar

该行仅显示+--- androidx.asynclayoutinflater:asynclayoutinflater:1.0.0@aar行一次(每个产品风味/构建类型一次)

更新: 发现了更多类似依存关系图的树,这是一个代码段,但是其中有很多东西,甚至不能将其粘贴到pastebin上

+--- androidx.appcompat:appcompat:1.0.2
|    +--- androidx.fragment:fragment:1.0.0
|    |    +--- androidx.core:core:1.0.0 -> 1.0.2 (*)
|    |    +--- androidx.legacy:legacy-support-core-ui:1.0.0
|    |    |    +--- androidx.asynclayoutinflater:asynclayoutinflater:1.0.0
|    |    |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.0.2
|    |    |    |    \--- androidx.core:core:1.0.0 -> 1.0.2 (*)

试图删除似乎无效的

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.multidex:multidex:2.0.1'

我的依赖关系如下

dependencies {
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.core:core:1.0.2'
    implementation 'androidx.emoji:emoji-appcompat:1.0.0'
    implementation 'androidx.emoji:emoji-bundled:1.0.0'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
    implementation 'androidx.legacy:legacy-support-v13:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'ca.barrenechea.header-decor:header-decor:0.2.8'
    implementation 'com.andkulikov:transitionseverywhere:1.8.0'
    implementation 'com.anjlab.android.iab.v3:library:1.0.44'
    implementation 'com.appsflyer:segment-android-integration:1.+'
    implementation 'com.codewaves.stickyheadergrid:stickyheadergrid:0.9.6'
    implementation 'com.facebook.android:facebook-android-sdk:5.1.1'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'
    implementation 'com.google.firebase:firebase-perf:18.0.1'
    implementation 'com.kishan.askpermission:askpermission:1.0.3'
    implementation 'com.segment.analytics.android.integrations:firebase:1.3.1'
    implementation 'com.segment.analytics.android.integrations:mixpanel:2.1.0'
    implementation 'com.segment.analytics.android:analytics:4.+'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.12.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
    implementation 'io.branch.sdk.android:library:2.+'
    implementation 'joda-time:joda-time:2.10.1'
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
    implementation 'me.relex:circleindicator:1.2.2@aar'
    implementation 'org.greenrobot:eventbus:3.1.1'
    implementation 'se.emilsjolander:StickyScrollViewItems:1.1.0'
    implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
        transitive = true;
    }
    kapt 'com.github.bumptech.glide:compiler:4.8.0'

    //---Testing---
    testImplementation 'junit:junit:4.12'
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    androidTestImplementation('androidx.test.espresso:espresso-contrib:3.1.0') {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude module: 'recyclerview-v7'
    }
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
    implementation 'androidx.test.espresso:espresso-idling-resource:3.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestUtil 'androidx.test:orchestrator:1.2.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31"
    implementation 'com.jakewharton.rxbinding:rxbinding:0.3.0'
    //-------------
}

我也尝试过强制支持库版本,不确定它是否有用,还是我做错了,但是我在SO上的帖子中看到了建议

final SUPPORT_LIB_VER = '28.0.0'

configurations.all {
    resolutionStrategy {
        force "com.android.support:appcompat-v7:${SUPPORT_LIB_VER}"
        force "com.android.support:support-v4:${SUPPORT_LIB_VER}"
    }
}

我的gradle.properties中也有这个

android.enableJetifier=true
android.useAndroidX=true

有人知道一种简单的方法来查找使用此特定依赖项的内容的方法,以便我可以尝试解决重复项,或者只是知道是什么库引起了该重复项吗?

2 个答案:

答案 0 :(得分:2)

对于此常见问题,我建议使用稍微不同的方法。最重要的是:从干净的石板开始!这意味着,依次选择“文件”->“使缓存无效/重新启动”,然后依次选择“构建”->“清理项目”和“构建”->“重建项目”。现在将所有依赖项更新为最新(尽管有时会引入蠕虫,因为可能会引入新问题)。这通常会为我解决。

我时不时地遇到这个问题,并且发现在分支之间切换时会发生这种情况,因为它们之间的依赖关系有所不同。因此,如果您要在服务分支(例如,维护生产代码)和功能分支(例如,引入新的依赖项,无论是名称还是只是版本)之间来回切换,就会遇到这种情况。 Android Studio在切换分支时清理(很多事情,尤其是清理)方面做得很差。它正在查看过时的缓存信息,并发现实际上并不存在的冲突。

我希望这会有所帮助!

答案 1 :(得分:0)

因此,经过几天的苦难,我终于找到了问题

我不得不改变

implementation 'com.segment.analytics.android.integrations:firebase:1.3.1'

implementation 'com.segment.analytics.android.integrations:firebase:1.3.1@aar'

fml

解决这个问题的最简单方法是找到一个干净的新android项目,并将所有来自主项目的依赖项放到那里,然后使用分而治之来查明具体是哪个库导致了该问题。找到一个随机的0级答案,该答案建议不加解释地将@aar放在最后,并且有效。