【问题标题】:Migrate to AndroidX - "Program type already present: android.support.v4.media.MediaBrowserCompat迁移到 AndroidX -“程序类型已存在:android.support.v4.media.MediaBrowserCompat
【发布时间】:2020-01-27 22:53:12
【问题描述】:

我正在迁移到 androidX 并被此异常阻止。

AGPBI: {"kind":"error","text":"Program type already present: 
android.support.v4.media.MediaBrowserCompat$ConnectionCallback$StubApi21",
"sources":[{}],"tool":"D8"}

这就是我的应用程序依赖项的样子,

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.adobe.mobile:adobeMobileLibrary:4.17.2'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-common-java8:2.1.0'
    implementation 'com.jakewharton.timber:timber:4.5.1'
    implementation "com.squareup.retrofit2:retrofit:${retrofitLibraryVersion}"
    implementation "com.squareup.retrofit2:converter-gson:${retrofitLibraryVersion}"
    implementation "com.squareup.retrofit2:adapter-rxjava2:${retrofitLibraryVersion}"
    implementation "com.squareup.okhttp3:logging-interceptor:${okHttpLibraryVersion}"
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.github.bumptech.glide:glide:3.8.0'
    implementation "org.bouncycastle:bcprov-jdk15on:${bouncyCastleVersion}"
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    implementation 'com.google.dagger:dagger:2.10'
    implementation 'com.airbnb.android:lottie:2.7.0'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.10'
    implementation 'com.airbnb.android:lottie:2.7.0'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation "com.google.firebase:firebase-messaging:17.4.0"
    implementation 'com.scottyab:rootbeer-lib:0.0.7'

    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:2.7.5'
    testImplementation "com.squareup.okhttp3:mockwebserver:${okHttpLibraryVersion}"
    testImplementation 'commons-codec:commons-codec:1.11'
    testImplementation 'pl.pragmatists:JUnitParams:1.1.1'

    androidTestImplementation 'org.apache.commons:commons-lang3:3.5'

    androidTestImplementation('androidx.test:runner:1.1.0') {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestImplementation('androidx.test:rules:1.1.0') {
        exclude group: 'com.android.support', module: 'support-annotations'
    }

    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    androidTestImplementation('androidx.test.espresso:espresso-intents: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: 'support-annotations'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'com.android.support', module: 'design'
        exclude group: 'com.android.support', module: 'recyclerview-v7'
    })
    androidTestImplementation 'org.mockito:mockito-core:2.7.5'
    androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'
    androidTestImplementation "com.squareup.okhttp3:mockwebserver:${okHttpLibraryVersion}"

}

我已经尝试排除这个模块,如下所示,

exclude group: 'com.android.support', module: 'support-media-compat'

真的不确定这一点,因为像这样排除,可能会在运行时破坏功能。

任何建议将不胜感激。

【问题讨论】:

标签: java android android-gradle-plugin build.gradle androidx


【解决方案1】:

1)。第一步应该是,使用获取依赖图/树,

gradlew app:dependencies --scan 

(在我的例子中,app 是模块名称)

2)。然后找出哪个正在使用受影响的模块,就我而言,它是 support-compat & support-media-compat in firebase-core强>依赖

排除受影响的模块有助于我编译,但由于在运行时使用排除的模块而导致崩溃,所以这不是正确的做法。

3)。这里的诀窍是,将所有依赖项更新到最新版本。

一旦你迁移到AndroidX,如果你遇到编译错误,记下它,只是注释掉那些行,实际上可以帮助你编译,但这不是正确的方法。您需要查看受影响的依赖项是迁移到 AndroidX 还是仍在使用支持库。

如果受影响的依赖项尚未迁移到 AndroidX,您将无能为力。,如果依赖项正在生成使用支持库的代码

【讨论】:

  • 如果受影响的依赖项尚未迁移到 AndroidX,您将无能为力。仅当依赖项生成使用支持库的代码时才会如此。 Jetifier 处理其他所有事情
【解决方案2】:

我通过将此行添加到Gradle 中解决了这个问题。 Google Document

implementation "androidx.media:media:1.1.0"

【讨论】:

    猜你喜欢
    • 2018-12-25
    • 2019-07-13
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 2018-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多