swift-klib-plugin: Getting invalid swift manifest and wrong target when building for iOS
Hello, we’ve run into a curious issue, while trying to use your plugin in our KPM project.
Steps to reproduce:
- Add the plugin + expose swift class to a KPM project
- Build it from Xcode
15.4or15.3. - You will get an
invalid swift manifesterror as it builds from MacOS, even though the target is set to build for iPhone Simulator.
> Task :ourProject:swiftklibKCryptoIosSimulatorArm64
'swiftbuild': Invalid manifest (compiled with: ["/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", "-vfsoverlay", "/var/folders/xg/9cxqrskx3zq5503j26vb1fn00000gn/T/TemporaryDirectory.EDusGx/vfs.yaml", "-L", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-lPackageDescription", "-Xlinker", "-rpath", "-Xlinker", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-target", "arm64-apple-macosx13.0", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.5.sdk", "-F", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks", "-I", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-L", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-swift-version", "5", "-I", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.5.sdk", "-package-description-version", "5.5.0", "/Users/username/outproject-mobile/outproject/build/swiftklib/KCrypto/iosSimulatorArm64/swiftBuild/Package.swift", "-Xfrontend", "-disable-implicit-concurrency-module-import", "-Xfrontend", "-disable-implicit-string-processing-module-import", "-o", "/var/folders/xg/9cxqrskx3zq5503j26vb1fn00000gn/T/TemporaryDirectory.h3z7Ne/swiftbuild-manifest"])
fatalError
/Users/username/ivy-mobile/iOS/<unknown>:1:1: using sysroot for 'iPhoneSimulator' but targeting 'MacOSX'
Hypothesis: Xcode executes task :ivy:embedAndSignAppleFrameworkForXcode, that build all the Kotlin files, and triggers :ivy:swiftklibKCryptoIosSimulatorArm64, however environment variables containing the build target are not passed or misinterpreted by the swiftklibKCryptoIosSimulatorArm64 task, therefore, when is executed from the Xcode, it builds for MacOS target, which is rejected in next step, as the rest of the project is for iPhone Simulator.
We also observe the same behavior when building for iOS generic devices (e.g., production build).
Strange workaround in Android Studio:
Doing Gradle Sync in Android Studio performs these tasks:
> Task :ivy:swiftklibKCryptoIosArm64
> Task :ivy:cinteropKCryptoIosArm64
> Task :ivy:swiftklibKCryptoIosSimulatorArm64
> Task :ivy:cinteropKCryptoIosSimulatorArm64
> Task :ivy:swiftklibKCryptoIosX64
> Task :ivy:cinteropKCryptoIosX64
After these tasks have run, the XCode build succeeds. This is the output of Kotlin build executed by Xcode – UP-TO-DATE, therefore skipping the KLib build as it has been already done from the Android Studio environment.
Task :ivy:swiftklibKCryptoIosSimulatorArm64 UP-TO-DATE Task :ivy:cinteropKCryptoIosSimulatorArm64 UP-TO-DATE
What is strange here?
- From my understanding, these tasks should NOT be executed at all for the Android environment. (Or maybe they should, but only on MacOS, so Android Studio can see contents of references Swift files, and Intelli Sence works)
- For some reason, it builds for the correct target, even when there are missing Xcode environment variables defining the target, as it is built inside Android Studio.
- As this Swift-KLib build is always triggered, it blocks the build on our Linux CI, where we build Android binaries, referencing separate issue: https://github.com/ttypic/swift-klib-plugin/issues/16
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 8
- Comments: 15 (2 by maintainers)
Still an issue on Xcode 16.2 and Kotlin 2.1.20. @jvondermarck’s approach didn’t work either
I figured it out why there is this error. This
invalid swift manifesterror happens when you edit the code inside your Swiftgroup.To avoid the error to happen you need follow these steps
swiftklibsection and thecreatepart :@heyshowshana @jvondermarck resolved by updating Xcode to version 16.0, update the Kotlin library to version 2.0.21 and resync your project. You can close this issue.
Awesome @wh173d3v11 !! 💪🏽
This PR will solve the above issues - #45