I have an Android App as an Android Studio project and I just installed Android Studio on a new device and tried to run the app in an Android Studio Emulator which was not a problem using the old device. However, in the new device I get the errors:
Duplicate class androidx.navigation.ActivityKt found in modules navigation-runtime-2.4.1-runtime (androidx.navigation:navigation-runtime:2.4.1) and navigation-runtime-ktx-2.3.5-runtime (androidx.navigation:navigation-runtime-ktx:2.3.5)
Duplicate class androidx.navigation.ActivityNavArgsLazyKt found in modules navigation-runtime-2.4.1-runtime (androidx.navigation:navigation-runtime:2.4.1) and navigation-runtime-ktx-2.3.5-runtime (androidx.navigation:navigation-runtime-ktx:2.3.5)
Duplicate class androidx.navigation.ActivityNavArgsLazyKt$navArgs$1 found in modules navigation-runtime-2.4.1-runtime (androidx.navigation:navigation-runtime:2.4.1) and navigation-runtime-ktx-2.3.5-runtime (androidx.navigation:navigation-runtime-ktx:2.3.5)
Duplicate class androidx.navigation.ActivityNavigatorDestinationBuilder found in modules navigation-runtime-2.4.1-runtime (androidx.navigation:navigation-runtime:2.4.1) and navigation-runtime-ktx-2.3.5-runtime (androidx.navigation:navigation-runtime-ktx:2.3.5)
Duplicate class androidx.navigation.ActivityNavigatorDestinationBuilderKt found in modules navigation-runtime-2.4.1-runtime (androidx.navigation:navigation-runtime:2.4.1) and navigation-runtime-ktx-2.3.5-runtime (androidx.navigation:navigation-runtime-ktx:2.3.5)
Duplicate class androidx.navigation.ActivityNavigatorExtrasKt found in modules navigation-runtime-2.4.1-runtime (androidx.navigation:navigation-runtime:2.4.1) and navigation-runtime-ktx-2.3.5-runtime (androidx.navigation:navigation-runtime-ktx:2.3.5)
Duplicate class androidx.navigation.AnimBuilder found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavActionBuilder found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavArgsLazy found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavArgsLazyKt found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavArgumentBuilder found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavControllerKt found in modules navigation-runtime-2.4.1-runtime (androidx.navigation:navigation-runtime:2.4.1) and navigation-runtime-ktx-2.3.5-runtime (androidx.navigation:navigation-runtime-ktx:2.3.5)
Duplicate class androidx.navigation.NavDeepLinkDsl found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavDeepLinkDslBuilder found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavDeepLinkDslBuilderKt found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavDestinationBuilder found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavDestinationDsl found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavGraphBuilder found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavGraphBuilderKt found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavGraphKt found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavGraphViewModelLazyKt found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.NavGraphViewModelLazyKt$navGraphViewModels$1 found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.NavGraphViewModelLazyKt$navGraphViewModels$backStackEntry$2 found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.NavGraphViewModelLazyKt$navGraphViewModels$storeProducer$1 found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.NavHostKt found in modules navigation-runtime-2.4.1-runtime (androidx.navigation:navigation-runtime:2.4.1) and navigation-runtime-ktx-2.3.5-runtime (androidx.navigation:navigation-runtime-ktx:2.3.5)
Duplicate class androidx.navigation.NavOptionsBuilder found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavOptionsBuilderKt found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavOptionsDsl found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.NavigatorProviderKt found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.PopUpToBuilder found in modules navigation-common-2.4.1-runtime (androidx.navigation:navigation-common:2.4.1) and navigation-common-ktx-2.3.5-runtime (androidx.navigation:navigation-common-ktx:2.3.5)
Duplicate class androidx.navigation.ViewKt found in modules navigation-runtime-2.4.1-runtime (androidx.navigation:navigation-runtime:2.4.1) and navigation-runtime-ktx-2.3.5-runtime (androidx.navigation:navigation-runtime-ktx:2.3.5)
Duplicate class androidx.navigation.fragment.DialogFragmentNavigatorDestinationBuilder found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.fragment.DialogFragmentNavigatorDestinationBuilderKt found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.fragment.FragmentKt found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.fragment.FragmentNavArgsLazyKt found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.fragment.FragmentNavArgsLazyKt$navArgs$1 found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.fragment.FragmentNavigatorDestinationBuilder found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.fragment.FragmentNavigatorDestinationBuilderKt found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.fragment.FragmentNavigatorExtrasKt found in modules navigation-fragment-2.4.1-runtime (androidx.navigation:navigation-fragment:2.4.1) and navigation-fragment-ktx-2.3.5-runtime (androidx.navigation:navigation-fragment-ktx:2.3.5)
Duplicate class androidx.navigation.ui.ActivityKt found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Duplicate class androidx.navigation.ui.AppBarConfigurationKt found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Duplicate class androidx.navigation.ui.AppBarConfigurationKt$AppBarConfiguration$1 found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Duplicate class androidx.navigation.ui.AppBarConfigurationKt$AppBarConfiguration$2 found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Duplicate class androidx.navigation.ui.AppBarConfigurationKt$AppBarConfiguration$3 found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Duplicate class androidx.navigation.ui.AppBarConfigurationKt$sam$i$androidx_navigation_ui_AppBarConfiguration_OnNavigateUpListener$0 found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Duplicate class androidx.navigation.ui.BottomNavigationViewKt found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Duplicate class androidx.navigation.ui.CollapsingToolbarLayoutKt found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Duplicate class androidx.navigation.ui.MenuItemKt found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Duplicate class androidx.navigation.ui.NavControllerKt found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Duplicate class androidx.navigation.ui.NavigationViewKt found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Duplicate class androidx.navigation.ui.ToolbarKt found in modules navigation-ui-2.4.1-runtime (androidx.navigation:navigation-ui:2.4.1) and navigation-ui-ktx-2.3.5-runtime (androidx.navigation:navigation-ui-ktx:2.3.5)
Here is my build.grandle file:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
apply plugin: "androidx.navigation.safeargs"
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.game"
minSdkVersion 24
targetSdkVersion 31
versionCode 1
versionName "1.0"
viewBinding {
enabled = true
}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation "androidx.constraintlayout:constraintlayout:2.1.3"
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
}
Do you know what I can do in order to fix this issue and can you tell me why at the new device it is a problem why at the older device it has not been a problem for years?
2
Answers
Remove the last 2 dependencies if you are using kotlin. If you are using java, then remove 5th and 6th dependencies. Sync project, and it should resolve the error.
You have four dependencies on Navigation:
As you’ve stated, you have declared your
$nav_version
asext.nav_version = '2.4.1'
.You can’t mix and match versions of Navigation – they all need to match exactly. Since you already have a variable, your
$nav_version
, just use that for all four dependencies. That way, they will always match exactly: