XCode run script

Deleted User

Posted on
Jun 01 2023

Is it possible to add a run script in XCode to upload dsym when I build for release?


John-Daniel Trask

Raygun

Posted on
Jun 02 2023

Hi,

You can upload dSYM files to Raygun from Xcode by scripting the process, using a post-build script that runs automatically every time you build your app. Here's how you can do it:

  1. Navigate to your target in Xcode.
  2. Click on Build Phases.
  3. Click on the + button to add a new build phase and select New Run Script Phase.
  4. In the new phase, you can add a shell script that uploads the dSYM file to Raygun. The script can look something like this:
# Check if dSYM file exists
if [ "${DWARF_DSYM_FOLDER_PATH}" ] && [ "${DWARF_DSYM_FILE_NAME}" ] && [ "${DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT}" == "YES" ]; then

    # Path to dSYM file
    DSYM_PATH="${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"

    # Verify if dSYM file exists
    if [ -d "${DSYM_PATH}" ]; then

        # Zip the dSYM file
        /usr/bin/zip -r "${DSYM_PATH}.zip" "${DSYM_PATH}"

        # Upload to Raygun
        /usr/bin/curl -F "symbolFile=@${DSYM_PATH}.zip" -F "authToken=YOUR_AUTH_TOKEN" -F "version=YOUR_APP_VERSION" https://app.raygun.com/upload/dSYM

    fi
fi

Remember to replace YOURAUTHTOKEN with your actual Raygun authentication token and YOURAPPVERSION with the version of your app.

This script first checks if a dSYM file has been generated during the build. If such a file exists, the script then zips it and uploads it to Raygun using the cURL command.

Remember that every time you create a new build or release version, you will need to upload the new dSYM files so that Raygun can symbolicate any new crashes that may happen. Also, it is necessary to set your build settings to generate dSYM files. If you don't, Xcode won't generate them, and you won't have anything to upload to Raygun.

This is the basic process to automate dSYM file uploads, but it could be more complicated depending on your setup. You might need to deal with multiple dSYM files if you have multiple targets, for example. But the process would still be the same: upload each dSYM file after building the corresponding target.

You can read more about curl uploading of the DSYM files here as well: https://raygun.com/documentation/language-guides/apple/crash-reporting/advanced-setup/#uploading-a-dsym-file

I hope that helps, let me know how you get on.

John-Daniel Trask


Reply