iOS Widget Extension with embedAndSignAppleFrameworkForXcode

I’m currently facing an issue after adding an iOS widget extension to my Multiplatform project, because
validating the archive fails with these errors:

Asset validation failed
Invalid Bundle. The bundle at 'iosApp.app/PlugIns/iosWidgetExtension.appex' contains disallowed nested bundles. (ID: 88c8e31d-6dbc-4179-8146-d54d6a3c1eab)

Asset validation failed
Invalid Bundle. The bundle at 'iosApp.app/PlugIns/iosWidgetExtension.appex' contains disallowed file 'Frameworks'. (ID: 688944b2-e139-41e9-b53c-e79a3de9ddad)

Since extensions are not supposed to contain Frameworks, I removed the build phase step where the framework was embedded in the extension (./gradlew :shared:embedAndSignAppleFrameworkForXcode). However, this creates a chicken and egg situation, where the iosApp target requires the iosWidgetExtension which itself does not build the framework anymore and therefore cannot resolve the shared module, because the build phase in the iosApp target didn’t execute yet.

Did anybody face this issue yet, not quite sure how I can resolve this…

A workaround I found, was to move the script from the build phase to the schema build pre-action of the iosApp target and provide the build settings:

cd "$SRCROOT/.."
./gradlew :shared:embedAndSignAppleFrameworkForXcode < /dev/null

The < /dev/null has to be added for xcodebuild CLI to work, see: Gradle hangs in Xcode pre-build actions · Issue #15941 · gradle/gradle · GitHub

Are there any drawbacks to this solution, besides not showing the framework as a proper build step in Xcode?

1 Like