Skip to content

App size increased(almost doubled) with Xcode 14 and Bitcode Disabled #571

@vinhnx

Description

@vinhnx

How to strip binary symbols without bitcode

Luckily, stripping binary symbols from the final build product is straightforward. Here are two ways you can strip binary symbols.

Using Xcode build settings

You can do automatic stripping of builds during the Archive build action by setting:

  • "Deployment Postprocessing" = "Yes"
  • "Strip Linked Product" to "Yes"
  • "Additional Strip Flags" to -rSTx

All other stripping settings to their defaults
However, with this method, you have to be careful that settings are the same for all targets. Also, there can be pitfalls when used with package managers. For Cocoapods, here is a discussion of the issue which links to one possible solution (make sure that the frameworks being stripped are all dynamic if you do this).

Using a Shell Script

One can also run the script below at the very end of the build process, right before signing. Note that for some package managers like Cocoapods, there may not be any point between the frameworks being copied in and being signed where a custom script can be run. In that case, signing must be done again manually after the stripping, because stripping will invalidate the signature.

Below is an example of a script you can use for binary stripping. Huge thanks to Filip Busic from Doordash for helping here!

#!/bin/bash
set -e

# if [ "Release" = "${CONFIGURATION}" ]; then # Uncomment and only do this for release builds that you don't need to debug
    
    # Path to the app directory
    APP_DIR_PATH="${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}"
    # Strip main binary
    strip -rSTx "${APP_DIR_PATH}/${EXECUTABLE_NAME}"
    # Path to the Frameworks directory
    APP_FRAMEWORKS_DIR="${APP_DIR_PATH}/Frameworks"
    
    # 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
        find "$APP_FRAMEWORKS_DIR" -type f -perm +111 -maxdepth 2 -mindepth 2 -exec bash -c 'codesign -v -R="anchor apple" "{}" &> /dev/null || (printf "%s\\n" "{}" && strip -rSTx "{}")' \;
    fi
    # Re-sign binaries as necessary
# fi

In the build phases's settings, make sure that "Based on dependency analysis" is unchecked so that the script is run on every build. You can read more about this method on our documentation.

Note: binary stripping has to be done before codesigning the app or else the code signature will be invalidated.

https://www.emergetools.com/blog/posts/how-xcode14-unintentionally-increases-app-size


Provided a fix for it. Our app size is back to normal as earlier.

So, when we have Bitcode enabled, Apple does the stripping of the symbols from our IPA and thus helps us with smaller app size. However, when we disable Bitcode, symbols are not stripped by default. There is no documentation by Apple which recommends us to strip the symbols from the binary for bitcode disabled apps. Stripping the symbols would take you back to the previous app size where things were all normal.

To strip the symbols, we can use this command.

strip -rSTx Binary -o StrippedBinary.

The T flag tells strip to remove Swift symbols, the other flags remove
debugging and local symbols.

Steps to perform:

Once you generate an xcarchive, go to Show package Contents -> Products -> Applications -> YourAppName.app -> Show package contents. You will have YourAppName file. Run strip -rSTx YourAppName -o YourAppName to strip the symbols.

If you have other frameworks bundled inside your app, go to Frameworks folder and run the above strip command for all those framework files as well.

Here is a small script I have written which will help you to do it in one shot. Please change yourAppName.

#!/bin/bash

yourAppName=PhonePe
appFolder="$yourAppName.app"

echo "$appFolder"
cd $appFolder

strip -rSTx $yourAppName -o $yourAppName

cd Frameworks

for d in */ ; do
    IFS='. ' read -r -a array <<< "$d"
    newname=${array[0]}1
    
    strip -rSTx $d/${array[0]} -o $d/${array[0]}
done

Once the above script or stripping process is complete, you can proceed as-usual with distributing the app to App Store. Once Apple completes the processing of your build, you will see a very high reduction in the app size.
https://stackoverflow.com/a/74142041/1477298


Great article Xcode 14 unintentionally increases app size, I have added the script for each of my targets Strip Binary Symbols

Also if you are using CocoaPods add below script to podfile

post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    config.build_settings['STRIP_INSTALLED_PRODUCT'] = 'YES'
    config.build_settings['STRIP_STYLE'] = "all"
    config.build_settings['STRIPFLAGS'] = "-rSTx"
  end
end

https://stackoverflow.com/a/75819829/1477298

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions