question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kotlin multiplatform iOS/Android : Could not find kodein-di-erased.klib

See original GitHub issue

I tried to use Kodein for my multiplatform library targeting iOS and Android and named SharedCode.

I have this error when I try to compile my library with ./gradlew :SharedCode:build --info

e: java.lang.IllegalStateException: Could not find “/Users/bob/.gradle/caches/modules-2/files-2.1/org.kodein.di/kodein-di-erased-iosx64/6.3.0/dfec9e18526e1ce9862a624fb00e0d448185575a/kodein-di-erased.klib” in [/Users/bob/Documents/myapp/modules, /Users/bob/.konan/klib, /Users/bob/.konan/kotlin-native-macos-1.2.1/klib/common, /Users/bob/.konan/kotlin-native-macos-1.2.1/klib/platform/ios_x64].

kodein version : 6.3.0 gradle version : 5.3.1 enableFeaturePreview(‘GRADLE_METADATA’) is present in settings.gradle

This is my SharedCode lib gradle file (sorry for the length but I prefer to copy the whole thing)

apply plugin: 'kotlinx-serialization'
apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply plugin: "com.squareup.sqldelight"

group = 'com.myapp.multiplatform'
version = '1.0'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 15
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }
}

sqldelight {
    MyApp {
        packageName = "com.myapp.multiplatform"
    }
}

dependencies {
    // Specify Kotlin/JVM stdlib dependency.
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'

    testImplementation 'junit:junit:4.12'
    testImplementation 'org.jetbrains.kotlin:kotlin-test'
    testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'

    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'org.jetbrains.kotlin:kotlin-test'
    androidTestImplementation 'org.jetbrains.kotlin:kotlin-test-junit'

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

kotlin {
    targets {
        final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos")   \
                            ? presets.iosArm64 : presets.iosX64

        fromPreset(iOSTarget, 'ios') {
            binaries {
                framework('SharedCode')
            }
        }

        fromPreset(presets.android, 'android')
    }

    sourceSets {
        all {
            dependencies {
                implementation "org.kodein.di:kodein-di-core:$kodein_version"
                implementation "org.kodein.di:kodein-di-erased:$kodein_version"
            }
        }

        commonMain {
            dependencies {
                //HTTP
                implementation "io.ktor:ktor-client-json:$ktor_json_version"
                implementation "io.ktor:ktor-client-serialization:$ktor_version"
                //Coroutines
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlinx_coroutines_version"
                //Kotlinx serialization
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
                //kclock
                implementation "com.soywiz.korlibs.klock:klock:$klock_version"
            }
        }

        commonTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-common'
                implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'

                api "io.ktor:ktor-client-mock:$ktor_version"
                api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlinx_coroutines_version"
            }
        }

        androidMain {
            dependencies {
                //HTTP
                implementation "io.ktor:ktor-client-json-jvm:$ktor_json_version"
                implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
                //Coroutines
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinx_coroutines_version"
                //Kotlinx serialization
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
                //sqldelight
                implementation "com.squareup.sqldelight:android-driver:$sqldelight_version"
            }
        }

        androidTest {
            dependencies {
                implementation 'junit:junit:4.12'
                implementation 'org.jetbrains.kotlin:kotlin-test'
                implementation 'org.jetbrains.kotlin:kotlin-test-junit'
                api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"

                api "io.ktor:ktor-client-mock-jvm:$ktor_version"
                api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinx_coroutines_version"
            }
        }

        iosMain {
            dependencies {
                //HTTP
                implementation "io.ktor:ktor-client-ios:$ktor_version"
                implementation "io.ktor:ktor-client-json-native:$ktor_json_version"
                implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
                //Coroutines
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$kotlinx_coroutines_version"
                //kotlinx serialization
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
                //sqldelight
                implementation "com.squareup.sqldelight:ios-driver:$sqldelight_version"
            }
        }

        iosTest {
            dependencies {
                api "io.ktor:ktor-client-mock-native:$ktor_version"
                api "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$kotlinx_coroutines_version"
            }
        }
    }
}

task iosTest {
    def device = project.findProperty("iosDevice")?.toString() ?: "iPhone 8"
    dependsOn 'linkTestDebugExecutableIos'
    group = JavaBasePlugin.VERIFICATION_GROUP
    description = "Runs tests for target 'ios' on an iOS simulator"

    doLast {
        def binary = kotlin.targets.ios.binaries.getExecutable('test', 'DEBUG').outputFile
        exec {
            commandLine 'xcrun', 'simctl', 'spawn', device, binary.absolutePath
        }
    }
}

tasks.check.dependsOn iosTest

tasks.withType(Test) {
    testLogging {
        exceptionFormat "full"
        events "passed", "failed"
        showStandardStreams true
    }
}

task packForXCode(type: Sync) {
    final File frameworkDir = new File(buildDir, "xcode-frameworks")
    final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'
    final def framework = kotlin.targets.ios.binaries.getFramework("SharedCode", mode)

    inputs.property "mode", mode
    dependsOn framework.linkTask

    from { framework.outputFile.parentFile }
    into frameworkDir

    doLast {
        new File(frameworkDir, 'gradlew').with {
            text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n"
            setExecutable(true)
        }
    }
}
tasks.build.dependsOn packForXCode

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
romainbslcommented, Sep 24, 2019

Actually no, but its a good idea to provide a compatibility table.

Kotlin 1.3.50 is compatible with release versions, but it’s available in the dev channel as explain here https://github.com/Kodein-Framework/Kodein-DI/issues/243

1reaction
ola-gawell-dctcommented, Jul 3, 2019

Thank you @kuhnroyal! Updating the versions solved my problem. Can you point me to documentation about how to retrieve values from the kodein instance on iOS?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kotlin multiplatform iOS/Android : Could not find kodein-di ...
I tried to use Kodein for my multiplatform library targeting iOS and Android and named SharedCode. I have this error when I try...
Read more >
Kotlin Multiplatform Mobile can't find klib package : KT-51677
Kotlin Multiplatform Mobile can't find klib package. The current error I`m having is: I build on android studio and no problem so far;...
Read more >
Kotlin Multiplatform Mobile can't find klib package
What I wanted to achieve was to compile my C/C++ library into a single Kotlin library and use that single API in both...
Read more >
Kotlin Multiplatform Mobile Can't Find Klib Package - ADocLib
Ask questionsKotlin multiplatform iOS/Android : Could not find kodeindierased.klib. I tried to use Kodein for my multiplatform library targeting iOS and ...
Read more >
Write and deploy a Kotlin library compatible with Android and ...
Learn how to create a Kotlin-Multiplatform library, compatible with Android & iOS.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found