I want to migrate my CocoaPods to Swift Package Manager.
I'm getting the following error if I add Objective c Framework using SwiftPM
'RSKImageCropper/RSKImageCropper.h' file not found
If I install the framework using pods, everything runs fine.
pod 'RSKImageCropper', '~> 3.0.2'
What should i do to solve this error?
Package.swift of RSKImageCropper
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "RSKImageCropper",
platforms: [.iOS(.v9)],
products: [
.library(
name: "RSKImageCropper",
targets: ["RSKImageCropper"]),
],
targets: [
.target(
name: "RSKImageCropper",
path: "RSKImageCropper",
resources: [
.copy("RSKImageCropperStrings.bundle")
],
publicHeadersPath: "include"
),
]
)
Only headers in include folder is public and visible (publicHeadersPath key).
Fixed by changing
#import <RSKImageCropper/RSKImageCropper.h>
to
#import <RSKImageCropper/RSKImageCropViewController.h>
Related
I'm facing a problem with my lib using SPM.
I've developed it using a target into the project to test and works fine.
After finish I've added the lib using SPM into a final project using the branch develop and I was able to integrate lib and project.
When I saw that is all right, I made a tag from my lib and import into project using Up To Next Major (tag)
And using this way I'm getting this error:
I've checked all the code, compare Package.swift with other projects, change the name, change de folder and nothing.
Here my Package.swift
import PackageDescription
let package = Package(
name: "GloboUI",
platforms: [
.iOS(.v12)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "GloboUI", targets: ["GloboUI"]),
],
dependencies: [
.package(url: "https://github.com/rechsteiner/Parchment", exact: "3.1.0"),
.package(url: "https://github.com/onevcat/Kingfisher.git", from: "7.0.0"),
.package(url: "https://github.com/airbnb/lottie-ios.git", from: "4.0.0"),
.package(url: "https://github.com/googleads/swift-package-manager-google-mobile-ads.git", from: "9.0.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "GloboUI",
dependencies: [
.product(name: "GoogleMobileAds", package: "swift-package-manager-google-mobile-ads"),
.product(name: "Parchment", package: "Parchment"),
.product(name: "Kingfisher", package: "Kingfisher"),
.product(name: "Lottie", package: "lottie-ios")
],
path: "Sources/GloboUI"
)
]
)
I tried remove and change this path in target, change the target names...a lot of try
Here my folder structure of the lib
I've tried remove package.resolved form the main project, clean derivate data, cache, everything.
But I'm not know what is happening.
Anyone has a clue about this issue?
Regards
I want to create a Swift Package with binary targets which has sub dependencies. As the binary targets not support sub dependencies out of the box, I have created a wrapper target that depends on both the binary framework and other dependencies as described here
Package has a target called Logger.
CocoaLumberjack is a dependency of Logger.
Logger I have generated as XCFramwork and hosted in a server as publicly accessible. Below I have added a screenshot of the Xcode project which I used to generate XCFramwork.
Please refer to the Package manifest file.
import PackageDescription
let package = Package(
name: "spmpoc",
products: [
.library(
name: "Logger",
targets: ["LoggerTarget"]),
],
dependencies: [
.package(
name: "CocoaLumberjack",
url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git",
from: "3.6.1"),
],
targets: [
.target(
name: "LoggerTarget",
dependencies: [.target(name: "LoggerWrapper",
condition: .when(platforms: [.iOS]))]
),
.target(
name: "LoggerWrapper",
dependencies: [
.target(name: "Logger", condition: .when(platforms: [.iOS])),
.product(name: "CocoaLumberjack", package: "CocoaLumberjack")
]
),
.binaryTarget(name: "Logger", url: "https://mypath.com/Logger.xcframework.zip", checksum: "mychecksum")
]
)
I am able to add Swift package via Swift Package Manager, but When I try to import Logger module build error occured as ..../Logger.framework/Modules/Logger.swiftmodule/arm64-apple-ios.swiftinterface:4:8: No such module 'CocoaLumberjack'
Could someone please help me to figure out what could be the issue here?
Error
XCFramwork code snapshot for reference
Update:
I have change import to #_implementationOnly import in Logger.swift. Now in the generated .swiftinterface files does not contains the "import CocoaLumberjack" hence, compile error went away. However, app crashing because it is still looking for CocoaLumberjack.framework but its not available. '.../Library/Developer/Xcode/DerivedData/TestSPMApp-gfbagjtzjrrkjuathrrienvklwxs/Build/Products/Debug-iphonesimulator/CocoaLumberjack.framework/CocoaLumberjack' (no such file)
CocoaLumberJack added to Logger framework as a pod dependency. It seems, inside the Pods-Logger.xcconfig file it is referring to CocoaLumberjack.framework. I believe this causes the issue now.
I think the real issue here is that the dependencies don't need to be a part of your modules's public interface. You would need to replace all instances of import for the dependencies in your code to #_implementationOnly import
E.g.
#_implementationOnly import CocoaLumberjack
You can read more about #_implementationOnly here
I am creating Swift Packages from various Objective-C Frameworks (via use of XCFrameworks).
I successfully created the SPs, but have run into an issue when it comes to the other SP dependencies it relies on.
If I only add the WrapperPackage to my DemoApp, the compiler fails due to missing the SubDependencyPackage frameworks.
If I add the SubDependencyPackage via SPM to the DemoApp, it compiles just fine.
Is it possible / How can I...
properly bundle the "sub-dependencies" (SubDependencyPackage) into the Swift Package (WrapperPackage) so that in the DemoApp I only need to add WrapperPackage via SPM and all dependencies are resolved?
Workflow
DemoApp adds WrapperPackage as a SPM dependency.
WrapperPackage contains 2 XCFrameworks.
The 2 XCFrameworks were generated from 2 Objective-C Frameworks.
The Objective-C Frameworks have "sub-dependencies" of a separate Swift Package (SubDependencyPackage).
DemoApp
|
--WrapperPackage (XCFrameworks)
|
--SubDependencyPackage (XCFramework Dependencies)
WrapperPackage.swift
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "WrapperPackage",
platforms: [.iOS(.v13)],
products: [
.library(name: "ObjectiveCFramework1", targets: ["ObjectiveCFramework1"]),
.library(name: "ObjectiveCFramework2", targets: ["ObjectiveCFramework2"]),
],
dependencies: [
.package(name: "SubDependencyPackage.git", url: "git#github.com:user/SubDependencyPackage.git", .branch("main")),
],
targets: [
.binaryTarget(name: "ObjectiveCFramework1", path: "XCFrameworks/ObjectiveCFramework1.xcframework"),
.binaryTarget(name: "ObjectiveCFramework2", path: "XCFrameworks/ObjectiveCFramework2.xcframework"),
]
)
I started to use xcode 11 and I really like the new feature Swift Package Manger. I'm currently moving some of my project with it.
One of my framework is a a Swift wrapper around c++ libraries. Theses libraries are static libraries and I cannot change it.
I'm trying to configure the Package.swift but I didn't have any success.
I create 2 targets one with all the c++ and objective-c++ files and one other with the Swift file.
My package looks like this:
// swift-tools-version:5.1
import PackageDescription
let package = Package(
name: "MyFrameworkSDK",
platforms: [.iOS(.v9)],
products: [
.library(
name: "MyFrameworkSDK",
targets: ["MyFrameworkSDK"]
),
],
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire", from: "4.9.0"),
.package(url: "https://github.com/realm/realm-cocoa", from: "3.19.0"),
.package(url: "https://github.com/SwiftyJSON/SwiftyJSON", from: "5.0.0")
],
targets: [
.target(
name: "CPP",
path: "Sources/CPP",
cxxSettings: [
.headerSearchPath("signalProcessingSDK/include/SignalProcessing"),
.headerSearchPath("signalProcessingSDK/include/MyCPPSDK"),
.headerSearchPath("signalProcessingSDK/include"),
.headerSearchPath("CPPSignalProcessing/Codebridge"), // objective-c++ bridge
.headerSearchPath("CPPSignalProcessing/SignalProcessing.Cpp")
],
linkerSettings: [
.unsafeFlags(["-LsignalProcessingSDK/lib", "-llibAlgebra"]) // Thise line seems not to work in the client project
]
),
.target(
name: "MyFrameworkSDK",
dependencies: ["Alamofire", "RealmSwift", "SwiftyJSON", "CPP"],
path: "Sources/Swift"
)
],
swiftLanguageVersions: [.v5],
cxxLanguageStandard: .gnucxx11
)
I get the following error in the client:
d: warning: directory not found for option '-LsignalProcessingSDK/lib'
ld: library not found for -llibAlgebra
So my questions are:
1) Is "unsafeFlags" is the right command to use to link binary with libraries? If not what should I use?
2) Is the path given to "unsafeFlags" absolute or relative to the target?
unsafeFlags is an option to pass arbitrary flags. But you have to pass them in "command line" manner.
["-L", "signalProcessingSDK/lib", "-l", "libAlgebra"]
But I suppose that "relative paths" may be not the right choice for you.
When running:
swift package generate-xcodeproj
The fallowing defaults are set that create manual work every time we make changes the the Package.swift file.
The Base SDK is set to macOS instead of iOS
BaseSDKIssue
The Deployment targets are set to default values (iOS8 instead of iOS13 is the exact change)
DeploymentTargetsIssue
the modules where created with:
swift package init --name xyz --type library
//modify Package.swift to have dependencies xyz has
swift package generate-xcodeproj
How can I get the Base SDK set to iOS and the Deployment targets set to iOS13 when i run generate-xcodeproj
This is a simple structure of what I am trying to do SimpleStructure
Take a look at this page about setting up packages. In the swift package file you can define platforms, as seen here:
// swift-tools-version:5.1
import PackageDescription
let package = Package(
name: "MyLibrary",
platforms: [
.macOS(.v10_13),
],
products: [
.library(name: "MyLibrary", targets: ["MyLibrary"]),
],
dependencies: [
.package(url: "https://url/of/another/package/named/Utility", from: "1.0.0"),
],
targets: [
.target(name: "MyLibrary", dependencies: ["Utility"]),
.testTarget(name: "MyLibraryTests", dependencies: ["MyLibrary"]),
]
)
I'm not sure there is anything beyond that to set up the Xcode project, as swift packages in general are set up to be pretty platform agnostic.