Closed cabaucom376 closed 5 months ago
@vlazdra can you look at this?
Hey @jonbhanson and @cabaucom376! 👋
As far as I'm aware, it's not possible to define which file is included in which schema build. It's something that needs to be handled manually by the developer.
I asked ChatGPT if it can help, and it came up with this solution. By manually adding/removing the file from the bundle you are including/excluding the flavour storyboard that has nothing to do in that bundle.
Will test this out on my project as well. Please let me know if this helps.
Open Your Project:
Select the Target:
Go to Build Phases:
Build Phases
tab in the project settings.Locate Copy Bundle Resources:
Build Phases
tab, find the Copy Bundle Resources
phase. This phase is responsible for copying resource files like storyboards, images, and other assets into the app bundle.Remove Unwanted Storyboards:
-
button to remove them from the Copy Bundle Resources
list.If you want to automate the inclusion/exclusion of specific storyboards based on the build configuration (e.g., Debug or Release), you can add a custom Run Script Phase.
Add a New Run Script Phase:
+
button at the top of the Build Phases
tab and select New Run Script Phase
.Insert the Script:
Copy Bundle Resources
phase to ensure it runs before resources are copied.Here is an example script that removes specific storyboard files for different build configurations:
# Define the storyboard names to be excluded for each configuration
DEBUG_STORYBOARD="Main.storyboardc"
RELEASE_STORYBOARD="AltMain.storyboardc"
# Path to the resource directory
RESOURCE_DIR="${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
# Remove storyboards based on the build configuration
if [ "$CONFIGURATION" == "Debug" ]; then
echo "Removing $RELEASE_STORYBOARD for Debug build"
rm -rf "$RESOURCE_DIR/$RELEASE_STORYBOARD"
elif [ "$CONFIGURATION" == "Release" ]; then
echo "Removing $DEBUG_STORYBOARD for Release build"
rm -rf "$RESOURCE_DIR/$DEBUG_STORYBOARD"
fi
Info.plist
file for each build configuration points to the correct storyboard.UIMainStoryboardFile
key in the Info.plist
for each build configuration.Imagine you have two storyboards: Main.storyboard
and AltMain.storyboard
. You want Main.storyboard
to be used for Debug builds and AltMain.storyboard
for Release builds.
In the Copy Bundle Resources
phase:
AltMain.storyboard
from the list for the Debug target.Main.storyboard
from the list for the Release target.Add the Run Script Phase:
Set Info.plist:
Info.plist
for the Debug configuration points to Main.storyboard
.Info.plist
for the Release configuration points to AltMain.storyboard
.By carefully configuring the build phases and using a script to manage resource inclusion, you can streamline your build process and ensure that only the necessary storyboards are included in your final app builds.
@cabaucom376 based on your thumbs up, I assumed this helped you and close the ticket.
I have 3 flavors setup in my iOS Flutter project and I have properly got the flavored splash screens to work appropriately
I noticed when I ran a build size analysis (
flutter build ios --analyze-size -t lib/main_prod.dart --flavor production
) that its still bundling all storyboard files:Any guidance on how to strip these?