SPM showing duplicate target name fatalError - ios

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

Related

Getting "No such module" error when trying to create an xcframework with dependencies

I tried different ways with different configurations and cannot make it run. Here is what I tried while creating the xcframework:
Add 1 framework dependency as pod
Add 1 framework dependency as Swift package (MKRingProgressView) and created also a swift package marking the dependency in the package dependency as follows:
name: "FirstFramework",
platforms: [
.iOS(.v15)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "FirstFramework",
targets: ["FirstFramework"]),
],
dependencies: [
.package(url:
"https://github.com/maxkonovalov/MKRingProgressView.git",
from: "2.3.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.
.binaryTarget(
name: "FirstFramework",
path: "./Sources/FirstFramework.xcframework")
]
Set build libraries for distribution to YES
I am always getting the error "No such module MKRingProgressView" when adding my framework to a Test project, so its not recognising the dependency of my framework.
Any ideas?

Add package dependency on library product

How can I add a 3rd party package as a dependency to my package with which I distribute an xcframework?
So, I have my product:
products: [
.library(
name: "MY-FRAMEWORK",
targets: ["MY-FRAMEWORK", "SOME-3RD-PARTY-XCFRAMEWORK"]
)
]
my dependency, which I require:
dependencies: [
.package(url: "URL-TO-3RD-PARTY-PACKAGE", revision: "VERSION")
]
and my targets:
targets: [
.binaryTarget(
name: "MY-FRAMEWORK",
path: "PATH-TO-MY-FRAMEWORK"
),
.binaryTarget(
name: "SOME-3RD-PARTY-XCFRAMEWORK",
path: "PATH-TO-SOME-3RD-PARTY-XCFRAMEWORK"
)
]
While compiling, the Package expresses his concern of me not using the dependency in any of the declared targets, which is true. Also, when trying to integrate my package to an application, I get an error that it cannot be imported due to some errors.
1. No such module '3RD-PARTY-PACKAGE'
2. Failed to build module 'MY-FRAMEWORK' for importation due to the errors above; the textual interface may be broken by project issues or a compiler bug.
Now, How can I use a package dependency for my library with SPM?
Ok, so for the last 2 days I was searching and trying to find a solution to my problem and I stumbled over this post. Looks like SPM truly does not support dependencies on binary targets. So, in order to make it work I was forced to create a wrapper target within the Package.
I've created a group in the Package named 'Wrapper' and added two
files: one .h file into an include group and one .m file in the root, both of
them empty (just a comment with why I did this).
Added a new target, which is the 'Wrapper' in which I added the package dependency and any 3rd party binary targets I had.
Updated my library to use the 'Wrapper' as a target.
And that was it. Bellow, you can see the Package.swift file:
let package = Package(
name: "MY-FRAMEWORK",
products: [
.library(
name: "MY-FRAMEWORK",
targets: ["MY-FRAMEWORK", "Wrapper"]
)
],
dependencies: [
.package(name: "3RD-PARTY-PACKAGE", url: "URL-TO-3RD-PARTY-PACKAGE", revision: "VERSION")
],
targets: [
// .binaryTarget doesn't support package dependencies so we use a wrapper to fix this
.target(
name: "Wrapper",
dependencies: [
"SOME-3RD-PARTY-XCFRAMEWORK", "3RD-PARTY-PACKAGE"
],
path: "Wrapper"
),
.binaryTarget(
name: "MY-FRAMEWORK",
path: "MY-FRAMEWORK.xcframework"
)
.binaryTarget(
name: "SOME-3RD-PARTY-XCFRAMEWORK",
path: "PATH-TO-SOME-3RD-PARTY-XCFRAMEWORK.xcframework"
)
]
)
and also the project structure:
Hope it will help somebody in the future. All credits must be given to the original post I followed. Without it, I would have still be stuck and searching the web. Cheers mate!
// edit: You can also have just one swift file into the 'Wrapper' group, not only the two .h and .m files.

Swift SPM Package minimum iOS version not propagating

I am creating a simple Library Swift Package:
import PackageDescription
let package = Package(
name: "dpo-sdk-spm",
platforms: [
.iOS(.v10),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "dpo-sdk-spm",
targets: ["dpo-sdk-spm"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.2.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 which this package depends on.
.target(
name: "dpo-sdk-spm",
dependencies: ["Alamofire"]),
.testTarget(
name: "dpo-sdk-spmTests",
dependencies: ["dpo-sdk-spm"]),
]
)
I specifically did not create a project file, as working with that in source control is a pain - and its not required to develop a library that will be consumed in a iOS App, that will have the necessary build settings etc. My Library was created using swift package init --type library and here is the structure:
I specified under the platforms node iOS V10, then pushed the package to my git repo. I added my git account to Xcode, created a App project, added my package via Xcode 11's built in SPM and had no issues, however trying to build I got:
Showing All Messages The package product 'Alamofire' requires minimum platform version 10.0 for the iOS platform, but this target supports 8.0
I did specify the platform and version in my Package.swift, why is the build pipeline ignoring this variable?

How to link binary with libraries with SPM and Xcode11

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.

generation of project file for iOS

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.

Resources