【问题标题】:Navigation fragment dependencies with JetPack librariesJetPack 库的导航片段依赖项
【发布时间】:2019-02-13 12:44:51
【问题描述】:

我正在使用 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

【问题讨论】:

  • 在你的项目中搜索androidx.core:core:1.1.0,你在某处使用吗?
  • 被其他依赖添加

标签: android android-fragments android-jetpack android-architecture-navigation


【解决方案1】:

添加这个库:

    implementation 'androidx.core:core:1.0.1'

更新

并检查您的 gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

【讨论】:

  • 其他依赖添加
  • 您是否通过添加此库进行检查。
  • 是的,我愿意。但没有任何改变
【解决方案2】:

找到下面的依赖

com.android.support:support-compat:28.0.0 

只替换为androidx.appcompat:appcompat:1.0.0

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

androidx.core.app.CoreComponentFactory

android.support.v4.app.CoreComponentFactory

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 2021-07-14
    • 2019-05-29
    相关资源
    最近更新 更多