Build SPM Package via Fastlane in Xcode 11 does not work - ios

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.

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?

Swift package has bitcode disabled

I created a really simple Swift package, that contain only a few Objective-C source files, but when I try to build another project that it, it fail compiling because:
ld: bitcode bundle could not be generated because 'MySwiftPackage.o' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build file 'MySwiftPackage.o' for architecture arm64
I also tried to force Bitcode to be enable by adding settings:
cSettings: [.define("OTHER_CFLAGS", to: "-fembed-bitcode")] and .define("ENABLE_BITCODE", to: "YES") with no luck.
How can I identify what is causing the bitcode to be disabled ?
Here is my package.swift:
let package = Package(
name: "MySwiftPackage",
platforms: [.iOS(.v11)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "MySwiftPackage",
targets: ["MySwiftPackage"]),
],
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: "MySwiftPackage",
publicHeadersPath: "Public",
cSettings: [
.headerSearchPath("Internal")
])
]
)

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?

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