无法使用Swift 4 Package Manager导入软件包 [英] Can't import packages using Swift 4 Package Manager
问题描述
尝试在计算机上使用Xcode-beta(v9)测试Swift 4,并将软件包导入测试项目时遇到问题:
Trying to test Swift 4 using Xcode-beta (v9) on my machine and having issues with importing packages into a test project:
- 使用
swift package init --type executable
启动的项目
- 更改了
Package.swift
并添加了2个项目进行试用:
- Initiated project using
swift package init --type executable
- Changed
Package.swift
and added 2 projects to try out:
Package.swift
// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "sampleproject",
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/IBM-Swift/Kitura.git", from: "1.7.6"),
.package(url: "https://github.com/Alamofire/Alamofire.git", from: "4.5.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: "sampleproject",
dependencies: []),
]
)
- 运行
swift build && swift package generate-xcodeproj
- 当我在Xcode-beta(v9)中打开项目并尝试导入Kitura或Alamofire时,出现了
No such module Kitura/Alamofire
错误消息 - 在终端中运行
swift build
会产生以下错误: - Run
swift build && swift package generate-xcodeproj
- When I open project in Xcode-beta(v9) and try to import Kitura or Alamofire, I'm getting
No such module Kitura/Alamofire
error message - Running
swift build
in terminal produces the following error:
编译Swift模块'investprosto'(1个来源) /Users/用户名/Projects/sampleproject/Sources/sampleproject/main.swift:1:8: 错误:没有这样的模块"Kitura"导入Kitura ^错误:终止(1):/Applications/Xcode- beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift- 构建工具-f/Users/username/Projects/sampleproject/.build/debug.yaml
Compile Swift Module 'investprosto' (1 sources) /Users/username/Projects/sampleproject/Sources/sampleproject/main.swift:1:8: error: no such module 'Kitura' import Kitura ^ error: terminated(1): /Applications/Xcode- beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift- build-tool -f /Users/username/Projects/sampleproject/.build/debug.yaml
依赖项虚拟文件夹包含具有相同软件包名称的目录,但它们为空.但是,.build\checkouts
和.build\repositories
包含程序包文件夹和相应的文件.
Dependencies virtual folder contains the directories with the same package names, but they are empty. However, .build\checkouts
and .build\repositories
contain packages folders and corresponding files.
我的系统配置中是否缺少某些内容?
Is there something I'm missing in my system's configuration?
推荐答案
原来,我还必须将依赖项包含在Package.swift的.target
中:
Turns out I had to also include the dependencies into the .target
of the Package.swift:
.target(named: "sampleproject", dependencies: ["Kitura", "Alamofire"])
然后再次构建项目.
这篇关于无法使用Swift 4 Package Manager导入软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!