I don't really understand how to read / write file...
# multiplatform
m
I don't really understand how to read / write files in okio 3 multiplatform (specifically on ios). All examples show how to do it using
FileSystem.SYSTEM
which is only available on `jvm` . It's like everything is there when you have
FileHandle
or
Sink
, but the first step is vague. Any hints?
m
FileSystem.SYSTEM
is also available for native
It's not for JS because there's no filesystem on the browser but there is
NodeJsFileSystem
in a separate artifact
So you can use
expect
/`actual`
m
hmm, in my
iosMain
source set I only have
FileSystem.SYSTEM_TEMPORARY_DIRECTORY
under
FileSystem.Companion
.
iosMain.dependsOn(commonMain)
and commonMain has
implementation("com.squareup.okio:okio:3.0.0")
maybe I have messed up my source sets some other way 🤔
but you are right, it's there
m
m
I'm starting to think it's more of an IDE issue. I added the dependency directly to
iosMain
source set and it shows up red, but then when I navigate to the
FileSystem
class the
SYSTEM
is there.
yeah, it builds just fine. @Sebastian Sellmair [JB] you might be interested in this. This dependency from okio
nativeMain
sourceset is resolved properly by build system, but my
iosMain
source set doesn't see it in Android Studio (regardles of if I add the dependency to
iosMain
or
commonMain
).
Copy code
val iosMain by creating {
            dependsOn(commonMain)
            iosArm64Main.dependsOn(this)
            iosX64Main.dependsOn(this)
            ...
            dependencies {
                implementation("com.squareup.okio:okio:3.0.0")
                ...
            }
        }
and
Copy code
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
s
Hey! Thanks for pinging me. Without looking into further details here, it seems that issues like this are expected. OKIO does not publish in a hierarchical multiplatform compatible way and so tooling will not be able to distinguish symbols that are in “intermediate” source sets (like iosMain) from others. So you can only use ‘commonMain’ APIs in iosMain or ios{Arch}Main apis in your ios{Arch}Main. The Kotlin Multiplatform team tried to help migrating OKIO to hmpp, however we can’t report significant progress there from our side. Obviously, OKIO is still very close to our heart (Kotlin Multiplatform Team) and we’re monitoring OKIO and have branches on our hands with hmpp support. In the end, this is square’s decision to migrate and there might be good reasons for them postponing it?
👀 1
m
Thanks for taking time to respond! In the meantime I found your PR in okio. Asked on #squarelibraries, maybe there are some plans
any workarounds maybe? I tried some random things like creating a matching
nativeMain
source sets but it doesn't help
s
There would be some workarounds I can think of, however those are rather complicated. Is it feasible for you to expect/actual around that issue for now?
m
I don't think expect/actual would help here, but it's not really that important, it builds, I can just work it out without code completion etc, so no need for big workarounds here. I wonder though, the
SYSTEM
is not present in
commonMain
, nor it's an `expect/actual` static field. It's just something that is declared in the
actual companion object FileSystem
both in
jvmMain
and
nativeMain
. So why does my AS pick up the jvm variable and doesn't do it for native? I guess it has something to do with the fact that
androidMain
is already provided and I obtain the source set
by getting
, whereas
iosMain
is
by creating
?
s
In short: jvmMain and androidMain are “platform source sets”. Like iosArm64Main commonMain and platform source sets will be provided with symbols to analise against. Intermediate source sets have more complicated platform attributes, since them are shared across multiple platforms.
Your intuitions are all correct in the “hmpp” world, the issue is just that OKIO does not publish in this mode. You either get commonMain, or platforms thats it. Tooling will not be provided with more ganularity!
m
Makes sense, thank you :)
919 Views