1

I'm creating a new project from scratch in Android Studio Flamingo 2022.2.1 Patch 2. As stated in the Android Developer docs for Jetpack Navigation, I've added the dependency:

implementation("androidx.navigation:navigation-compose:2.6.0")

There is no other code or any other added dependencies in the project. I have added no other dependencies. However, despite having done nothing other than add the above dependency I get a "Duplicate Class Error"

Execution failed for task ':app:checkDebugDuplicateClasses'
A failure occurred while executing 
com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable

I'm trying to learn Jetpack Compose and now totally stuck because of this. I've got no idea how to resolve the issue. I've tried doing "invalidate cache and restart". I've also tried checking for updates and updating to the latest version.

UPDATE**

All the duplicate errors are similar to this one:

   > Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)

They all have something to to with "kotlin-stdlib-1.8.20" and "kotlin-stdlib-jdk8-1.7.20".

UPDATE 2** I tried to use dependencyInsight tool but got a JAVA_HOME environmental variable error.

I tried using an older version of Jetpack Navigation and it worked. I then tried creating a new project and it seemed the automatically created dependencies changed and now it works.

Conclusion - Really not sure what was going. Not sure if I should delete this post now.

W Simm
  • 45
  • 6

1 Answers1

0

This problem happened to me as well (as someone learning Jetpack Compose too).

The reason for the problem is having some libraries that not updated to the latest stable version. You only need to make changes to the Gradle file and ensure to sync it after the changes (this will be suggested automatically).

Here is how to fix the problem:

In your gradle file, update all libraries to the newest version. The gradle file can be found in your Project folder structure in the folder called "App".

In there, make sure to update to all the latest versions. As I write this, the latest version for navigation-compose is 2.7.0, so I have:

implementation "androidx.navigation:navigation-compose:2.7.0"

This will lead to the problem you describe if the other libraries are not also updated to the latest version. Hover over the "implementation" lines and click on the suggestions tot update to the latest version, that fixes the problem.