'Adding XCFramework to framework project gives error: Include of non-modular header inside framework module
We’ve been successfully using the ACRCloud iOS SDK in our iOS app. You simply download it, add their XCFramework to your project, and add the following to your bridging header:
#import "ACRCloudConfig.h"
#import “ACRCloudRecognition.h"
We now need to move our code that uses ACRCloud into a framework. I am getting an error though. This is what I did:
- In Xcode select File > New > Project > iOS > Framework
- Set Language to Swift and create it
- Drag and drop the ACRCloudSDK.xcframework into the project
- In the MyFramework.h file, add the import statements from above - I understand frameworks do not support bridging headers so this is the location they should be added instead
- Add a test class in a new Swift file - seems this is required
class TestClass {
var acrClient: ACRCloudRecognition?
}
- Build the framework with command B
Result: I get the following errors:
/Users/Admin/Downloads/MyFramework/MyFramework/MyFramework.h:19:9: Include of non-modular header inside framework module 'MyFramework': '/Users/Admin/Library/Developer/Xcode/DerivedData/MyFramework-gcmepfcyafmmyugjhujjgyybneuo/Build/Products/Debug-iphonesimulator/include/ACRCloudRecognition.h’
Could not build Objective-C module ‘MyFramework'
I confirmed that the MyFramework.h file is in Build Phases > Headers > Public (nothing is in Project). I also tried changing Allow Non-modular Includes In Framework Modules to Yes. What is needed to make this work? Thanks!
Solution 1:[1]
The folks at ACRCloud got this working. Here's what I had to do:
- In Xcode select File > New > Project > iOS > Framework
- Set Language to Swift and create it
- Drag and drop the ACRCloudSDK.xcframework into the project
- In Finder, open the xcframework > ios-arm64_armv7 > Headers and drag and drop those two files into your project alongside the xcframework
- In the MyFramework.h file, import those two header files
#import "ACRCloudConfig.h"
#import "ACRCloudRecognition.h"
- In your framework target's Build Phases > Link Binary With Libraries, make sure ACRCloudSDK.xcframework is Required
- Expand the Headers section in Build Phases and move the header files from Project to Public
You should now be able to build the framework without error and use ACRCloudRecognition without issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |