I’m building a Swift Package distributed in the form of an XCFramework.
Importing the resulting binary inside a Swift application works just fine, but trying to import it inside of an Objective-c application does not. (file not found
or module not found
at import statement).
For testing purpose, I just drag n drop the XCFramework into my projects to import it.
What am I missing?
Here is the Swift Package definition:
let package = Package(
name: "MySDK",
platforms: [.iOS(.v14)],
products: [
.library(
name: "MySDK",
type: .dynamic,
targets: ["MySDK"]),
],
targets: [
.target(
name: "MySDK"),
.testTarget(
name: "MySDKTests",
dependencies: ["MySDK"]),
]
)
and here is the build script, using xcodebuild
(there is no intermediate Xcode project):
# Build for iOS simulator
xcodebuild
-workspace ${WORKSPACE}
-scheme ${SCHEME}
-configuration ${CONFIGURATION}
-destination "generic/platform=iOS Simulator"
-archivePath "${BUILD_DIR}/archives/${SCHEME}-Simulator"
BUILD_DIR=${BUILD_DIR}
SKIP_INSTALL=NO
DEFINES_MODULE=YES
SWIFT_INSTALL_OBJC_HEADER=YES
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
OTHER_SWIFT_FLAGS="-DCOCOAPODS"
# Build for iOS device
xcodebuild
-workspace ${WORKSPACE}
-scheme ${SCHEME}
-configuration ${CONFIGURATION}
-destination "generic/platform=iOS"
-archivePath "${BUILD_DIR}/archives/${SCHEME}-Device"
BUILD_DIR=${BUILD_DIR}
SKIP_INSTALL=NO
DEFINES_MODULE=YES
SWIFT_INSTALL_OBJC_HEADER=YES
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
OTHER_SWIFT_FLAGS="-DCOCOAPODS"
######################
# Create universal xcframework
######################
xcodebuild -create-xcframework
-framework ${SCHEME}/${BUILD_DIR}/Release-iphoneos/PackageFrameworks/${SCHEME}.framework
-framework ${SCHEME}/${BUILD_DIR}/Release-iphonesimulator/PackageFrameworks/${SCHEME}.framework
-output ${SCHEME}/${BUILD_DIR}/${SCHEME}.xcframework