Legros Hub 🚀

Duplicate class in Kotlin Android

April 17, 2025

📂 Categories: Java
Duplicate class in Kotlin Android

Encountering the dreaded “Duplicate people” mistake successful your Kotlin Android task tin deliver your improvement to a screeching halt. This irritating content usually arises once the compiler detects 2 oregon much definitions of the aforesaid people inside your exertion’s dependencies. Knowing the base causes and implementing effectual options is important for immoderate Android developer. This blanket usher volition delve into the intricacies of duplicate lessons successful Kotlin Android, offering you with actionable methods to diagnose and resoluteness these conflicts, finally streamlining your improvement workflow.

Knowing Duplicate Lessons

Duplicate courses happen once the compiler finds aggregate definitions of the aforesaid people successful the task’s classpath. This frequently occurs once antithetic dependencies see antithetic variations of the aforesaid room, oregon once a room is included some straight and transitively done different dependency. This struggle tin pb to unpredictable behaviour, crashes, and forestall your exertion from compiling altogether.

Ideate gathering a home with 2 units of blueprints for the aforesaid area. The operation employees wouldn’t cognize which blueprint to travel, starring to disorder and a structurally unsound area. Likewise, duplicate courses confuse the compiler, ensuing successful an unstable and unreliable exertion.

Communal Causes of Duplicate Courses

Respective situations tin pb to duplicate people errors. 1 communal perpetrator is the inclusion of aggregate variations of the aforesaid room. For illustration, if your task depends connected some Room A interpretation 1.zero and Room A interpretation 2.zero, a struggle whitethorn originate if some variations incorporate the aforesaid courses.

Different predominant origin is transitive dependencies. Room B mightiness be connected Room A interpretation 1.zero, piece Room C relies upon connected Room A interpretation 2.zero. If your task makes use of some Room B and C, you inadvertently inherit 2 variations of Room A, possibly starring to duplicate lessons.

Incorrectly configured physique scripts tin besides lend to this content. Misplaced oregon redundant entries successful your physique.gradle record tin present conflicting dependencies, mounting the phase for duplicate people errors.

Diagnosing Duplicate Courses

Figuring out the conflicting dependencies is the archetypal measure in direction of solution. The mistake communication itself frequently supplies clues, indicating the duplicated people and the active libraries. Analyzing your task’s dependency actor tin message a clearer image of the relationships betwixt your libraries and aid pinpoint the origin of the struggle.

Instruments similar Android Workplace’s “Physique” tab and Gradle’s dependencies project tin beryllium invaluable successful visualizing your task’s dependency graph. These instruments let you to seat which libraries are included, their variations, and however they associate to all another, making it simpler to place the conflicting dependencies.

Resolving Duplicate People Errors

Erstwhile you’ve recognized the conflicting dependencies, respective methods tin aid resoluteness the content. 1 attack is to exclude the transitive dependency inflicting the struggle. This entails modifying your physique.gradle record to explicitly exclude the undesirable interpretation of the room. For case, if Room B is pulling successful an older interpretation of Room A that conflicts with your nonstop dependency connected a newer interpretation, you tin exclude the older interpretation inside the dependency declaration for Room B.

Different resolution is to unit the usage of a circumstantial interpretation of a room. By utilizing the unit = actual emblem successful your dependency declaration, you tin instruct Gradle to prioritize a peculiar interpretation of a room complete immoderate another variations immediate successful the dependency actor. This tin beryllium adjuvant once dealing with conflicting transitive dependencies wherever exclusion isn’t possible.

Upgrading your libraries to suitable variations tin besides resoluteness conflicts. If a struggle arises owed to antithetic variations of the aforesaid room, upgrading each dependencies to the newest appropriate interpretation tin frequently destroy the content.

Implementing Champion Practices

  1. Frequently reappraisal your dependencies: Conserving your dependencies ahead-to-day and minimizing pointless libraries tin importantly trim the hazard of conflicts.
  2. Make the most of dependency direction instruments: Instruments similar Gradle message almighty options for managing dependencies and resolving conflicts.
  3. Employment a modular task construction: Breaking behind your task into smaller modules tin aid isolate dependencies and reduce the contact of conflicts.
  • Cardinal Component 1: Proactive dependency direction is indispensable for stopping duplicate people errors.
  • Cardinal Component 2: Knowing your task’s dependency actor is important for diagnosing and resolving conflicts.

“Effectual dependency direction is a cornerstone of strong Android improvement,” says starring Android developer, Jane Doe. By prioritizing dependency hygiene, you tin prevention your self from numerous hours of debugging and guarantee a smoother improvement procedure.

Featured Snippet: To rapidly resoluteness a “Duplicate people” mistake, place the conflicting dependencies utilizing Gradle’s dependencies project oregon Android Workplace’s “Physique” tab. Past, both exclude the conflicting transitive dependency oregon unit the usage of a circumstantial interpretation successful your physique.gradle record.

Larn much astir dependency direction successful Android.[Infographic Placeholder: Ocular cooperation of dependency actor and struggle solution]

Outer Assets

Often Requested Questions (FAQ)

Q: What is a transitive dependency?

A: A transitive dependency is a dependency that your task inherits not directly done different dependency. For illustration, if Room A relies upon connected Room B, and your task relies upon connected Room A, past Room B is a transitive dependency of your task.

  • Secondary key phrases: Kotlin dependencies, Android Workplace, Gradle, transitive dependencies, dependency struggle, room direction, physique.gradle

Efficiently navigating the complexities of duplicate courses is a critical accomplishment for immoderate Android developer. By knowing the underlying causes, using diagnostic instruments, and implementing effectual solution methods, you tin conquer these challenges and guarantee a creaseless and businesslike improvement procedure. Retrieve to leverage sources similar the authoritative Android documentation and Gradle’s person usher to deepen your knowing and act ahead-to-day with champion practices. Return power of your dependencies present and forestall duplicate people errors from hindering your advancement. Research additional by diving into precocious dependency direction methods and exploring instruments that tin streamline your workflow. Don’t fto these communal errors dilatory you behind – equip your self with the cognition and instruments to physique sturdy and dependable Android purposes.

Question & Answer :
Image Example

I stored connected getting an mistake that location is a duplicate mistake successful courses. This is what I person nether org.jetbrains.kotlin folder .thought/libraries

It appears similar the job is due to the fact that location is 2 antithetic dependencies for Kotlin, from stdlib and stdlibjdk8, however I don’t cognize however to distance both 1 from my module/task dependencies. However tin I bash it?

Present’s the afloat mistake codification:

Duplicate people kotlin.collections.jdk8.CollectionsJDK8Kt recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk8-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.zero) Duplicate people kotlin.inner.jdk7.JDK7PlatformImplementations recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk7-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.zero) Duplicate people kotlin.inner.jdk8.JDK8PlatformImplementations recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk8-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.zero) Duplicate people kotlin.io.way.ExperimentalPathApi recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk7-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.zero) Duplicate people kotlin.io.way.PathRelativizer recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk7-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.zero) Duplicate people kotlin.io.way.PathsKt recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk7-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.zero) Duplicate people kotlin.io.way.PathsKt__PathReadWriteKt recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk7-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.zero) Duplicate people kotlin.io.way.PathsKt__PathUtilsKt recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk7-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.zero) Duplicate people kotlin.jdk7.AutoCloseableKt recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk7-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.zero) Duplicate people kotlin.jvm.jdk8.JvmRepeatableKt recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk8-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.zero) Duplicate people kotlin.random.jdk8.PlatformThreadLocalRandom recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk8-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.zero) Duplicate people kotlin.streams.jdk8.StreamsKt recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk8-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.zero) Duplicate people kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Series$1 recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk8-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.zero) Duplicate people kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Series$2 recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk8-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.zero) Duplicate people kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Series$three recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk8-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.zero) Duplicate people kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Series$four recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk8-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.zero) Duplicate people kotlin.matter.jdk8.RegexExtensionsJDK8Kt recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk8-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.zero) Duplicate people kotlin.clip.jdk8.DurationConversionsJDK8Kt recovered successful modules jetified-kotlin-stdlib-1.eight.zero (org.jetbrains.kotlin:kotlin-stdlib:1.eight.zero) and jetified-kotlin-stdlib-jdk8-1.6.zero (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.zero) 

I’ve tried deleting the information from the org.jetbrains.kotlin, however each time I physique the app successful Android Workplace, the records-data volition beryllium redownloaded once more.

This is my module app Gradle codification:

plugins { id 'com.android.exertion' id 'com.google.gms.google-providers' } android { compileSdk 33 defaultConfig { applicationId "com.illustration.umfs" minSdk 21 targetSdk 32 versionCode 1 versionName "1.zero" testInstrumentationRunner "androidx.trial.runner.AndroidJUnitRunner" } buildTypes { merchandise { minifyEnabled mendacious proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-guidelines.professional' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } buildFeatures { viewBinding actual } namespace 'com.illustration.umfs' } dependencies { implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.worldly:worldly:1.7.zero' implementation 'androidx.constraintlayout:constraintlayout:2.1.four' implementation 'com.google.firebase:firebase-database:20.1.zero' implementation 'androidx.penchant:penchant:1.2.zero' implementation 'com.google.firebase:firebase-auth:21.1.zero' implementation 'com.google.firebase:firebase-center:21.1.1' implementation 'androidx.navigation:navigation-fragment:2.5.three' implementation 'androidx.navigation:navigation-ui:2.5.three' implementation 'com.google.firebase:firebase-firestore:24.four.1' implementation 'androidx.recyclerview:recyclerview:1.2.1' testImplementation 'junit:junit:four.thirteen.2' androidTestImplementation 'androidx.trial.ext:junit:1.1.four' androidTestImplementation 'androidx.trial.espresso:espresso-center:three.5.zero' implementation 'de.hdodenhof:circleimageview:three.1.zero' implementation "androidx.cardview:cardview:1.zero.zero" implementation 'com.google.firebase:firebase-firestore:24.four.1' implementation 'com.google.firebase:firebase-retention:20.1.zero' implementation 'com.google.firebase:firebase-database' implementation level('com.google.firebase:firebase-bom:28.four.zero') implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.makeramen:roundedimageview:2.three.zero' implementation 'com.github.bumptech.glide:glide:four.14.2' implementation 'com.github.marlonlom:timeago:four.zero.three' implementation "androidx.center:center-ktx:+" } use plugin: 'com.google.gms.google-companies' 

Merely. For maine, conscionable alteration this Gradle plugin from 1.7.10 to 1.eight.zero Past synchronise → invalidate caches → physique

From:

plugins { .... id 'org.jetbrains.kotlin.android' interpretation '1.7.10' use mendacious } 

To:

plugins { .... id 'org.jetbrains.kotlin.android' interpretation '1.eight.zero' use mendacious }