Framework does not load on simulator

When running in debug mode from Xcode with debug session active, the app launches in the simulator and I am able to debug.

When trying to launch the app in the simulator without debug session (by double clicking on the icon), it crashes with the log message below.

Everything is fine on the real device.


This makes it impossible for me to debug Apple Watch apps, since the iOS version of the app cannot be launched in the background from the Apple Watch.

I am running Xcode 7 beta 3, but I don't think it is a bug, I am probably missing som flag in build settings. Any help is appreciated.


Application Specific Information:

dyld: launch, loading dependent libraries

DYLD_FALLBACK_LIBRARY_PATH=/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib

DYLD_ROOT_PATH=/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk

DYLD_FALLBACK_FRAMEWORK_PATH=/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks

DYLD_SHARED_REGION=avoid


Dyld Error Message:

Library not loaded: @rpath/SMHI_Parser.framework/SMHI_Parser

Referenced from: /Users/USER/Library/Developer/CoreSimulator/Devices/807ED0BE-DF53-4914-8847-9708719ECD22/data/Containers/Bundle/Application/C9958BD8-FB34-4937-9072-89A103A92D22/MyApp.app/MyApp

Reason: no suitable image found. Did find:

/Users/Cray/Library/Developer/CoreSimulator/Devices/807ED0BE-DF53-4914-8847-9708719ECD22/data/Containers/Bundle/Application/C9958BD8-FB34-4937-9072-89A103A92D22/Sky Tracker.app/Frameworks/SMHI_Parser.framework/SMHI_Parser: no matching architecture in universal wrapper

Everything you need to know is right in the error message:

/Users/Cray/Library/Developer/CoreSimulator/Devices/807ED0BE-DF53-4914-8847-9708719ECD22/data/Containers/Bundle/Application/C9958BD8-FB34-4937-9072-89A103A92D22/Sky Tracker.app/Frameworks/SMHI_Parser.framework/SMHI_Parser: no matching architecture in universal wrapper

The framework SMHI_Parser.framework was not built to include Simulator code (i.e. i386 and x86_64), so it can't be loaded in the Simulator. You (or whomever built that framework for you) need to build that framework for the Simulator when you are building your app for the Simulator.

Thanks for answering. I understand that. The question is, how can I force the compilator to build for the simulator. Those are my settings. I added i386 and x86_64. It does not help. Is there anything else I can check? Where can I get more information about fault tracing this kind of issue? SMHI_Parser loads now, but I have another one which does not. Same message and identical build settings with one that loads as far as I can see.


Architectures : Standard architectures (armv7, arm64) - $(ARCH_STANDARD)
Build Active Architecture Only : No
Supported Platforms: iOS
Valid Architectures: arm64 armv7 arm7s i386 x86_64

The SMHI_Parser.framework that you are referencing there was built for device and not for the simulator.


I suspect you perhaps have a "Copy Files" phase which is copying the framework, but you are copying the version that was built for device rather than the version that was built for the sim. Does that sound about right? If not, can you describe how SMHI_Parser.framework is getting built and packaged into your app bundle?

Yes, that sounds about right.


I found that if I clear Dynamic Library Install Name in Build settings - which is defined as $(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH), I am able to install and run the app in the simulator, i.e. the app is not crashing when launched from the Springboard as before. It appears to load all the frameworks and it works on both iPhone and Watch simulator.


At the same time, I need "Dynamic Libarary Install Name" as it is defined by default in order to be able to install the frameworks on the iPhone. But I cannot have both at the same time, apparently. I have kind of found a workaround even though it is not so enjoyable to play with the build settings all the time.


All the frameworks I am using are my own, built by myself in Xcode, latest beta on everything. I have checked build settings hundreds of times.

It is the oposite on the Watch, by the way. I can run and launch the app in the simulators, but my two frameworks that I am using will not install on my Apple Watch (device).


It would be good to know if loading frameworks on the watchOS 2.0 device is something that should be working at the moment. Maybe I should just wait for the next release.

I suspect that it working after you changed that build setting is more of a side effect than the solution you are looking for.


Is SMHI_Parser.framework a framework that you are building yourself, or is it provided by a 3rd party? If it is yours, are you building it in the same Xcode project or a different one? If a different one, are they in the same workspace?


If you could file a radar (http://bugreport.apple.com) with a reduced case that shows the issue, that would certainly be helpful =)

All right. I created a barebone sample project with a framework, main app, and iOS and watchOS targets.

I managed to reproduce my findings from earlier.

Radar nr: 22056813


SMHI_Parser.framework is my own framework, built by my self. No third party involvement.

I have separate projects for frameworks, but they are all in the same workspace, as it is in the filed bug report.

Thanks. I haven't looked at the project in radar yet, but my hunch is that you're just not rebuilding the frameworks when you are building your app, so the previously built (device copy) is what is copied into your sim app.

I have the similar problem and what you described is exactly what happened...


the project originally worked fine for simulator but couldn't run on device, I had to manually embed my frameworks in the build phases to make it run on the device. Now the reverse problem happened: the app won't run on simulator with the wrong image error mentioned above...


My workspace containing 2 primary frameworks, which reference a few 3rd party framework from pod, and an app project. The build does compile correctly, but the bundling process is problematic... What is the recommended configuration for the app to dynamically include the frameworks for device ?

jeremyhu,


The bug report is now closed: "This is behaving correctly. You are attempting to use a device framework in the simulator."


Could you please answer what is required to make that sample project run on both simulator and device as expected? Is there anything wrong in project's Build settings or am I supposed to somehow swap frameworks manually to make it run on both? I would appreciate any help with this issue.

I have filed a new bug report: 22201743. It is the same simple project with Watch target. Can you make it load the embedded framework on the Watch (the device)? If so, what am I doing wrong?

Hi Jasko,


I'm sorry I forgot to follup in forums. Yes, the radar was initially closed, but I reopened it.


I do believe that there is a bug here that Xcode will need to handle, but I'm not sure when that will be.


I believe that the issue has to do with how Xcode resolves which file to copy during the Copy Files Phase. If you look in that phase, you'll note that the device version of your framework is being copied instead of the simulator version. This is why the device framework is being copied when you are building for the sim. Xcode has some special rules for "fixing" cases like this for the simulator such that it will copy the sim framework instead of the device framework, but I think that that functionality only works right if the framework being copied is in the same project. In your case, you have both in separate projects (in the same workspace), and the build system doesn't know how to deal with that situation.


I suggest that as a workaround you combine these into the same project instead of using different projects in a workspace.

That is good to hear and it is nice to know that the bug is acknowledged.

Thanks for your workaround suggestions!

Hello

I have a very similar problem:

I have a workspace with 6 projects (mainly three projects which exit twice for iOS and tvOS):

  • a common framework
  • a second framework which depends on the common framework
  • an app which depends on the common and the second framework
    I have embedded the common framework and the second framework in the app's linking settings

On the iPhone my app runs when debugging AND when starting it directly

On the iPhone simulator and the tvOS simulator the app runs only when debugging from XCode. When I start it directly it crashes.

I don't have yet a apple TV and therefore I don't know if my app would run on the apple TV.

I have to set "Build active Architecture only" to NO but this had no effect.

As I can see there was no new answer on this thread since August 2015.

Therefore My question:

Has the bug been fixed in XCode 7.2 and if yes, what have I to do to make my app run on the simulator with my frameworks?

No, the bug has not yet been fixed. You will need to workaround it as described above.

Hi,

The recommended workaround is not possible in my case as I have an external dependency (Dropbox) which needs to be included as a subproject based on their documents (https://github.com/dropbox/SwiftyDropbox). Please look at the section "Manually add sub project". Including their code in my project causes naming collisions.

Hei guys,


I also have the same or a similar problem. I have a workspace with several app projects, framework projects and pods, where some framework project depends on other framework projects and the app projects depend on different framework projects and pods.


The framework dependencies are registered under Embedded Binaries on each target. There the path to each framework refers to build/Debug-iphoneos. And I have no idea how to change that, except if I manually edit the project file. And it looks like that path comes from this attribute sourceTree = BUILT_PRODUCTS_DIR;


In the Build settings of the app target where the dependencies are used, the Pre-configuration Build Products Path is set to $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME), but this always gets compiled into build/Debug-iphoneos


Is there any variable which at run phase will provide correctly iphoneos or iphonesimulator, depending whether the build is for device or simulator?


If I build and run for device, all frameworks build correctly and the app runs fine and can be debugged. But if I build and run for simulator, the framework builds for device are used at runtime instead of the ones built for simulator. So when I make a change in a framework, I need first to build the target for device, then run it on simulator. This is frustrating, to perform several operations, instead of just one.


Would be nice to have a solution for this, such as if the app runs on the simulator, it uses the framework builds for the simulator, instead of the ones build for device. And of course when run on the device to use the framwork builds for device. Is there any way to configure in XCode this approach?


Thank you,

Bogdan.

Framework does not load on simulator
 
 
Q