Kotlin multiplatform iOS/Android : Could not find kodein-di-erased.klib
See original GitHub issueI 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:
- Created 4 years ago
- Comments:9 (1 by maintainers)
Top GitHub Comments
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
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?