Thread
#multiplatform
    Osman Saral

    Osman Saral

    1 year ago
    Hello, I'm getting "Could not identify native targets for platform: 'iphonesimulator' and architectures: '[]'" does anyone know the reason?
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    Are you on a M1 Mac? 😄
    Osman Saral

    Osman Saral

    1 year ago
    I've added ios targets like below:
    val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
            when {
                System.getenv("SDK_NAME")?.startsWith("iphoneos") == true -> ::iosArm64
                System.getenv("NATIVE_ARCH")?.startsWith("arm") == true -> ::iosSimulatorArm64
                else -> ::iosX64
            }
    
        val xcf = XCFramework()
        iosTarget("ios") {
            binaries.framework {
                baseName = "KMM"
                xcf.add(this)
            }
        }
    yes 😄
    I'm using kotlin 1.5.30
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    You don't need that "iosTarget" stuff above no more. That's deprecated.
    This is my config working on M1 with 1.5.30
    val xcf = XCFramework()
    
    /* App Store */
    iosArm64 {
        binaries.framework {
            baseName = "shared"
            embedBitcode("bitcode")
            xcf.add(this)
        }
    }
    
    /* iOS Simulator M1 */
    iosSimulatorArm64 {
        binaries.framework {
            baseName = "shared"
            xcf.add(this)
        }
    }
    
    /* Apple Silicon macOS Devices */
    macosArm64 {
        binaries.framework {
            baseName = "shared"
            xcf.add(this)
        }
    }
    
    val commonMain by sourceSets.getting {
    
        sourceSets["commonMain"].kotlin.srcDir(file("build/generated/source/commonMain/"))
    
        dependencies {
    
            // ...
        }
    }
    val commonTest by sourceSets.getting {
        dependencies {
            // ...
        }
    }
    
    val iosArm64Main by sourceSets.getting
    val iosArm64Test by sourceSets.getting
    
    val iosSimulatorArm64Main by sourceSets.getting
    val iosSimulatorArm64Test by sourceSets.getting
    
    val macosArm64Main by sourceSets.getting
    val macosArm64Test by sourceSets.getting
    
    val appleMain by sourceSets.creating {
    
        iosArm64Main.dependsOn(this)
        iosSimulatorArm64Main.dependsOn(this)
    
        macosArm64Main.dependsOn(this)
    
        dependencies {
    
            // ...
        }
    }
    val appleTest by sourceSets.creating {
    
        iosArm64Test.dependsOn(this)
        iosSimulatorArm64Test.dependsOn(this)
    
        macosArm64Test.dependsOn(this)
    }
    Also had some help from the friendly people around here to come up with that. So I'm happy to share it. 😄
    Osman Saral

    Osman Saral

    1 year ago
    thank you
    but i've taken this snippet from here:https://youtrack.jetbrains.com/issue/KT-47631
    are you sure it's depreceted?
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    Yes.
    Old stuff, delete it.
    At least I had that section before and now there is no need for that anymore.
    Osman Saral

    Osman Saral

    1 year ago
    Well, kotlin 1.5.30 plugin still generates this code. Can you show me the source of the deprecation?
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    No. Then keep it if you want it.
    Osman Saral

    Osman Saral

    1 year ago
    I'm sorry if you get me wrong 🙂 i don't want to keep it. I just want to see a documentation
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    Ok... You have an M1, right? Why do you want to build iosX64 for your simulator?
    And if you want it, why decide upon an hack and not include both architectures? That's now possible with 1.5.30 You don't need any hack for that.
    Your error message comes from the fact that your M1 simulator wants arm64, but you include only iosX64 because of that hack that doesn't work correctly. The easiest solution for M1 Mac is to build iosSimulatorArm64 Study my code above. That's what will work for you - without any hacks.
    Osman Saral

    Osman Saral

    1 year ago
    thanks I will try
    What confused me was this "hack" is still generated with kotlin 1.5.30 plugin.
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    That's because not everyone has an M1 Mac. That code is generic and falls back to Intel if you work on an Intel Mac.
    But since we both have M1 we don't need to worry about hacks to make it work on Intel. Or do you have coworkers on the same project with Intel Macs?
    In that case you can leave your gradle as is and add "arm64" to the excluded architectures for "iOS simulator debug". Then your error message will go away, but you will use the simulator with Rosetta.
    That's what I needed to do before Kotlin 1.5.30
    And that's why I call it "deprecated" because you can go fully native now.
    I hope that helped you out.
    Osman Saral

    Osman Saral

    1 year ago
    well did you know I also gave you that excluded architectures tip before 😂 https://kotlinlang.slack.com/archives/C3PQML5NU/p1624966879002300?thread_ts=1624532429.384300&cid=C3PQML5NU
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    I forgot 😂
    Osman Saral

    Osman Saral

    1 year ago
    I'm glad it worked for you
    yes I have coworkers who has intel macs. This settings are already set.
    but i still get this error
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    I think this causes the problem for you, because this hack builds the arm64 version for you and you exclude it via xcode settings
    Osman Saral

    Osman Saral

    1 year ago
    the problem is, the hack activates only one architecture. your code activates more than one, which should be the case I think.
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    In that scenario with Intel co-workers it looks like you should go with Intel for simulator
    Yes, you can add both architectures in your case
    I tried that and it works. I removed it since I don't need it, but it's possible.
    Osman Saral

    Osman Saral

    1 year ago
    That scenario worked for me before 1.5.30 too. probably your gradle setup will work too. But I'm not sure it will work form my intel coworkers
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    It will work if you include iosX64 additionally
    Osman Saral

    Osman Saral

    1 year ago
    Okay I will try that thanks
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    /* iOS Simulator Intel */
    iosX64 {
        binaries.framework {
            baseName = "shared"
            xcf.add(this)
        }
    }
    So in your case with excluded architectures it's the typical story how a hack/workaround today will turn into a bug tomorrow 😄 You just need to forget about that you changed months ago some small thing. Gladly with upcoming 1.5.30 I remembered that setting. 😅
    Osman Saral

    Osman Saral

    1 year ago
    hello stefan sorry to bother again. I've tried your solution and also added the
    appleMain
    source sets etc. did you get this error too: Failed building KotlinMPPGradleModel org.gradle.internal.resolve.ArtifactNotFoundException: Could not find ktor-client-ios-1.6.3-samplessources.jar (io.ktor:ktor-client-ios:1.6.3). I've found this issue https://youtrack.jetbrains.com/issue/KTIJ-10769 how did you resolve this?
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    Ktor is not adapted for M1 yet. At this moment I don't use it. If you need that framework you have to go with Intel for now. See the open issue: https://youtrack.jetbrains.com/issue/KTOR-3144 But the structure in my build.gradle.kts is better and more flexible nontheless. So you can comment out the iosSimulatorArm64() and wait for Ktor. Like this: https://github.com/Kotlin/kmm-production-sample/blob/master/shared/build.gradle.kts
    Osman Saral

    Osman Saral

    1 year ago
    thank you for the detailed answer. the error message was really misleading. I did what you suggested and it works. (It was already working before, I really didn't understand what silicon support brought to the table. I can't even use it. thanks anyway)
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    You are welcome. 🙂 And you will be able to use it as soon as the rest of your team discards the old shitty Intel MacBooks and upgrade to shiny M1 😄
    m

    Michal Klimczak

    1 year ago
    did you guys have a problem that after you tried this hmpp stuff, IDE stopped recognising sourceSets? I can see this in the snippet
    sourceSets["commonMain"].kotlin.srcDir(file("build/generated/source/commonMain/"))
    - does it mean that we need to manually declare the source sets now?
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    No, I should have removed that line. I generate additional Kotlin files there and this is why I need to add it. You don't need that.
    m

    Michal Klimczak

    1 year ago
    So when I have this
    iosSimulatorArm64 {
            binaries.framework {
                baseName = "shared"
                xcf.add(this)
            }
        }
    the source roots get messed up. But when I get rid of it, they are fine again.
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    Did you specify the
    iosSimulatorArm64Main.dependsOn(this)
    stuff?
    Osman Saral

    Osman Saral

    1 year ago
    Same for me @Michal Klimczak
    m

    Michal Klimczak

    1 year ago
    yes. narrowed it down even more. When I have the simulator AND
    koin
    in
    commonMain
    koin probably doesn't support this target yet, too. maybe the source roots get messed up when that happens
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    Ok, I have no
    koin
    and doing manual DI there is no problem for me.
    Thanks for the warning 😄
    m

    Michal Klimczak

    1 year ago
    I had a chance to have a quick chat with @Sebastian Sellmair [JB] about this. When you hit gradle sync it now presents a weird warning about lack of
    samplesourcesjar
    and indeed it did for my koin example (I completely missed that). The fix is going to be to show an error message which will precisely explain the issue along with telling you which libs are at fault. You can track it here: https://youtrack.jetbrains.com/issue/KTIJ-10769 As far as I understood, it depends on IDE, not just kotlin plugin, so Android Studio users will have to wait a bit for a proper fix.
    Stefan Oltmann

    Stefan Oltmann

    1 year ago
    I'm annoyed that ktor did not adapt arm64 yet.
    Sebastian Sellmair [JB]

    Sebastian Sellmair [JB]

    11 months ago
    @e5l Would you mind dropping an update on arm64 support here?