5

I have created a custom Objective-C framework. I would like to import it into any given iOS project and use its provided functionality on both the iOS Simulator and an actual device. To import the framework, I link it using the Build Phases > Link Binary With Libraries setting in the app's target. I'm then able to import it into one of my classes with this statement:

#import <CustomFramework/CustomFramework.h>

I can instantiate my framework's classes just fine, but when I try to run my project on a device, I get the following error message:

dyld: Library not loaded: @rpath/CustomFramework.framework/CustomFramework
Referenced from: /var/mobile/Applications/A61E882D-481A-4C0B-B4FD-69F5D24968BF/TestApp.app/TestApp
Reason: image not found

And if I try to run it on the simulator, I get a different error message:

ld: warning: ignoring file /Users/user/Desktop/CustomFramework.framework/CustomFramework, missing required architecture i386 in file /Users/user/Desktop/CustomFramework.framework/CustomFramework (2 slices)
Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_CustomFramework", referenced from:
      objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This occurs when I instantiate a class from the framework. If I import the framework but don't actually use it, my app builds successfully. It just errors whenever I instantiate a class from the framework for some reason.

To get the app to build on a device, I followed this SO answer. Instead of linking the framework, I added a new Copy Files phase in the target's Build Phases setting, set the Destination to Framework, and added my framework.

That works great; however, I'd like to test my app on the iOS Simulator as well. When I try to run my app on the simulator, I still get the "missing required architecture i386" error. I've tried the solutions proposed at just about every related SO topic I could find, and nothing has helped me resolve this issue.

Please note that I am trying to use my custom framework in a new Xcode project, so none of the app/build settings have been changed from their defaults.

How can I fix this error so that I can run my app on both the iOS Simulator and a device with my framework included in the project? Any insight would be greatly appreciated!

Community
  • 1
  • 1
Alexander
  • 3,959
  • 2
  • 31
  • 58

2 Answers2

5

The issue was that the framework was not compiled for the iOS Simulator's architecture, which is i386. Xcode only compiles a framework for the target architecture, so if I built the framework for the iOS Simulator, it wouldn't work on a device, and if I built the framework for a device, it wouldn't work on the iOS Simulator.

I created my framework from scratch with help from this tutorial: http://www.raywenderlich.com/65964/create-a-framework-for-ios

The multi-architecture build script is what allowed my framework to run on both the iOS Simulator and a device.

Alexander
  • 3,959
  • 2
  • 31
  • 58
  • 2
    Thank you for the answer! Still it's preposterous that as far as 2015, we still have to resort to manual building to get a decent framework (the tutorial is like, 10 pages long?!). Shame on you, Apple! – Rick77 May 12 '15 at 08:24
  • 1
    @Rick77 Glad to help! I completely agree. I also develop apps for Windows and Windows Phone, and I haven't even had to think about this on those platforms. – Alexander May 12 '15 at 12:49
  • @Alexander My framework was not compiled for the iOS Simulator's architecture.It supports only device, How to make my framework work in Simulator.I am using Framework. – jerfin May 03 '16 at 07:33
  • 1
    @Arun If you are making your own framework, then you will want to follow the Ray Wenderlich tutorial in my answer. The tutorial includes a multi-architecture build script that, when integrated in your build process, will work on both the device and the simulator. If you aren't creating your own framework, you will need to ask the developer of that framework to compile it to support multiple architectures. – Alexander May 04 '16 at 13:08
  • @Alexander Thanks for you answer helped me. – jerfin May 05 '16 at 05:48
  • @Alexander Thanks for u r explanation. I'm m also facing the same problem. But mine is not own created framework. – Ramakrishna Dec 01 '16 at 06:11
0

I encountered this same problem with Xcode 7.1 when trying to build for the simulator. Someone else said it worked for them under Xcode 8.2.1, so I tried building/running there and it worked. I didn't have to change targets or anything in my project.

So try upgrading your Xcode if you can, you will presumably get additional bug fixes as well.

toddkaufmann
  • 315
  • 2
  • 10