Thread
#multiplatform
    Bailey Pollard

    Bailey Pollard

    1 year ago
    Hey folks, wondering if there is any way to eliminate the need for duplicated code in both iosX64Main/iosArm64Main directories? Tried to find some documentation on this with no luck
    mbonnin

    mbonnin

    1 year ago
    Bailey Pollard

    Bailey Pollard

    1 year ago
    I read that, seems a bit questionable needing to duplicate the same code, just having it build for different archs
    mbonnin

    mbonnin

    1 year ago
    What we're doing is that we're creating a
    apple
    sourceSet and sourcing it from the different targets: https://github.com/apollographql/apollo-android/blob/dev-3.x/build-logic/src/main/kotlin/Mpp.kt#L24
    Arkadii Ivanov

    Arkadii Ivanov

    1 year ago
    The
    ios
    shortcut defines the
    iosMain
    source set, so you can place your iOS code there. It should compile even without HMPP, which just adds IDE support (imports are resolved and not red).
    Bailey Pollard

    Bailey Pollard

    1 year ago
    I should've mentioned this in the original post, I added an external ios framework to my project without the use of cocoapods. I can only import this framework in the iosX64Main/iosArm64Main directories. The import does not compile correctly in the iosMain directory. Is this expected behaviour for external frameworks?
    Big Chungus

    Big Chungus

    1 year ago
    What I usually do is add custom sourceRoot to both sourceSets
    That way it's part (not just a dependency) of both sourceSets
    Bailey Pollard

    Bailey Pollard

    1 year ago
    Any open source examples of this?
    Big Chungus

    Big Chungus

    1 year ago
    kotlin.sourceSets["iosX64Main"].kotlin.srcDir("src/sharedIosMain/kotlin") Do this in gradle for both and place your code there. Or even better yet, just add one's kotlin root to the other's
    Bailey Pollard

    Bailey Pollard

    1 year ago
    Let me try that
    Big Chungus

    Big Chungus

    1 year ago
    Beware that this is a hack, not standard practice
    Bailey Pollard

    Bailey Pollard

    1 year ago
    How does one use code in
    iosMain
    that was declared in
    iosX64Main
    ?
    rnett

    rnett

    1 year ago
    You can't, (well, if you put an
    expect
    in
    iosMain
    and the
    actual
    in each sub-source set you kind of can). The setup with HMPP is you have some "more common" source set like
    iosMain
    that each of the
    iosX64Main
    ,
    iosArm64Main
    , etc depend on. It's essentially the same as a common source set, just only shared between a few modules