Hi. Someone has experience working with KMM on the...
# multiplatform
m
Hi. Someone has experience working with KMM on the m1/apple silicon/arm macbooks? I can configure the shared module to run on iOS physical devices but it’s broken for simulators
Copy code
Building for iOS Simulator, but linking in dylib built for iOS, file '/Users/.../Shared.framework/Shared' for architecture arm64
1
If i’m not mistaken, the problem is that the simulator on this machines isn’t X64, so this configuration for the
packForXcode
task is not going to work:
Copy code
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
With the previous lines, even the shared iOS sources set doesn’t detect the iOS platform packages. I managed to fix that with something like this:
Copy code
val targetName = "iosArm64"
val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
This also works for iOS devices but not for simulators
☝️ 1
I can live working with physical devices, but I wanted to migrate my UIKit views to SwiftUI and the previews need the simulator to be rendered
s
There isn’t an arm64 simulator target available right now. For the time being I just run the app directly on my M1 machine and it acts like an iPad app. Can you move your SwiftUI views from the app and into a separate framework and have the previews work?
m
That’s a good idea, thanks for the recommendation. Probably is going to require more boilerplate to connect my shared business logic and the Framework with the UI components but it seems the best alternative to have a smooth UI development
Another alternative that I was thinking about is to replace the shared Framework with a fake implementation from Xcode with the correct target for development to create the UI components, then and replace it with the real one in a build phase script
m
There isn’t an arm64 simulator target available right now
@Sam what do you mean by that? I too stumbled upon this issue and I'm trying to work around it. So far: • I can build for arm64 with your help but when i try to install I get some issue https://developer.apple.com/forums/thread/667393 • I was thinking about packing as xcframework but this is a longer journey, I suppose: https://github.com/ge-org/multiplatform-swiftpackage • I'm still not sure about the simulators - do you mean that all the ios simulators are x86_64 based and they won't run at all on m1 mac, or something else related specifically to KMM?
s
When running on an Intel Mac the simulator is X86_64 and the Kotlin compiler can target that. It can’t target the simulator on arm64 at this time. https://kotlinlang.org/docs/reference/native-overview.html#target-platforms I hope that this changes quickly as I really like developing on an M1.
💯 3
m
Thank you guys, this thread has been a lifesaver. One thing that bothers me a bit is that in this message @max.cruz you seem to suggest that the original script didn't work for building for M1 macbook. https://kotlinlang.slack.com/archives/C3PQML5NU/p1610021451138700?thread_ts=1610021434.138600&amp;cid=C3PQML5NU For me, the
System.getenv("SDK_NAME")
returns
iphoneos14.3
when I build on and for my M1 macbook. So the original script works for me (generating
iosArm64
framework).
(also, as a sidenote, generating xcframework might be an interesting option: https://github.com/ge-org/multiplatform-swiftpackage)
s
Just curious to know how the ios app runs on simulator when running through android studio? Error is only on running through Xcode. Is there any workaround or still same? @max.cruz
m
The status is the same but it's in the Kotlin roadmap https://youtrack.jetbrains.com/issue/KT-44321. Basically, you can work with those computers with some workarounds and using a real device https://youtrack.jetbrains.com/issue/KT-43667, anyway I stopped using it because of the Gradle performance; it's really bad for Android, not a real alternative yet.
I think that we need to wait not just for the release of the target in Kotlin Native but also for the release of Gradle, Android Studio, and the OpenJDK (I know that there is the Azul version, but didn't test if it's fully functional). I would not recommend get one of those ones yet if you need to do some Android work
s
I wonder how it runs on simulator through Android studio and not when running through Xcode.
So, I justrealised this problem is only with iOS 14 simulator. It;s working through Xcode on iOS 13 simulator