Build error, dependency in target requires explicit declaration

2.8k Views Asked by At

I used SPM to add packages to my project/App. In the package file I wanted to set target to a dependency. I get this error anytime the app tries to build.

// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription

let package = Package(
    name: "Sycra",
    products: [
      
        .library(
            name: "Sycra",
            targets: ["Sycra"]),
    ],
    dependencies: [
        .package(url: "https://github.com/NordicSemiconductor/IOS-nRF-Mesh-Library", .upToNextMinor(from: "3.2.0"))
        
    ],
    targets: [
         define a module or a test suite.
         
        .target(
            name: "Sycra",
            dependencies: ["NordicMesh"]),
        .testTarget(
            name: "SycraTests",
            dependencies: ["Sycra"]),
    ]
)

FILE STRUCTURE

FILE STRUCTURE IMG

ERORR

dependency 'NordicMesh' in target 'Sycra' requires explicit declaration; reference the package in the target dependency with '.product(name: "NordicMesh", package: "IOS-nRF-Mesh-Library")'

1

There are 1 best solutions below

2
LoVo On BEST ANSWER

Actually the error message already tells you what you have to do:

add

.product(name: "NordicMesh", package: "IOS-nRF-Mesh-Library") 

to the dependencies array:

    ... dependencies: [
        .product(name: "NordicMesh", package: "IOS-nRF-Mesh-Library") //<<< like this
        //other dependencies
    ]),