Search code examples
iosxcodereact-nativebitcodexcode16

iOS apps built with Xcode 16 grow up in size significantly


After upgrading to Xcode 16 I've noticed that my app grew up in size, from 10MB to 165MB(!).

I've presumed it's related to bitcode settings removal in this version of Xcode, so I've added my own strip symbols step to build phases (same as the one proposed in https://docs.emergetools.com/docs/strip-binary-symbols), but nothing has changed.

I need some advice on what else to check in order to decrease the app size back to normal while continuing to use the most recent version of Xcode.


Solution

  • Finally, I've found the solution.
    It was the framework binaries (in my case, hermes) that caused the problem by holding its symbols unstripped.

    Long story short:

    1. Take the strip symbols script from the guide at https://docs.emergetools.com/docs/strip-binary-symbols
    2. In the script use a different value for the APP_FRAMEWORKS_DIR:

    APP_FRAMEWORKS_DIR="${BUILT_PRODUCTS_DIR}/XCFrameworkIntermediates"

    instead of

    APP_FRAMEWORKS_DIR="${APP_DIR_PATH}/Frameworks"

    so it should look like this

    #!/bin/bash
    set -e
    
    echo "Starting the symbol stripping process..."
    
    if [ "Release" = "${CONFIGURATION}" ]; then
      echo "Configuration is Release."
      
      # Path to the app directory
      APP_DIR_PATH="${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}"
      echo "App directory path: ${APP_DIR_PATH}"
    
      # Strip main binary
      echo "Stripping main binary: ${APP_DIR_PATH}/${EXECUTABLE_NAME}"
      strip -rSTx "${APP_DIR_PATH}/${EXECUTABLE_NAME}"
      if [ $? -eq 0 ]; then
        echo "Successfully stripped main binary."
      else
        echo "Failed to strip main binary." >&2
      fi
    
      # Path to the Frameworks directory
      APP_FRAMEWORKS_DIR="${BUILT_PRODUCTS_DIR}/XCFrameworkIntermediates"
      echo "Frameworks directory path: ${APP_FRAMEWORKS_DIR}"
    
      # Strip symbols from frameworks, if Frameworks/ exists at all
      # ... as long as the framework is NOT signed by Apple
      if [ -d "${APP_FRAMEWORKS_DIR}" ]; then
        echo "Frameworks directory exists. Proceeding to strip symbols from frameworks."
        find "${APP_FRAMEWORKS_DIR}" -type f -perm +111 -maxdepth 2 -mindepth 2 -exec bash -c '
        codesign -v -R="anchor apple" "{}" &> /dev/null ||
        (
            echo "Stripping {}" &&
            if [ -w "{}" ]; then
                strip -rSTx "{}"
                if [ $? -eq 0 ]; then
                    echo "Successfully stripped {}"
                else
                    echo "Failed to strip {}" >&2
                fi
            else
                echo "Warning: No write permission for {}"
            fi
        )
        ' \;
        if [ $? -eq 0 ]; then
            echo "Successfully stripped symbols from frameworks."
        else
            echo "Failed to strip symbols from some frameworks." >&2
        fi
      else
        echo "Frameworks directory does not exist. Skipping framework stripping."
      fi
    else
      echo "Configuration is not Release. Skipping symbol stripping."
    fi
    
    echo "Symbol stripping process completed."
    
    1. In your Xcode project's target build phases add the script as a custom "Strip symbols" step before the "Embed Pods Frameworks" one.