Home > database >  Duplicate class with Amplify and Android Navigation
Duplicate class with Amplify and Android Navigation

Time:05-02

I am trying to use AWS Amplify, and Android Navigation with Safe Args for Java. My project compiles properly, but crashes at runtime. The error indicates that the problem lies in the navigation classes, and playing with the modules I was using I found out that the other module causing the conflict is the one for AWS Amplify. I read on the Official website that I should in this case remove the navigation library since it seems to already be included in the Amplify library. Can I still use the Navigator if I remove the implementation lines in my gradle files? Is there another way to fix this? The objective is just to be able to use both Navigation and Amplify in the same project. Thank you for the help :)

I am using Android Studio Bumblebee 2021.1.1 Patch 3 and my project is for Android 8.1 (Oreo).

My app level build.gradle file is

plugins {
    id 'com.android.application'

    // Safe Args
    id 'androidx.navigation.safeargs'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.myApplication"
        minSdk 27
        targetSdk 31
        versionCode 1
        versionName "0.0.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        // Support for Java 8 features (Amplify)
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    // Navigation
    def nav_version = "2.4.2"
    // Java language implementation
    implementation "androidx.navigation:navigation-ui:$nav_version"
    implementation "androidx.navigation:navigation-fragment:$nav_version"

    // Lottie
    def lottie_version = "5.0.3"
    implementation "com.airbnb.android:lottie:$lottie_version"

    // Amplify core dependency
    def amplify_version = "1.35.3"
    implementation "com.amplifyframework:core:$amplify_version"

    // Support for Java 8 features
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'androidx.navigation:navigation-fragment:2.4.2'
    implementation 'androidx.navigation:navigation-ui:2.4.2'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

Project level build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.1.3' apply false
    id 'com.android.library' version '7.1.3' apply false

    // Safe Args
    id 'androidx.navigation.safeargs' version '2.4.2' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I also added the android.useAndroidX=true and android.enableJetifier=true lines in gradle.properties.

The error:

Duplicate class androidx.navigation.ActivityKt found in modules navigation-runtime-2.4.2-runtime (androidx.navigation:navigation-runtime:2.4.2) and navigation-runtime-ktx-2.3.4-runtime (androidx.navigation:navigation-runtime-ktx:2.3.4)
Duplicate class androidx.navigation.ActivityNavArgsLazyKt found in modules navigation-runtime-2.4.2-runtime (androidx.navigation:navigation-runtime:2.4.2) and navigation-runtime-ktx-2.3.4-runtime (androidx.navigation:navigation-runtime-ktx:2.3.4)
Duplicate class androidx.navigation.ActivityNavArgsLazyKt$navArgs$1 found in modules navigation-runtime-2.4.2-runtime (androidx.navigation:navigation-runtime:2.4.2) and navigation-runtime-ktx-2.3.4-runtime (androidx.navigation:navigation-runtime-ktx:2.3.4)
Duplicate class androidx.navigation.ActivityNavigatorDestinationBuilder found in modules navigation-runtime-2.4.2-runtime (androidx.navigation:navigation-runtime:2.4.2) and navigation-runtime-ktx-2.3.4-runtime (androidx.navigation:navigation-runtime-ktx:2.3.4)
Duplicate class androidx.navigation.ActivityNavigatorDestinationBuilderKt found in modules navigation-runtime-2.4.2-runtime (androidx.navigation:navigation-runtime:2.4.2) and navigation-runtime-ktx-2.3.4-runtime (androidx.navigation:navigation-runtime-ktx:2.3.4)
Duplicate class androidx.navigation.ActivityNavigatorExtrasKt found in modules navigation-runtime-2.4.2-runtime (androidx.navigation:navigation-runtime:2.4.2) and navigation-runtime-ktx-2.3.4-runtime (androidx.navigation:navigation-runtime-ktx:2.3.4)
Duplicate class androidx.navigation.AnimBuilder found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavActionBuilder found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavArgsLazy found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavArgsLazyKt found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavArgumentBuilder found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavControllerKt found in modules navigation-runtime-2.4.2-runtime (androidx.navigation:navigation-runtime:2.4.2) and navigation-runtime-ktx-2.3.4-runtime (androidx.navigation:navigation-runtime-ktx:2.3.4)
Duplicate class androidx.navigation.NavDeepLinkDsl found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavDeepLinkDslBuilder found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavDeepLinkDslBuilderKt found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavDestinationBuilder found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavDestinationDsl found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavGraphBuilder found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavGraphBuilderKt found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavGraphKt found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavGraphViewModelLazyKt found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.NavGraphViewModelLazyKt$navGraphViewModels$1 found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.NavGraphViewModelLazyKt$navGraphViewModels$backStackEntry$2 found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.NavGraphViewModelLazyKt$navGraphViewModels$storeProducer$1 found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.NavHostKt found in modules navigation-runtime-2.4.2-runtime (androidx.navigation:navigation-runtime:2.4.2) and navigation-runtime-ktx-2.3.4-runtime (androidx.navigation:navigation-runtime-ktx:2.3.4)
Duplicate class androidx.navigation.NavOptionsBuilder found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavOptionsBuilderKt found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavOptionsDsl found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.NavigatorProviderKt found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.PopUpToBuilder found in modules navigation-common-2.4.2-runtime (androidx.navigation:navigation-common:2.4.2) and navigation-common-ktx-2.3.4-runtime (androidx.navigation:navigation-common-ktx:2.3.4)
Duplicate class androidx.navigation.ViewKt found in modules navigation-runtime-2.4.2-runtime (androidx.navigation:navigation-runtime:2.4.2) and navigation-runtime-ktx-2.3.4-runtime (androidx.navigation:navigation-runtime-ktx:2.3.4)
Duplicate class androidx.navigation.fragment.DialogFragmentNavigatorDestinationBuilder found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.fragment.DialogFragmentNavigatorDestinationBuilderKt found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.fragment.FragmentKt found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.fragment.FragmentNavArgsLazyKt found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.fragment.FragmentNavArgsLazyKt$navArgs$1 found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.fragment.FragmentNavigatorDestinationBuilder found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.fragment.FragmentNavigatorDestinationBuilderKt found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.fragment.FragmentNavigatorExtrasKt found in modules navigation-fragment-2.4.2-runtime (androidx.navigation:navigation-fragment:2.4.2) and navigation-fragment-ktx-2.3.4-runtime (androidx.navigation:navigation-fragment-ktx:2.3.4)
Duplicate class androidx.navigation.ui.ActivityKt found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)
Duplicate class androidx.navigation.ui.AppBarConfigurationKt found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)
Duplicate class androidx.navigation.ui.AppBarConfigurationKt$AppBarConfiguration$1 found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)
Duplicate class androidx.navigation.ui.AppBarConfigurationKt$AppBarConfiguration$2 found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)
Duplicate class androidx.navigation.ui.AppBarConfigurationKt$AppBarConfiguration$3 found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)
Duplicate class androidx.navigation.ui.AppBarConfigurationKt$sam$i$androidx_navigation_ui_AppBarConfiguration_OnNavigateUpListener$0 found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)
Duplicate class androidx.navigation.ui.BottomNavigationViewKt found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)
Duplicate class androidx.navigation.ui.CollapsingToolbarLayoutKt found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)
Duplicate class androidx.navigation.ui.MenuItemKt found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)
Duplicate class androidx.navigation.ui.NavControllerKt found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)
Duplicate class androidx.navigation.ui.NavigationViewKt found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)
Duplicate class androidx.navigation.ui.ToolbarKt found in modules navigation-ui-2.4.2-runtime (androidx.navigation:navigation-ui:2.4.2) and navigation-ui-ktx-2.3.4-runtime (androidx.navigation:navigation-ui-ktx:2.3.4)

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

CodePudding user response:

You can't mix and match navigation-fragment:2.4.2 (from your dependency) and navigation-fragment-ktx:2.3.4 (from Amplify) - all navigation artifacts need to be the same version.

So just change your dependencies to use the -ktx versions of each artifact, thus ensuring that both the version you specifically depend on and the version pulled in from Amplify are the same.

implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
  • Related