'Duplicated class Koin org.koin and io.insert-koin

I'm using two library that have dependencies of two different versions of Koin.

One of the library has org.koin:koin-android:2.0.1 and the other has io.insert-koin:koin-core-jvm:3.0.1 dependencies.

At compile time I got tons of Duplicate class error as below,

Duplicate class org.koin.android.BuildConfig found in modules jetified-koin-android-2.0.1-runtime (org.koin:koin-android:2.0.1) and jetified-koin-android-3.0.1-runtime (io.insert-koin:koin-android:3.0.1)
Duplicate class org.koin.android.ext.koin.KoinExtKt$androidContext$1 found in modules jetified-koin-android-2.0.1-runtime (org.koin:koin-android:2.0.1) and jetified-koin-android-3.0.1-runtime (io.insert-koin:koin-android:3.0.1)
Duplicate class org.koin.core.scope.Scope$injectOrNull$1 found in modules jetified-koin-core-2.0.1 (org.koin:koin-core:2.0.1) and jetified-koin-core-jvm-3.0.1 (io.insert-koin:koin-core-jvm:3.0.1)
Duplicate class org.koin.java.KoinJavaComponent$inject$1 found in modules jetified-koin-core-jvm-3.0.1 (io.insert-koin:koin-core-jvm:3.0.1) and jetified-koin-java-2.0.1 (org.koin:koin-java:2.0.1)
...

When I try to exclude one of them as below,

configurations {
    all { 
        exclude group: "io.insert-koin", module: "koin-android"
        exclude group: "io.insert-koin", module: "koin-core-jvm"
    }
}

I got NoClassDefFoundError at runtime on the relevant one.

When exclude org.koin:koin-android:2.0.1

Caused by: java.lang.ClassNotFoundException: Didn't find class "org.koin.core.KoinComponent" on path: DexPathList[[zip file "/data/app/...

When exclude io.insert-koin:koin-core-jvm:3.0.1

Caused by: java.lang.ClassNotFoundException: Didn't find class "org.koin.core.component.KoinComponent" on path: DexPathList[[zip file "/data/app/...

How can I get to use both libraries?



Solution 1:[1]

Koin 3.x.x has no backwards compatibility. If there is no update on the sdk which uses Koin 2.x.x version, maybe you should better find an older version for the opposite library, which uses Koin 2.x.x. But please be aware Koin version 2.2.3 also has a different path than others (Because of jcenter limitations)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bsoykal