When you have a dependency on a package with a range of versions, your package must set the supported platform version to the highest iOS version supported by the dependency. Otherwise it might error with something like The package product 'x' requires minimum platform version 16.0 for the iOS platform, but this target supports 15.0
Does anyone know a way around this? We’d like to have a range of versions of the package that support multiple iOS versions.
For example, GoogleMaps 9.4.0 supports iOS 15 and 10.4.0 supports iOS 16. However, my package, which depends on GoogleMaps, must support iOS 16 no matter what version of GoogleMaps it resolves to because it has the potential to resolve to 10.4.0 (and therefore require iOS 16).
If it resolves to GoogleMaps 9.4.0, it builds fine. If it resolves to 10.4.0, it’ll fail with this error:
error: The package product 'GoogleMaps' requires minimum platform version 16.0 for the iOS platform, but this target supports 15.0 (in target 'MyPackage' from project 'MyPackage')
In our particular use case, we want to create a Swift Package that wraps the GoogleMaps SDK and allows the client to control the version of GoogleMaps they use.
Here's a pared-down example Package.swift:
// swift-tools-version: 6.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "MyPackage",
platforms: [
.iOS("15.0")
],
products: [
.library(
name: "MyPackage",
targets: ["MyPackage"]
)
],
dependencies: [
.package(
url: "https://github.com/googlemaps/ios-maps-sdk",
"9.0.0"..<"11.0.0"
)
],
targets: [
.target(
name: "MyPackage",
dependencies: [
.product(
name: "GoogleMaps",
package: "ios-maps-sdk"
)
]
)
]
)
Build command:
xcodebuild build -scheme MyPackage -sdk "`xcrun --sdk iphonesimulator --show-sdk-path`" -destination "OS=15.5,name=iPhone 13"