Hi! I created a appleMain source set in my build.g...
# multiplatform
f
Hi! I created a appleMain source set in my build.gradle to share common code between Apple platforms for instance iOS and WatchOS. However, it seems Intellij was unable to find the imports and now i can't autocomplete code anymore. 😞 Any idea how i can make this work again? Here is my build.gradle file: https://github.com/felipehjcosta/chat-app/blob/master/common/client/build.gradle
k
Instead of calling source on your targets source set, use dependsOn
f
Are you saying something like this?
Copy code
iosMain {
            dependsOn appleMain
        }

        iosTest {
            dependsOn appleTest
        }

        watchMain {
            dependsOn appleMain
        }

        watchTest {
            dependsOn appleTest
        }
👌 1
Well, it didn't work 😞
Copy code
apply plugin: "kotlin-multiplatform"

version = "0.1.0"
def ios_framework_name = "Client"

kotlin {
    jvm {
        compilations.main.kotlinOptions {
            jvmTarget = "1.8"
        }
    }
    js {
        browser()
    }
    targets {
        final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") ? presets.iosArm64 : presets.iosX64

        fromPreset(iOSTarget, 'ios') {
            binaries {
                framework("$ios_framework_name")
            }
        }

        final def watchTarget = System.getenv('SDK_NAME')?.startsWith("watchos") ? presets.watchosArm64 : presets.watchosX86

        fromPreset(watchTarget, 'watch') {
            binaries {
                framework("$ios_framework_name")
            }
        }
    }

    sourceSets {
        all {
            languageSettings {
                useExperimentalAnnotation 'kotlin.Experimental'
                useExperimentalAnnotation 'kotlinx.serialization.UnstableDefault'
            }
        }
        commonMain {
            dependencies {
                api project(":common:core")
                implementation kotlin('stdlib-common')
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
            }
        }

        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }

        jvmMain {
            dependencies {
                implementation kotlin('stdlib-jdk8')
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
                implementation 'com.squareup.okhttp3:okhttp:4.3.0'
            }
        }

        jvmTest {
            dependencies {
                implementation kotlin('test')
                implementation kotlin('test-junit')
                implementation "junit:junit:$junit_version"
                implementation "io.mockk:mockk:1.9"
                implementation 'com.squareup.okhttp3:mockwebserver:4.3.0'
            }
        }

        jsMain {
            dependencies {
                implementation kotlin('stdlib-js')
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
            }
        }

        jsTest {
            dependencies {
                implementation kotlin('test-js')
                implementation npm("mock-socket", "^9.0.0")
            }
        }

        appleMain {
            dependsOn commonMain
            dependencies {
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
            }
        }

        appleTest {
            dependsOn commonTest
        }

        iosMain {
            dependsOn appleMain
        }

        iosTest {
            dependsOn appleTest
        }

        watchMain {
            dependsOn appleMain
        }

        watchTest {
            dependsOn appleTest
        }
    }
    // Configure all compilations of all targets:
    targets.all {
        compilations.all {
            kotlinOptions {
                allWarningsAsErrors = true
            }
        }
    }
}
IntelliJ can't find the packages
l
You are trying to use HMPP (hierarchical multiplatform projects), which is not ready yet (coming in 1.3.70).
👍 2
f
Oh, I see! Thanks @louiscad!
k
interesting. I have something similar working, but there is a subtle difference
my iosX64 target is named ios, and my shared code is in iosMain. my iosArm64 source set depends on that
so the source I am editing is directly associated with a target