导航片段与 JetPack 库的依赖关系

Navigation fragment dependencies with JetPack libraries

我正在使用 Jetpack 库开发 Android 应用程序。 我也想使用导航,以更酷的方式定义导航。为此,我包括(Android Studio 为我做的)依赖项:

implementation 'android.arch.navigation:navigation-fragment:1.0.0-beta02'

我正在使用 JetPack 库(不要看我是如何定义它们的,它是有效的):

   lifecycleVersion = '2.0.0'
    loggingRetrofitVersion = "3.9.0"
    butterKnife = "10.0.0"
    kriptonVersion = "5.1.0-rc.3"
    eventBusVersion = "3.1.1"

    okHttpVersion="3.13.1"
    kriptonVersion = "5.1.0-rc.3"
    aboutlibrariesVersion = "6.1.1"
    daggerVersion="2.21"
    glideVersion="4.8.0"

    // Testing
    jUnitVersion = '4.12'
    mockitoVersion = '2.13.+'
    jacocoVersion = '0.7.9'
    espressoVersion="3.1.0"

    // Libraries android
    appCompatVersion = '1.0.2'
    supportAnnotationVersion="1.0.0"
    multidexVersion = '2.0.0'
    cardviewVersion="1.0.0"
    constraintLayoutVersion="1.1.3"
    coordinatorLayoutVersion="1.0.0"
    recyclerViewVersion="1.0.0"
    materialVersion="1.1.0-alpha03"
    viewPagerVersion="1.0.0"

    // Presentation
    appDependencies = [
            "androidx.appcompat:appcompat:$appCompatVersion",
            "androidx.cardview:cardview:$cardviewVersion",
            "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion",
            "androidx.coordinatorlayout:coordinatorlayout:$coordinatorLayoutVersion",
            "androidx.recyclerview:recyclerview:$recyclerViewVersion",
            "androidx.viewpager:viewpager:$viewPagerVersion",
            "com.google.android.material:material:$materialVersion",

            // ViewModel and LiveData
            "androidx.lifecycle:lifecycle-livedata-core:$lifecycleVersion",
            "androidx.lifecycle:lifecycle-runtime:$lifecycleVersion",
            "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion",
            "androidx.lifecycle:lifecycle-extensions:2.1.0-alpha02",

           "org.greenrobot:eventbus:$eventBusVersion",

            "com.jakewharton:butterknife:$butterKnife",
            "com.abubusoft:kripton-android-library:$kriptonVersion",
            "com.squareup.okhttp3:logging-interceptor:$loggingRetrofitVersion",

            "com.google.dagger:dagger:$daggerVersion",    
            "com.squareup.retrofit2:converter-scalars:2.5.0",

            "io.reactivex:rxjava:1.1.8"

    ]

由于我包含了库导航,当我尝试构建项目时收到以下错误:

> Task :app:processDebugManifest FAILED
D:\mobile\my-project\app\src\main\AndroidManifest.xml:22:18-86 Error:
    Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.1.0-alpha03] AndroidManifest.xml:22:18-86
    is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:7:5-99:19 to override.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

好的,我可以简单地添加新标签..但我想避免在我的项目中有 androidx 和旧的支持库。

我怎样才能做到这一点? JetPack 是否有 android.arch.navigation:navigation-fragment 等效库?我找到了,但我什么也没找到。

提前致谢。

更新:我运行 gradle 目标依赖项,结果是(对于特定库):

+--- android.arch.navigation:navigation-fragment:1.0.0-beta02
|    +--- com.android.support:support-fragment:28.0.0
|    |    +--- com.android.support:support-compat:28.0.0
|    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    +--- com.android.support:collections:28.0.0
|    |    |    |    \--- com.android.support:support-annotations:28.0.0
|    |    |    +--- android.arch.lifecycle:runtime:1.1.1
|    |    |    |    +--- android.arch.lifecycle:common:1.1.1
|    |    |    |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    |    |    |    +--- android.arch.core:common:1.1.1
|    |    |    |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    |    |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    |    |    \--- com.android.support:versionedparcelable:28.0.0
|    |    |         +--- com.android.support:support-annotations:28.0.0
|    |    |         \--- com.android.support:collections:28.0.0 (*)
|    |    +--- com.android.support:support-core-ui:28.0.0
|    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    +--- com.android.support:support-core-utils:28.0.0
|    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    +--- com.android.support:documentfile:28.0.0
|    |    |    |    |    \--- com.android.support:support-annotations:28.0.0
|    |    |    |    +--- com.android.support:loader:28.0.0
|    |    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    |    +--- android.arch.lifecycle:livedata:1.1.1
|    |    |    |    |    |    +--- android.arch.core:runtime:1.1.1
|    |    |    |    |    |    |    +--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    |    |    |    |    |    |    \--- android.arch.core:common:1.1.1 (*)
|    |    |    |    |    |    +--- android.arch.lifecycle:livedata-core:1.1.1
|    |    |    |    |    |    |    +--- android.arch.lifecycle:common:1.1.1 (*)
|    |    |    |    |    |    |    +--- android.arch.core:common:1.1.1 (*)
|    |    |    |    |    |    |    \--- android.arch.core:runtime:1.1.1 (*)
|    |    |    |    |    |    \--- android.arch.core:common:1.1.1 (*)
|    |    |    |    |    \--- android.arch.lifecycle:viewmodel:1.1.1
|    |    |    |    |         \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    |    |    |    +--- com.android.support:localbroadcastmanager:28.0.0
|    |    |    |    |    \--- com.android.support:support-annotations:28.0.0
|    |    |    |    \--- com.android.support:print:28.0.0
|    |    |    |         \--- com.android.support:support-annotations:28.0.0
|    |    |    +--- com.android.support:customview:28.0.0
|    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    \--- com.android.support:support-compat:28.0.0 (*)
|    |    |    +--- com.android.support:viewpager:28.0.0
|    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    \--- com.android.support:customview:28.0.0 (*)
|    |    |    +--- com.android.support:coordinatorlayout:28.0.0
|    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    \--- com.android.support:customview:28.0.0 (*)
|    |    |    +--- com.android.support:drawerlayout:28.0.0
|    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    \--- com.android.support:customview:28.0.0 (*)
|    |    |    +--- com.android.support:slidingpanelayout:28.0.0
|    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    \--- com.android.support:customview:28.0.0 (*)
|    |    |    +--- com.android.support:interpolator:28.0.0
|    |    |    |    \--- com.android.support:support-annotations:28.0.0
|    |    |    +--- com.android.support:swiperefreshlayout:28.0.0
|    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    \--- com.android.support:interpolator:28.0.0 (*)
|    |    |    +--- com.android.support:asynclayoutinflater:28.0.0
|    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    \--- com.android.support:support-compat:28.0.0 (*)
|    |    |    \--- com.android.support:cursoradapter:28.0.0
|    |    |         \--- com.android.support:support-annotations:28.0.0
|    |    +--- com.android.support:support-core-utils:28.0.0 (*)
|    |    +--- com.android.support:support-annotations:28.0.0
|    |    +--- com.android.support:loader:28.0.0 (*)
|    |    \--- android.arch.lifecycle:viewmodel:1.1.1 (*)
|    \--- android.arch.navigation:navigation-runtime:1.0.0-beta02
|         +--- com.android.support:support-core-utils:28.0.0 (*)
|         \--- android.arch.navigation:navigation-common:1.0.0-beta02
|              \--- com.android.support:support-compat:28.0.0 (*)
+--- androidx.core:core:1.0.1 -> 1.1.0-alpha03 (*)
+--- junit:junit:4.12

添加这个库:

    implementation 'androidx.core:core:1.0.1'

更新:

并检查你的 gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

找到下面的依赖项

com.android.support:support-compat:28.0.0 

并替换为 androidx.appcompat:appcompat:1.0.0

因为 CoreComponentFactory class 在两个依赖项中都可用,这就是为什么它作为重复的冲突 class

androidx.core.app.CoreComponentFactory

android.support.v4.app.CoreComponentFactory