Xcode 6 Error - “Missing Required Architecture i38

2019-01-24 16:23发布

问题:

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!

回答1:

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.



回答2:

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.