I’m building a Swift framework which seems relatively simple. Then I needed to import CommonCrypto.
In the framework’s .h file I added the line
#import <CommonCrypto/CommonCrypto.h>
and included Security.framework in Link Binary with Libraries for the framework’s target.
When I build I get the following build error:
Include of non-modular header inside framework module ‘MyKit'
I’ve tried changing the Allow Non-modular Includes In Framework Modules to YES and NO and tried every combination for both the framework target and the project with no luck.
The MyKit.h’s Target Membership is set to Public and is ticked for MyKit too.
In Xcode 10.0 you'll be able to import CommonCrypto. As a work around I suggest inverting that dependency with a protocol and importing CommonCrypto in your framework client.
Related
My iOS app follows the "Photos Extension" template:
- A standalone, "container" app
- A Photo Editing extension, which is deployed by embedding it within the app above.
As suggested by Apple, code that is shared by both the app and the extension is gathered in a "core" cocoa framework that is embedded in the app, and to which both the app and the extension are linked.
So my Xcode project contains three targets:
The Framework target,
The Photo Editing Extension target, which links to the Framework but does not embed it, and
The App target, that embeds the Extension binary and the Framework binary, and links to both.
So far, so good.
Furthermore, the framework, the app, and the extension depend on two libraries MyLibraryA and MyLibraryB I have on Github (and in turn, MyLibraryA depends on MyLibraryB).
I originally set the dependency on MyLibraryA and MyLibraryB using Carthage, and everything was working fine.
Then, I decided to migrate my libraries A and B to Swift Packages.
I removed all Carthage-related settings in project and targets, framework search paths, etc. to make sure the Swift Package versions of my libraries are referenced and not the cached Carthage builds. I also deleted the Carthage directories (checkouts and build).
The Problem
When I build the shared/embedded Framework target, there are no issues.
But when I try to build either the App or App Extension targets, I get an error pointing to the shared frameworks Swift header (MyFramewor-Swift.h):
// ...
#import CoreGraphics;
#import CoreImage;
#import Foundation;
#import PhotosUI;
#import UIKit;
#import MyLibraryA; <-- Module 'MyLibraryA' Not Found
// ...
And the resulting:
Could not build Objective-C module 'MyFramework'
I know frameworks that are distributed as binaries cannot depend on Swift packages, but this embedded framework is compiled locally from source code and then embedded.
Perhaps there are some changes I can make to my setup on Xcode to get it to work?
I tried changing Enable Modules (C and Objective-C) to No in the Build Settings for the Framework target, to no avail.
You can currently set Install Objective-C Compatibility Header to No in Build Settings for modules that require a Swift Package dependency.
This's probably due to "Swift Packages" being "Swift", but still looks like a bug to me.
I've added Today extension to my Swift project, because of that I had to add it to targets for my Model class, which resulted in "Use of unresolved identifier..." when using libraries imported in ObjC bridging header. There's no issue for libraries written in Swift(imported directly in class). How can I solve this?
Is there a way to include a (non-Apple) framework in the "SupportCode.swift" file, in the Sources directory of a Playground?
While the framework is successfully imported when the import directive is placed in the Playground itself, I get a "No such module" error popping up when trying to import the same framework in SupportCode.swift.
I have my playground embedded in a workplace with the required frameworks added to it as well.
It is a hack. if you have file like "Parse.framework", just copy it to Xcode's system frameworks folder at "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks"
Now you can import this framework in playground just like any other system framework.
This didn't work until recently.
In order to import an external framework, you have to have the playground and your framework's target/project in an Xcode Workspace. Once you have that and you build the framework, you can just import the framework with an import.
If the playground is already in a project that is not a workspace file, you can convert the project to a workspace by choosing File > Save As Workspace then add the playground to that workspace.
You can also drag the framework project in the Finder to the project navigator in the workspace.
Open the playground file in the editor, and add import the custom framework using an import statement.
NOTE: These are the conditions.
The framework is in the same workspace as the playground.
The framework has already been built.
If it is an iOS framework, it is built for a 64-bit run-time
destination.
The workspace contains at least one active scheme that builds a
target.
If it is an Objective-C framework, it sets the Defines Module build
setting to Yes.
I have found this tutorial exactly how I was doing in my project.
https://m.pardel.net/using-3rd-party-frameworks-in-swift-playgrounds-fd415f6dba10
Please don't miss to add empty .swift file in your project as describe in this answer https://stackoverflow.com/a/47922876/855261
Here in this change-log(facebook change-log) it is stated that there is no need for objective-c bridging headers for swift.
But when I import FBSDKCoreKit in AppDelegate.swift these errors occur:
FBSDKAppLinkResolver.h
/Users/[username]/Documents/FacebookSDK/FBSDKCoreKit.framework/Headers/FBSDKAppLinkResolver.h:21:9:
Include of non-modular header inside framework module
'FBSDKCoreKit.FBSDKAppLinkResolver'
AppDelegate.swift
/Users/ashrafkholeif/Projects/xcode/TabbedApplicationTemplate/TabbedApplicationTemplate/TabbedApplicationTemplate/AppDelegate.swift:10:8:
Could not build Objective-C module 'FBSDKCoreKit'
edit: I even set the allow non-modular header inside framework modules to YES.
I had the exact same issue, the solution suggested on https://stackoverflow.com/a/29457503/425682 for an Objective-C project worked straight away on my Swift project:
Write a new file in the Facebook SDK folder under Bolts.framework/Modules/module.modulemap with the following content:
framework module Bolts {
umbrella header "Bolts.h"
export *
module * { export * }
explicit module BFAppLinkResolver {
header "BFAppLinkResolver.h"
link "BFAppLinkResolver"
export *
}}
This works without bridging headers (not needed anymore in version 4.0.1 of the SDK as mentioned by the OP), and without changes to the build settings.
EDIT: this bug is now fixed as of version 4.1 of the Facebook SDK, the library works without having to do any change.
This is a bug and Facebook is currently "assigning this to the appropriate team".
To get updates to this issue follow this link:
https://developers.facebook.com/bugs/362995353893156/
and hit subscribe.
Hopefully it doesn't take them too long to fix.
Also here is a related question recently posted on SO:
issue using FBSDK in swift iOS application
And some people have found success using the answers on this link (none have worked for me):
Facebook iOS8 SDK build module error for FBSDKCoreKit
The fix that worked for me:
rm -r ~/Documents/FacebookSDK/FBSDKCoreKit.framework/Modules/
Repeat with other frameworks.
Source: https://developers.facebook.com/docs/ios/troubleshooting#xcode_link
Create a new header file and import any objective-c code you are using, something like this..
#ifndef RJv1_RJBridge_h
#define RJv1_RJBridge_h
#import "NSMutableString+Obfuscated.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#endif
Then go to your Build Settings, look for Install Objective-C Compability Header, and make sure is set to Yes, then add a relative path to your header file in the field Objective-C Bridging Header.
Hope it works!
I am unable to compile the Glympse API for iOS due to 4 duplicate symbol errors in the framework. Like the example projects, I only import the GlympseLite.h header in my .pch file. Is anyone else having this issue?
One of the duplicate symbols is: __ZN7Glympse15ControlsFactory9showAboutERKNS_1OINS_12IGlympseLiteEEERKNS1_INS_8IGlympseEEE
How did you add GlympseKitLite into your project? Could you provide exact steps.
Which XCode version are you using?
Is there anything special about compiler/linker flags in your project?
Is it brand new or existing project?
Were you able to build sample projects provided with SDK?
I just confirmed that it compiles fine in a brand new projects. Here are the steps I followed:
Created new iOS project.
Dragged GlympseKitLite.embeddedframework (from SDK package) to Frameworks.
Added all required standard frameworks (CFNetwork, libz, CoreLocation, AddressBook, Security, EventKit, MapKit, MessageUI).
Added import entry to PCH file.
Called Glympse::LiteFactory::createGlympse(...);
In the mean time you can try the following. Set C Language Dialect, C++ Language Dialect and C++ Standard Library to Compiler Default. Let me know, if it helps.