[Solved] Error when adding KeychainSwift as Swift Package to my own Swift Package
Svantulden opened this issue · 2 comments
Description
When I added this library to my own Swift Package, I couldn't seem to link the library to my package. My setup in the Package.swift
:
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "MyTarget",
platforms: [
.iOS(.v13)
],
products: [
.library(
name: "MyTarget",
targets: ["MyTarget"]
),
],
dependencies: [
.package(url: "https://github.com/evgenyneu/keychain-swift.git", from: "20.0.0")
],
targets: [
.target(
name: "MyTarget",
dependencies: [
"KeychainSwift"
]
)
]
)
Which gave the error:
product 'KeychainSwift' required by package 'mytarget' target 'MyTarget' not found.
I tried many things, like changing the name to keychain-swift
, as the compiler sometimes gave an extra message at the error like: valid product names are 'keychain-swift'
, but that also didn't work.
Cause:
This issue happens when packages specify a different Package.name property compared to the github repo name. E.g. KeychainSwift's repo name is keychain-swift but the Package.swift says is called KeychainSwift.
Solution:
I'm posting this here so it hopefully helps someone else as well. I don't know if it should be updated in the Readme.md
, if so, I can make a PR for that.
The solution is to specify a name
as well for my Package.swift
:
dependencies: [
.package(name: "KeychainSwift", url: "https://github.com/evgenyneu/keychain-swift.git", from: "20.0.0")
],
targets: [
.target(
name: "MyTarget",
dependencies: [
"KeychainSwift"
]
)
]
Thanks for that, a PR would be great. :D
PR opened @ #170