36

I recently update Xcode to Version 7.1, which included Swift 2.1. I installed Swift 2.1 with no troubles. After attempting to run my project, I realized that I needed to grab the latest version of Realm, since the previous version did not support Swift 2.1. I deleted the old frameworks and imported Realm 0.96.2. Whenever I run, I now get this error:

bash: /Users/userName/Library/Developer/Xcode/DerivedData/appName-ghiroqitgsbvfhdqxsscyokyoouz/Build/Products/Debug-iphoneos/appName.app/Frameworks/Realm.framework/strip-frameworks.sh: No such file or directory

I suspected the problem was with the script that is required if you wish to submit your app the the App Store, so I removed the Run Script Phase, added a new one, and copied the script from the Realm documentation site:

bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework/strip-frameworks.sh"

I thought that that would fix it, but it did not. I then thought that the problem may be in the Realm.framework or RealmSwift.framework files, so I removed them and re-imported them (Just in case I messed something up). Nothing changed. Does anyone know if there is a fix to this error?

Thanks! -CodeIt

CodeIt
  • 769
  • 2
  • 7
  • 16
  • 5
    Strip Framework Architectures should be AFTER Embed Frameworks under the Build Phases tab. You can drag it using your mouse (since it isn't totally obvious). Realm should specify this instruction in their documentation. @marius helped make this clear. – AppreciateIt Apr 16 '17 at 21:58

2 Answers2

53

From the error message, it seems like, you didn't added Realm.framework and RealmSwift.framework to the Embedded Binaries pane, which you find in the General tab of your project, as shown below:

Embedded Binaries

For further validation, you can check the tab Build Phases. It should look like below:

Build Phases

Note: Make sure that the run script phase comes after the Embed Frameworks phase.

Why is this script needed?

The vendored frameworks are not just single executables, but actually FAT binaries which are archives of linked executables on different architectures. This includes architecture slices for arm64 and armv7, which are necessary for deployment on the phone as well as i386 and x86_64 which are necessary for running the app in the simulator.

The strip-frameworks.sh script main responsibility is to take care of removing unnecessary slices. This reduces the final package size and is necessary for AppStore deployment because iTunes Connect rejects apps with simulator architectures.

More Details

The script works on base of the build setting VALID_ARCHS. Because that is changing the signed executable of the framework, it also needs to take care of code signing. Since introduction of bitcode, it also got further post processing as responsibility. It extracts the included *.bcsymbolmap files from the framework bundle and places them into correct path in the *.xcarchive.

The FAQ topic on Bitcode of PSPDFKit has a good explanation on what BCSymbolMaps are:

A BCSymbolMap is a lot like a dSYM for bitcode. Xcode builds it as part of creating the app binary, and also for every dynamic framework. It's required for re-symbolicating function/method names to understand crashers.

marius
  • 7,766
  • 18
  • 30
  • Marius, thank you! I had never added the frameworks to the _Embedded Binaries_ pane, and it works perfectly now! A light bulb just went off in my head - the `${FRAMEWORKS_FOLDER_PATH}` inside the script is regarding the Frameworks destination in the embedded frameworks pane, yes? – CodeIt Oct 28 '15 at 17:40
  • Yes, the resolved build setting `$FRAMEWORKS_FOLDER_PATH` configures / refers to the relative path of the `Frameworks` directory in the `$BUILT_PRODUCTS_DIR`. So the script failed because the framework wasn't copied to the right place. That's not only important for the script, but also for shipping, because dynamic frameworks are not becoming part of your executable and reside separated and must been bundled for that reason to be dynamically loaded at runtime. – marius Oct 28 '15 at 18:09
  • 34
    The order of build phases is crucial! Strip Framework Architectures after Embed Frameworks. Thank you for let me recognize that @marius – FBente Aug 17 '16 at 15:53
  • @marius I have confirmed all these steps and still have the error outlined in the question. Any other idea what the problem might be? – user2363025 Nov 29 '16 at 18:47
  • Sorry @user2363025, totally missed your comment here! Beyond what it outlined in the answer and our docs, I don't have any specific hints what could go wrong. But you're always welcome to send over a reproducible project to help@realm.io. – marius Dec 06 '16 at 09:30
  • I had a similar issue but for the amazon SDK, make sure to add the 'core' framework as well as any other framework you might need. In my case I need S3 and Core – Joseph Astrahan Dec 13 '16 at 02:13
  • @KrishnaCA: I added an explanation to my answer. :) – marius Feb 24 '18 at 12:19
  • @marius, I believe that this is specific to `Realm.framework` right? – KrishnaCA Feb 24 '18 at 12:22
  • @KrishnaCA: The script is distributed with the `Realm.framework`, but applies beyond. In fact a lot of third party frameworks do use exactly the *same* script, which takes care of all frameworks you're integrating. The dependency managers CocoaPods and Carthage provide built-in functionalities around this. – marius Feb 25 '18 at 13:16
  • @marius, I had a similar issue with `Razorpay.framework`. But, had to distribute it without bitcode to resolve the problem. I tried using a similar script to solve this. But, it didn't work. It's because it doesn't have the `strip-frameworks.sh`. Thanks for the clarification – KrishnaCA Feb 25 '18 at 13:26
  • 1
    @marius - it would be helpful to update the answer to include that the `run script` step needs to come after `embed binaries` and this should be checked. I suspect at some stage of upgrading to the latest version of Realm (or Xcode), my `embed binaries` step got "magically" moved last. It was building ok when last touched (a few months prior), and when it breaks this way it's very confusing. – Michael Aug 26 '18 at 06:29
  • @Michael: Good point. That's why I included the screenshot, but writing it down explicitly makes it clearer. :) – marius Sep 07 '18 at 10:07
11

In my case, change the process order in Build Phases to solve

  • not OK

11

  • OK

555

dengApro
  • 3,848
  • 2
  • 27
  • 41