Can't import packages using Swift 4 Package Manager

Timka picture Timka · Jul 11, 2017 · Viewed 10.6k times · Source

Trying to test Swift 4 using Xcode-beta (v9) on my machine and having issues with importing packages into a test project:

  • 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: []),
    ]
)
  • 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:

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

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?

Answer

Timka picture Timka · Jul 11, 2017

Turns out I had to also include the dependencies into the .target of the Package.swift:

.target(named: "sampleproject", dependencies: ["Kitura", "Alamofire"])

and build the project again.