Migrating to xcframwork Xcode 12.5, dyld: Library not loaded
Asked Answered
P

1

9

Environment

  • MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)
  • Big sur 11.3.1
  • Xcode 12.5
  • Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)
  • Target: x86_64-apple-darwin20.4.0

Problem

Up until Xcode 12.4, we used this workaround to get frameworks for our project and the those frameworks are in the form of bundles (yellow briefcase icons). Also, I need to hand carve a Carthage Copy File script (under Build Phase) for each of my targets, which is annoying and error prone.

A few days ago I read the Carthage official doc and it suggests to use xcframework. From the steps it sounds like the annoying copy file step is no longer needed and I decided to give it shot.

I followed the migration steps exactly. I also changed the framework search path to make it point from $(PROJECT_DIR)/YOUR_PROJECT/Carthage/Build/iOS to $(PROJECT_DIR)/YOUR_PROJECT/Carthage/Build . The app just ran in the simulator but it was too early to cheer up and it crashes whenever I tried to run it in an iPhone. In the debugger console it complains

dyld: Library not loaded: @rpath/Auth0.framework/Auth0
  Referenced from: /private/var/containers/Bundle/Application/9575D8AA-BD35-447B-ACC3-F8545CDB62EE/FIT dev.app/FIT dev
  Reason: image not found
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

Solution

Finally I came across this Medium post from 2 years ago, where it suggests to embed & sign the frameworks that were dragged and dropped to the project. I did same thing to my project by changing the Embed status of some of the frameworks from Do not embed to Embed & Sign (from the tab General/Frameworks, Libraries and Embedded Content).

Bingo! The project runs in both simulator and real device, the UI test also runs as before.

The migration steps in Carthage's official doc didn't mention this step at all. Also, I couldn't find any posts that addresses the similar issue. So I just want to share my migration steps and hope this may be helpful some else

  • Follow migration steps exactly (If you have multiple targets, the trick here is to drop all the xcframeworks under the /Frameworks group in your file navigator, in this way you can link the xcframeworks to all your targets in one shot)

enter image description here

enter image description here

  • Set the embed status for your newly added xcframeworks, see the snapshots below, where I put the frameworks into three groups

    • Green, third party library, e.g. auth0, alamofire -> Embed and Sign
    • Orange -> Development library -> Embed and Sign
    • The rest, in my case are xcframeworks for Firebase -> Do not embed

Set embed status

Phyto answered 28/5, 2021 at 20:48 Comment(0)
P
2

I have already answered my question in itself, please see the question, thanks :)

Phyto answered 28/5, 2021 at 20:49 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.