https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
t

Thomas Skovsgaard

11/23/2023, 10:15 AM
Hey I'm trying to add Okio to my js-node KMP project as described here https://square.github.io/okio/multiplatform/, but Android studio can't resolve node filesystem
Failed to resolve: com.squareup.okio:okio-nodefilesystem:3.6.0
I have no problem with the core
com.squareup.okio:okio:3.6.0
Instead of
Copy code
js {
            dependencies {
                implementation(libs.okio.nodefilesystem)
            }
            binaries.executable()
            nodejs {
                generateTypeScriptDefinitions()
            }
        }
I need to do
Copy code
js {
            jsMain.dependencies {
                implementation(libs.okio.nodefilesystem)
            }
            binaries.executable()
            nodejs {
                generateTypeScriptDefinitions()
            }
        }
👍 1
j

jw

11/23/2023, 12:47 PM
The dependencies should be declared in sourceSets, not as part of the target
Your first snippet does not match what's on the website
t

Thomas Skovsgaard

11/23/2023, 12:49 PM
The snippet was only for the JS target, this is the sourcesets from my build.gradle.kts file 🙂
Copy code
sourceSets {
        commonMain.dependencies {
            implementation(libs.ktor.client.core)
            implementation(libs.kotlinx.coroutines.core)
            implementation(libs.okio)
        }

        androidMain.dependencies {
            implementation(libs.ktor.client.okhttp)
            implementation(libs.kotlinx.coroutines.android)

        }

        iosMain.dependencies {
            implementation(libs.ktor.client.darwin)
        }

        js {
            jsMain.dependencies {
                implementation(libs.okio.nodefilesystem)
            }
            binaries.executable()
            nodejs {
                generateTypeScriptDefinitions()
            }
        }

        commonTest.dependencies {
            implementation(libs.kotlin.test)
        }
    }
j

jw

11/23/2023, 12:53 PM
You are mixing the target declaration with the sourceSet configuration
The js { } block should be at the same level of sourceSets { }
But jsMain belongs within sourceSets
t

Thomas Skovsgaard

11/23/2023, 12:55 PM
Arh I see, so in this way
Copy code
sourceSets {
        commonMain.dependencies {
            implementation(libs.ktor.client.core)
            implementation(libs.kotlinx.coroutines.core)
            implementation(libs.okio)
        }

        androidMain.dependencies {
            implementation(libs.ktor.client.okhttp)
            implementation(libs.kotlinx.coroutines.android)

        }

        iosMain.dependencies {
            implementation(libs.ktor.client.darwin)
        }
        jsMain.dependencies {
            implementation(libs.okio.nodefilesystem)
        }
        
        commonTest.dependencies {
            implementation(libs.kotlin.test)
        }
    }

    js {

        binaries.executable()
        nodejs {
            generateTypeScriptDefinitions()
        }
    }
j

jw

11/23/2023, 12:56 PM
Yep!
t

Thomas Skovsgaard

11/23/2023, 12:57 PM
It is funny though, the other thing actually worked, I got generated the typescript definitions and the code to save to filesystem works from my node application 🤷
5 Views