https://kotlinlang.org logo
b

basher

01/22/2019, 7:41 PM
Does anyone here have
@Serializable
working on multiplatform building for iOS? Running into this build error:
Copy code
cannot access 'Serializable': it is internal in '<http://kotlin.io|kotlin.io>'
I've checked the existing GH issues where it appeared people just had import/plugin issues, but I think I'm doing that right: -
apply plugin: 'kotlin-multiplatform'
-
apply plugin: 'kotlinx-serialization'
-
implementation: "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:${versions.serialization}"
-
import kotlinx.serialization.Serializable
Something I'm missing?
k

kgonyon

01/22/2019, 7:49 PM
Are you trying to use
@Serializable
inside common or native source set? I have it working for my multiplatform project which is building for ios.
Copy code
apply plugin: 'com.android.library'
apply plugin: 'kotlin-multiplatform'
apply plugin: 'kotlinx-serialization'
apply plugin: 'maven-publish'
Copy code
iosMain {
            dependencies {
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$kotlin_coroutines_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$kotlin_serialization_version"
            }
        }
I had to make sure I was using gradle 4.7 as well.
b

basher

01/22/2019, 7:57 PM
trying to use it in common
I'm working without gradle metadata though due to SQLDelight and kotlinx libs using different gradle metadata versions
@kgonyon i'm now trying this out in a new mpp sample project (using gradle 4.7 and all that), and i'm doing the same thing as you but getting the same error. What other dependencies do you have setup for your common code?
k

kgonyon

01/22/2019, 8:38 PM
Copy code
commonMain {
            dependencies {
                implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialization_version"
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
                implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
            }
        }
Copy code
kotlin_native_version=1.3.11
kotlin_version=1.3.11
kotlin_serialization_version= 0.9.1
kotlin_coroutines_version=1.1.0
b

basher

01/22/2019, 8:39 PM
ah that was it! i had org.jetbrains.kotlinx:kotlinx-serialization-runtime-common instead of org.jetbrains.kotlinx:kotlinx-serialization-runtime. thanks! this gets me closer to figuring it out in my larger project
k

kgonyon

01/22/2019, 8:41 PM
No problem. Glad I could help some.
d

Drew

01/22/2019, 8:53 PM
@basher I'm also trying to figure out how to do this (except w/ coroutines) when Gradle metadata is disabled (because I need SQLDelight). If you remember, can you let me know when you figure it out?
b

basher

01/22/2019, 8:54 PM
👍 if I figure it out, i'll def update here 🙂
👍 1
Figured it out. For your iOS targets, you need to add
Copy code
impelementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native_debug_ios_arm64:${versions.serialization}"`
impelementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native_release_ios_arm64:${versions.serialization}"`
use those instead of just plain
-native
and then you do the same for sim but
-iosx64
d

Drew

01/22/2019, 10:04 PM
@basher nice. It seemed to be working--until I changed some dependencies around (or did a clean build, or something) and then started getting some weird error. ..
Copy code
exception: java.lang.IllegalStateException: Could not find "/Users/.../.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-serialization-runtime-native_debug_ios_arm64/0.9.1/b0a5a1202ec09423abf641fd47393aade3172064/kotlinx-serialization-runtime-native_debug_ios_arm64-0.9.1.klib" in [/Users/.../Projects/HelloKotlinMPP, /Users/.../.konan/klib, /Users/.../.konan/kotlin-native-macos-1.0.3/klib/common, /Users/.../.konan/kotlin-native-macos-1.0.3/klib/platform/ios_x64].
j

Jonas Bark

01/22/2019, 10:08 PM
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
works fine for me for iOS targets
1
d

Drew

01/22/2019, 10:10 PM
@Jonas Bark even without having enabled Gradle metadata?
b

basher

01/22/2019, 10:26 PM
@Drew hm not sure about that sorry
d

Drew

01/22/2019, 10:26 PM
Yeah, no worries. I’ll figure it out! MPP seems so tricky right now with all the dependency management
a

Ashley Figueira

01/22/2019, 10:43 PM
@Drew indeed.
d

Drew

01/22/2019, 10:45 PM
I really want to dive in and create some cool stuff--but it’ll only be useful / beneficial in my org w/ stuff working decently on iOS… and it seems like iOS/native is just not there for dependency management and coroutines (in my experience anyway). Guess I can learn enough to contribute a fix back to the repos though
6 Views