Instabug/Instabug-SP

Upload DSYMs script not working via SwiftPM

Jeehut opened this issue ยท 14 comments

Steps to Reproduce the Problem

  1. Integrate Instabug via SwiftPM as described in this README (or the documentation)
  2. Add the following build script (from the documentation):
#- -- SCRIPT BEGIN - --
# SKIP_SIMULATOR_BUILDS=1
  SCRIPT_SRC=$(find "$PROJECT_DIR" -name 'Instabug_dsym_upload.sh' | head -1)
  if [ ! "${SCRIPT_SRC}" ]; then
    echo "Instabug: err: script not found. Make sure that you're including InstabugResources.bundle in your project directory"
    exit 1
  fi
  APP_TOKEN="MY_TOKEN"
  source "${SCRIPT_SRC}"
#- -- SCRIPT END - --
  1. Build your application

Expected Behavior

My application should build fine. Also the DSYMs should be uploaded successfully.

Actual Behavior

My application errors out with this error:

Instabug: err: script not found. Make sure that you're including InstabugResources.bundle in your project directory
Command PhaseScriptExecution failed with a nonzero exit code

Instabug integration code

What an "integration code"?

SDK Version

10.4.0

iOS Version

Not relevant (but min target is iOS 10 if needed).

Device Model

Not relevant.

[Optional] Project That Reproduces the Issue

โ€“

Additional Notes

I checked out the .zip files the Package.swift points to and found that there are actually InstabugResources.bundle files (see screenshot below), but the script seems not to point to them correctly when Instabug is integrated via SwiftPM. I have the feeling either the script is not updated to accustom SwiftPM or there's an additional step missing to add a symlink to the project somehow which will point to the right files.
Bildschirmfoto 2021-02-19 um 17 00 21

I found a workaround for this, I just had to replace the third line of the script (starting with SCRIPT_SRC=) with these 2 lines:

  SEARCH_DIR="$(dirname $(dirname $BUILD_ROOT))/SourcePackages/artifacts/Instabug"
  SCRIPT_SRC=$(find "$SEARCH_DIR" -name 'Instabug_dsym_upload.sh' | head -1)

Please also note that the script doesn't find any DSYMs of dependencies that were downloaded as build artifacts when integrating all dependencies via SwiftPM. You might want to also adjust the script to find any dependencies in the SourcePackages/artifacts folder (see my workaround above), I can find the downloaded DSYM files there, but the script doesn't seem to find them. The funny thing is, one of the dependencies with missing DSYMs is actually Instabug itself. ๐Ÿ˜„
Bildschirmfoto 2021-02-19 um 18 16 35

Hey @Jeehut, sorry for the late reply. Thank you for the detailed report ๐Ÿ™
We will update the script to fix these two issue, will update you once it's released.

@hassaanelgarem any updates on that?

Hi @Jeehut
You will find our docs updated ASAP
For now you can:

  1. Add the current script (with your workaround) in Edit Scheme > Build > Post-actions > New run script
  2. Make sure to select your app to provide build settings to script
  3. Remove the current script from the build phases

Hello. I'm facing the same issues. Any updates on this?

Hi @mdoukmak sorry for being late
did you follow the documentation for automatically uploading the DSYMs with SPM?

I'm following the documentation with SPM version
Xcode Cloud cannot find Instabug_dsym_upload.sh under $PROJECT_DIR or $BUILT_PRODUCTS_DIR

xmollv commented

I'm following the documentation with SPM version
Xcode Cloud cannot find Instabug_dsym_upload.sh under $PROJECT_DIR or $BUILT_PRODUCTS_DIR

I think that I'm having the same issue since it ain't working, but I'm struggling to find the logs for that. Where did you see the failure? Did you manage to solve it?

@KerollosNabil @husseinkishk @hassaanelgarem do you guys have a ready-to-go script for Xcode Cloud? IMHO more and more users will start integrating with SPM and using Xcode Cloud as the CI, seems that there should be an easy way to make it work!

xmollv commented

I've been digging around this, and indeed the script doesn't work for SPM. I had it on my Post-Actions in the Archive phase, and I get this:

Instabug: err: script not found. Make sure that you're including InstabugResources.bundle in your project directory

I tried with the suggested fix above, but that seems to be only for the Build phase, on the Archive phase I get this:

find: /Users/xmollv/Library/Developer/Xcode/DerivedData/Here-aggpbcicmjapmbgpgnogtudadswu/Build/Intermediates.noindex/ArchiveIntermediates/SourcePackages/artifacts/Instabug: No such file or directory
Instabug: err: script not found. Make sure that you're including InstabugResources.bundle in your project directory

To be able to see the logs of a Post-Action on an Archive phase, I had to send the logs to a .txt file to be able to see them, otherwise I couldn't find them anywhere, see: https://stackoverflow.com/a/47167623/5683397

Any ideas on how to solve this?

xmollv commented

I know that this is not SPM related, but anyone having issues in Xcode Cloud will probably end up finding this issue. I managed to make the dSYM upload work when using SPM and Xcode Cloud. Instead of using the Post-Action step in the Archive process, I'm using the ci_post_xcodebuild.sh with the following script:

set -e
 if [[ -n $CI_ARCHIVE_PATH ]]; then
   ENDPOINT="https://api.instabug.com/api/sdk/v3/symbols_files"
   APP_TOKEN="<YOUR_APP_TOKEN>"
   DSYMS_DIR="${CI_ARCHIVE_PATH}/dSYMs"
   DSYM_PATH_ZIP="${CI_ARCHIVE_PATH}/dSYMs.zip"
   zip --recurse-paths --quiet "${DSYM_PATH_ZIP}" "${DSYMS_DIR}"
   curl -X POST "${ENDPOINT}" -F os=iOS -F symbols_file=@"${DSYM_PATH_ZIP}" -F application_token="${APP_TOKEN}"
 fi

Got some inspiration from Instabug_dsym_upload.sh and from this blog post: https://www.jakubkaspar.dev/blog/xcode-14-with-no-bitcode-xcode-cloud-and-dsym-files-for-firebase-crashlytics

Hi @xmollv, it's impressive how you handled everything on your own ๐Ÿ‘Œ

We will be investigating what we can do from our side to better help customers who are using SPM and XcodeCloud, will keep everyone here posted with any updates ๐Ÿ‘

Hi @xmollv, Thank you for reaching out.

This script was designed with the expectation that it will be used from within Xcode. That's why it wasn't working before.

You can use the script here in the Xcode build phases.

You can also use it from ci_scripts/ci_post_xcodebuild.sh by making some adjustments.

#- -- SCRIPT BEGIN - --
# SKIP_SIMULATOR_BUILDS=1
SCRIPT_SRC=$(find "$CI_DERIVED_DATA_PATH" -name 'Instabug_dsym_upload.sh' | head -1)

DWARF_DSYM_FOLDER_PATH="$CI_ARCHIVE_PATH/dSYMs"
DWARF_DSYM_FILE_NAME="${CI_PRODUCT}.app.dSYM"

if [ ! "${SCRIPT_SRC}" ]; then
echo "Instabug: err: script not found. Make sure that you're including InstabugResources.bundle in your project directory"
exit 1
fi
 # APP_TOKEN="YOUR-APP-TOKEN-HERE"
source "${SCRIPT_SRC}"
#- -- SCRIPT END - --

We are currently working on improving this solution and support for Xcode-cloud.