moko-resources
moko-resources copied to clipboard
iOS: "IllegalArgumentException: bundle with identifier com.xxx.presentation.resources.main not found" due to custom build CONFIGURATION name
Problem
After migrating from a dynamic framework, that used CocoaPods plugin, to a static one, without the latter, we faced difficulties with bundling resources to the app.
Setup
As shown in the ReadMe file, we added the following script to our build phase:
"$SRCROOT/../../gradlew" -p "$SRCROOT/../../" :app:composeApp:copyFrameworkResourcesToApp \
-Pmoko.resources.PLATFORM_NAME="$PLATFORM_NAME" \
-Pmoko.resources.CONFIGURATION="$CONFIGURATION" \
-Pmoko.resources.ARCHS="$ARCHS" \
-Pmoko.resources.BUILT_PRODUCTS_DIR="$BUILT_PRODUCTS_DIR" \
-Pmoko.resources.CONTENTS_FOLDER_PATH="$CONTENTS_FOLDER_PATH"
Everything else is set up correctly:
- Latest moko-resources version: 0.24.4.
- Resources plugin is added to the submodule and to the shared module.
- Resources library is added to the submodule and the shared module through
implementation(...).
Here's how we build and link the shared framework to the iosApp (This script runs before copying resources, as shown above):
if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then
echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\""
exit 0
fi
cd "$SRCROOT/../../"
./gradlew :app:composeApp:embedAndSignAppleFrameworkForXcode
Diagnosis
- Running
find . -type d -name "*.bundle"in the build folder of the shared module shows that bundles exist during the build phase:
./bin/iosArm64/debugFramework/ComposeApp.framework/xxx-kmp-app.data:local.bundle
./bin/iosArm64/debugFramework/ComposeApp.framework/xxx-kmp-app.presentation:resources.bundle
./xcode-frameworks/DebugDevelopment/iphoneos17.4/ComposeApp.framework/xxx-kmp-app.data:local.bundle
./xcode-frameworks/DebugDevelopment/iphoneos17.4/ComposeApp.framework/xxx-kmp-app.presentation:resources.bundle
- Running
./gradlew tasksin the root project folder shows that copy tasks are correctly generated:
**Moko-resources tasks**
**--------------------**
copyResourcesDebugFrameworkIosArm64
copyResourcesDebugFrameworkIosSimulatorArm64
copyResourcesDebugFrameworkIosX64
copyResourcesDebugTestIosArm64
copyResourcesDebugTestIosSimulatorArm64
copyResourcesDebugTestIosX64
copyResourcesReleaseFrameworkIosArm64
copyResourcesReleaseFrameworkIosSimulatorArm64
copyResourcesReleaseFrameworkIosX64
generateMR
....
// остальные все generate
Workaround
During our discussion with the author @Alex009, we realized that the issue is caused by custom build CONFIGURATION name. In our case, we used DebugDevelopment, while the copy tasks expected something like Debug or Release for static frameworks.
As a workaround, we added KOTLIN_FRAMEWORK_BUILD_TYPE variable to configuration files, with the following values:
// inside debug configuration files
KOTLIN_FRAMEWORK_BUILD_TYPE=debug
// inside release configuration files
KOTLIN_FRAMEWORK_BUILD_TYPE=release
Then we updated the copy script to use KOTLIN_FRAMEWORK_BUILD_TYPE instead of CONFIGURATION, which now looks like this:
"$SRCROOT/../../gradlew" -p "$SRCROOT/../../" :app:composeApp:copyFrameworkResourcesToApp \
-Pmoko.resources.PLATFORM_NAME="$PLATFORM_NAME" \
-Pmoko.resources.CONFIGURATION="$KOTLIN_FRAMEWORK_BUILD_TYPE" \
-Pmoko.resources.ARCHS="$ARCHS" \
-Pmoko.resources.BUILT_PRODUCTS_DIR="$BUILT_PRODUCTS_DIR" \
-Pmoko.resources.CONTENTS_FOLDER_PATH="$CONTENTS_FOLDER_PATH"
This solved our problem! 🎉