For a KMP project that just targets android and jv...
# multiplatform
s
For a KMP project that just targets android and jvm, is it possible to get Android Studio/IntelliJ to not mark Java-specific stuff as an error?
x
you shouldn't reference java specific stuff in
commonMain
anyways.
commonMain
is only for pure-kotlin (jvm-free)
if you really really want to, you can use typealiases for it
Copy code
//commonMain
expect class Random

//jvmMain
actual typealias Random = java.util.Random

//androidMain
actual typealias Random = java.util.Random
keep in mind, that jvm and android are two different targets and the
Random
above may not be the same
s
Thanks, trying that.
Specifically I'm trying to use File. So if I want to use any methods or Kotlin extensions, I guess I need to make expect/actual declarations for those too.
e
as a workaround to lighten the workload a bit: if you create a separate KMP module with only a JVM target, you can declare the
actual
only once. then using that a
commonMain
dependency in your JVM+Android project, you'll have the same actual in both
s
Thanks guys. Not the answer I was hoping for, but I appreciate the help. Did someone make a KMP file library to make my life easier?
e
okio filesystem supports KMP https://square.github.io/okio/file_system/
s
Looks better than whatever I'd do. .. and with testing! Thanks!