DEV Community

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

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

Hi Kurt!
Thank for this article, I have a question. In the android studio, how can we turn on autocomplete code when writing code inside package iosMain?

Collapse
 
kuuurt profile image
Kurt Renzo Acosta

Hi! Autocomplete works for me out of the box but if you're using libraries from cocoapods then you have to build the project first on Xcode.

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

Currently, I just using the sample project without cocoapods but android studio no turn on code suggestion and autocomplete. Example "dispatch_get_main_queue" and "dispatch_async". is it need another plugin?

Thread Thread
 
kuuurt profile image
Kurt Renzo Acosta

How are you configuring your native targets?

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

this is my config

targets {
    fromPreset(presets.jvm, "jvm")

    fromPreset(presets.iosX64, "ios_x86_64")
    fromPreset(presets.iosArm64, "ios_arm64")
    configure([ios_x86_64, ios_arm64]) {
        compilations.main.outputKinds("FRAMEWORK")
    }
}

I following from github link github.com/adrianbukros/github-mul...

Thread Thread
 
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!