https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

jean

03/17/2021, 7:43 PM
I followed this article to create a swift package of my shared code : https://johnoreilly.dev/posts/kotlinmultiplatform-swift-package/. I managed to import it through github and I can see the dependency (the swift file, the zip folder and the xcframework). But when I make the
import MyPackage
statement, xcode complains about
no such module 'MyPackage'
. Has anyone encounter this error? Do I need to specify something more than
Copy code
multiplatformSwiftPackage {
    packageName("MyPackage")
    swiftToolsVersion("5.3")
    targetPlatforms {
        iOS { v("13") }
    }
}
in
build.gradle.kts
?
j

John O'Reilly

03/17/2021, 7:46 PM
j

jean

03/17/2021, 7:58 PM
Yep, turned out the name the Module is the one assigned by
Copy code
iOSTarget("ios") {
    binaries {
        framework {
            baseName = "SharedCode"
        }
    }
}
And when I do
import SharedCode
it works. I guess I can just remove the whole fat framework configuration code that was generated when i created the project. Thanks for the hint!
👍 1
j

John O'Reilly

03/17/2021, 8:00 PM
I'll update the article with a link to that issue....probably something others will run in to as well
j

jean

04/06/2021, 10:45 AM
this works all fine as long as I run the app on the simulator for ios, but I get this error when I target a real device :
Copy code
While building for iOS, no library for this platform was found in '/my/path/myProject-grhslbkhqdpygnfqgbgubfvufjyi/SourcePackages/checkouts/myProject-swift-package/myProject.xcframework'.
myProject.xcframework
does indeed only contain
ios-x86_64-simulator
? Am I missing something?
Turned out it’s because I used this to configure ios target
Copy code
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64

    iOSTarget("ios") {
        ...
    }
After replacing it with
ios { ... }
everything works as expected
5 Views