https://kotlinlang.org logo
o

Osman Saral

09/16/2021, 12:25 PM
Hello, I'm getting "Could not identify native targets for platform: 'iphonesimulator' and architectures: '[]'" does anyone know the reason?
s

Stefan Oltmann

09/16/2021, 12:25 PM
Are you on a M1 Mac? 😄
o

Osman Saral

09/16/2021, 12:26 PM
I've added ios targets like below:
Copy code
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
s

Stefan Oltmann

09/16/2021, 12:26 PM
You don't need that "iosTarget" stuff above no more. That's deprecated.
This is my config working on M1 with 1.5.30
Copy code
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. 😄
o

Osman Saral

09/16/2021, 12:51 PM
thank you
but i've taken this snippet from here: https://youtrack.jetbrains.com/issue/KT-47631
are you sure it's depreceted?
s

Stefan Oltmann

09/16/2021, 12:52 PM
Yes.
Old stuff, delete it.
At least I had that section before and now there is no need for that anymore.
o

Osman Saral

09/16/2021, 12:53 PM
Well, kotlin 1.5.30 plugin still generates this code. Can you show me the source of the deprecation?
s

Stefan Oltmann

09/16/2021, 12:54 PM
No. Then keep it if you want it.
o

Osman Saral

09/16/2021, 12:56 PM
I'm sorry if you get me wrong 🙂 i don't want to keep it. I just want to see a documentation
s

Stefan Oltmann

09/16/2021, 12:58 PM
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.
o

Osman Saral

09/16/2021, 1:15 PM
thanks I will try
What confused me was this "hack" is still generated with kotlin 1.5.30 plugin.
s

Stefan Oltmann

09/16/2021, 1:18 PM
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.
o

Osman Saral

09/16/2021, 2:06 PM
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
s

Stefan Oltmann

09/16/2021, 2:07 PM
I forgot 😂
o

Osman Saral

09/16/2021, 2:07 PM
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
s

Stefan Oltmann

09/16/2021, 2:08 PM
I think this causes the problem for you, because this hack builds the arm64 version for you and you exclude it via xcode settings
In that scenario with Intel co-workers it looks like you should go with Intel for simulator
o

Osman Saral

09/16/2021, 2:08 PM
the problem is, the hack activates only one architecture. your code activates more than one, which should be the case I think.
s

Stefan Oltmann

09/16/2021, 2:09 PM
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.
o

Osman Saral

09/16/2021, 2:09 PM
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
s

Stefan Oltmann

09/16/2021, 2:10 PM
It will work if you include iosX64 additionally
o

Osman Saral

09/16/2021, 2:11 PM
Okay I will try that thanks
s

Stefan Oltmann

09/16/2021, 2:11 PM
Copy code
/* 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. 😅
o

Osman Saral

09/16/2021, 8:34 PM
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.ktorktor client ios1.6.3). I've found this issue https://youtrack.jetbrains.com/issue/KTIJ-10769 how did you resolve this?
s

Stefan Oltmann

09/17/2021, 6:16 AM
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
🤯 1
o

Osman Saral

09/17/2021, 9:12 AM
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)
s

Stefan Oltmann

09/17/2021, 9:14 AM
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

09/17/2021, 9:35 AM
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?
s

Stefan Oltmann

09/17/2021, 9:37 AM
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

09/17/2021, 9:44 AM
So when I have this
Copy code
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.
s

Stefan Oltmann

09/17/2021, 9:45 AM
Did you specify the
iosSimulatorArm64Main.dependsOn(this)
stuff?
o

Osman Saral

09/17/2021, 9:46 AM
Same for me @Michal Klimczak
m

Michal Klimczak

09/17/2021, 9:46 AM
yes. narrowed it down even more. When I have the simulator AND
koin
in
commonMain
👍 1
koin probably doesn't support this target yet, too. maybe the source roots get messed up when that happens
s

Stefan Oltmann

09/17/2021, 9:47 AM
Ok, I have no
koin
and doing manual DI there is no problem for me.
Thanks for the warning 😄
👍 1
m

Michal Klimczak

09/17/2021, 12:00 PM
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.
👍 1
s

Stefan Oltmann

09/17/2021, 12:14 PM
I'm annoyed that ktor did not adapt arm64 yet.
2
s

Sebastian Sellmair [JB]

10/06/2021, 10:21 AM
@e5l Would you mind dropping an update on arm64 support here?
❤️ 2
35 Views