Swift SPM Package minimum iOS version not propagating - ios

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?

Related

SPM showing duplicate target name fatalError

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

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?

How can I include/bundle other Swift Package dependencies in a Swift Package that only contains binaryTargets (XCFrameworks)?

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"),
]
)

Build SPM Package via Fastlane in Xcode 11 does not work

I recently updated my package manager from Cocoapods to SPM because Xcode 11 already has it integrated. All my libraries already supported SPM, so I gave it a try. It all works fine during Xcode debug building, but I'm currently using Fastlane to automate the deployment and testing process, and my spm package fails during the testing step because my package doesn't support MacOs, but some dependencies do, so it somehow tries to force me to provide MacOS support. Unfortunately, I can't do that at the moment.
Do you have any idea if I'm using spm incorrectly, or if this is a bug of spm?
RxSwift also supports MacOs, but spm seems to have no problem with this particular package, only Kingfisher, RxSwiftExt and Willow are affected.
This is the error:
error: the product 'Kingfisher' requires minimum platform version 10.12 for macos platform
error: the product 'RxSwiftExt' requires minimum platform version 10.11 for macos platform
error: the product 'Willow' requires minimum platform version 10.11 for macos platform
This is my test statement from fastlane/swift
swift test --build-path ./build --package-path Core --configuration debug
And this is my Package.swift
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Core",
platforms: [
.iOS(.v11)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "Core",
type: .static,
targets: ["Core"]),
],
dependencies: [
// Local Dependencies
.package(path: "../RxKingfisher"),
// Remote Dependencies
.package(url: "https://github.com/Nike-Inc/Willow.git", Package.Dependency.Requirement.branch("master")),
.package(url: "https://github.com/ReactiveX/RxSwift", .branch("master")),
.package(url: "https://github.com/Quick/Nimble", .branch("master")),
.package(url: "https://github.com/Quick/Quick", .branch("master")),
.package(url: "https://github.com/realm/realm-cocoa", .branch("master")),
.package(url: "https://github.com/RxSwiftCommunity/RxRealm", .branch("master")),
.package(url: "https://github.com/RxSwiftCommunity/Action", .branch("master")),
.package(url: "https://github.com/RxSwiftCommunity/RxSwiftExt", .branch("master")),
.package(url: "https://github.com/onevcat/Kingfisher", .branch("master")),
.package(url: "https://github.com/Swinject/Swinject", .branch("master")),
.package(url: "https://github.com/RxSwiftCommunity/RxDataSources", .branch("master")),
// We need to change to the master branch after it was merged
.package(url: "https://github.com/jrendel/SwiftKeychainWrapper", Package.Dependency.Requirement.revision("8b0da97503be8db3b008581a30fdec71046136a7"))
],
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: "Core",
dependencies: [
// Remote
"Realm", "RealmSwift", "RxDataSources", "RxRealm", "Kingfisher", "RxSwift", "Action", "SwiftKeychainWrapper", "RxSwiftExt", "Swinject", "Willow",
// Locals
"RxKingfisher"
]),
.testTarget(
name: "CoreTests",
dependencies: ["Core", "Quick", "Nimble", "RxTest", "RxBlocking"])
]
)
Not sure about the syntax for swift command, but with xcodebuild setting the destination helped me.
xcodebuild -quiet clean test -project YourProject.xcodeproj -scheme YourScheme -destination 'platform=iOS Simulator,name=iPhone 8'
It seems that setting iOS for the platforms in Package.swift you will still have the Mac as available build target, which is at the beginning of the list and ends up being used in this case.

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