I’m trying to build my flutter 3.22.3 project in Xcode Version 15.4 (15F31d). I keep getting an error
No such module FlutterMacOS
I want to avoid editing the xcode ui directly apart from adding a run script for the runner and flutter assemble build targets. I have removed and recreated the macos directory but it didn’t help. Here is my run script for both runner and flutter assemble targets, largely written by chatGPT:
#!/bin/sh
export DEBUG_INFORMATION_FORMAT=dwarf
export ENABLE_TESTABILITY=YES
export PRODUCT_NAME="myapp"
export PRODUCT_BUNDLE_IDENTIFIER="com.myapp.app"
export PRODUCT_MODULE_NAME="myapp"
# Paths to the input and output files
INPUT_FILE="${SRCROOT}/Flutter/ephemeral/Flutter-Inputs.xcfilelist"
OUTPUT_FILE="${SRCROOT}/Flutter/ephemeral/Flutter-Outputs.xcfilelist"
# Check if the input file exists, if not create it
if [ ! -f "$INPUT_FILE" ]; then
echo "Creating $INPUT_FILE..."
echo "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" > "$INPUT_FILE"
else
echo "$INPUT_FILE already exists. Skipping creation."
fi
# Check if the output file exists, if not create it
if [ ! -f "$OUTPUT_FILE" ]; then
echo "Creating $OUTPUT_FILE..."
echo "$SRCROOT/Flutter/ephemeral/Flutter-Generated.xcconfig" > "$OUTPUT_FILE"
else
echo "$OUTPUT_FILE already exists. Skipping creation."
fi
# Determine the correct path based on the build configuration
if [ "$CONFIGURATION" == "Debug" ]; then
FLUTTER_FRAMEWORK="${FLUTTER_ROOT}/bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework"
FRAMEWORK_SEARCH_PATHS="$FLUTTER_ROOT/bin/cache/artifacts/engine/darwin-x64 $SRCROOT/../Flutter/ephemeral $SRCROOT/Flutter/ephemeral"
else
FLUTTER_FRAMEWORK="${FLUTTER_ROOT}/bin/cache/artifacts/engine/darwin-x64-release/FlutterMacOS.xcframework/macos-arm64_x86_64/FlutterMacOS.framework"
FRAMEWORK_SEARCH_PATHS="$FLUTTER_ROOT/bin/cache/artifacts/engine/darwin-x64-release $SRCROOT/../Flutter/ephemeral $SRCROOT/Flutter/ephemeral"
fi
# Ensure FlutterMacOS.framework is added to the project
FRAMEWORK_DIR="${SRCROOT}/../Flutter/ephemeral"
DESTINATION_FRAMEWORK_DIR="${PROJECT_DIR}/Flutter/ephemeral/FlutterMacOS.framework"
if [ ! -d "$DESTINATION_FRAMEWORK_DIR" ]; then
echo "Copying FlutterMacOS.framework to $DESTINATION_FRAMEWORK_DIR"
mkdir -p "$FRAMEWORK_DIR"
cp -R "$FLUTTER_FRAMEWORK" "$DESTINATION_FRAMEWORK_DIR"
else
echo "FlutterMacOS.framework already exists in $DESTINATION_FRAMEWORK_DIR. Skipping copy."
fi
# Set the framework search paths and other linker flags dynamically
export OTHER_LDFLAGS="$(inherited) -framework FlutterMacOS"
# Add the framework search paths and other linker flags to the xcconfig file
XC_CONFIG_FILE="$PROJECT_DIR/Flutter/ephemeral/Flutter-Generated.xcconfig"
if [ ! -f "$XC_CONFIG_FILE" ]; then
touch "$XC_CONFIG_FILE"
fi
echo "FRAMEWORK_SEARCH_PATHS=$(inherited) $FRAMEWORK_SEARCH_PATHS" >> "$XC_CONFIG_FILE"
echo "HEADER_SEARCH_PATHS=$(inherited) $FRAMEWORK_SEARCH_PATHS" >> "$XC_CONFIG_FILE"
echo "OTHER_LDFLAGS=$(inherited) $OTHER_LDFLAGS" >> "$XC_CONFIG_FILE"
echo "EXCLUDED_ARCHS=arm64" >> "$XC_CONFIG_FILE"
# Set the environment variables for Xcode build
export XCODE_WORKING_DIR="$SRCROOT"
export XCODE_PROJECT_DIR="$SRCROOT"
echo "$PRODUCT_NAME.app" > "$PROJECT_DIR/Flutter/ephemeral/.app_filename"
"$FLUTTER_ROOT"/packages/flutter_tools/bin/macos_assemble.sh embed
"$FLUTTER_ROOT/packages/flutter_tools/bin/macos_assemble.sh"
touch "$PROJECT_DIR/Flutter/ephemeral/tripwire"