DEV Community

Discussion on: Maximizing Code Sharing between Android and iOS with Kotlin Multiplatform

 
kuuurt profile image
Kurt Renzo Acosta • Edited

Sorry for the delayed response. With your configuration, you're having two native source sets, ios_x86_64Main and ios_arm64Main. Autocomplete should work for both of those. However, I looked at the repo you linked and it's creating a common source set for both of those so you can code it iniosMain`. I'm afraid there's still an issue with this.

  1. If you are using cocoapods for your native targets, you can do a switching mechanism like they do here

`kotlin

val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
    if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
        ::iosArm64
    else
        ::iosX64

iOSTarget("ios") {
    binaries {
        framework {
            baseName = "SharedCode"
        }
    }
}

`

  1. If you're not using cocoapods, you can enable this flag in your gradle.properties.


kotlin.mpp.enableGranularSourceSetsMetadata=true

Thread Thread
 
haiithust profile image
Lương Công Hải

did it, Thank you so much!