iosswiftpackagedependenciesfastlane

Add own package dependencies to testTarget in package file


I'm developing a Swift app and using my own written packages in it. Everything works fine until I attempt to run tests via Fastlane. It throws an error saying, Could not resolve package dependencies. However, when I run the tests from Xcode, everything works smoothly.

If I run the tests from xCode, it works well.

My package file:

import PackageDescription

let package = Package(
    name: "Package_Name",
    platforms: [.iOS(.v17)],
    products: [
        .library(name: "Package_Name", targets: ["Package_Name"]),
    ],
    dependencies: [
        .package(name: "ConfigManager", path: "/Packages/ConfigManager"),
        .package(name: "NetworkManager", path: "/Packages/NetworkManager"),
        .package(name: "Notifications", path: "/Packages/Notifications")
    ],
    targets: [
        .target(
            name: "Package_Name",
            dependencies: ["ConfigManager",
                           "NetworkManager",
                           "Notifications"],
            resources: [
                .process("Resources")
            ]),
        .testTarget(
            name: "Package_NameTests",
            dependencies: ["Package_Name",
                           "ConfigManager",
                           "NetworkManager",
                           "Notifications"],
        resources: [
            .process("Resources")
        ]),
    ]
)

Error message from fastlane:

▸ xcodebuild: error: Could not resolve package dependencies:
▸   the package at '/Packages/ConfigManager' cannot be accessed (Error Domain=NSCocoaErrorDomain Code=260 "The folder “ConfigManager” doesn’t exist." UserInfo={NSFilePath=/Packages/ConfigManager, NSUserStringVariant=(
▸     Folder
▸ ), NSUnderlyingError=0x6000007aba20 {Error Domain=NSOSStatusErrorDomain Code=-43 "fnfErr: File not found"}})

lane in Fastfile

lane :testPackage do
      puts 'Test ' + "Package_Name"
      scan(
          package_path: './Packages/' + "Package_Name",
          scheme: "Package_NameTests",
          devices: ["iPhone 15"],
          output_style: 'standard',
          output_directory: './fastlane/report/' + "Package_Name"  + '/',
          code_coverage: true,
          result_bundle: true,
          fail_build: false,
          clean: true,
          configuration: "Debug"
        )
    end

Thank you in advance,


Solution

  • Package_Name's dependencies are listed as absolute paths.

        dependencies: [
            .package(name: "ConfigManager", path: "/Packages/ConfigManager"),
            .package(name: "NetworkManager", path: "/Packages/NetworkManager"),
            .package(name: "Notifications", path: "/Packages/Notifications")
        ],
    

    This seems fishy to me. Maybe you meant for the dependencies location to be in a subfolder from the current Package.swift file? That would be ./Packages/...

    EDIT: Your comment indicates this answer was helpful and set you off on the right path. It sounds like, in your case, the dependent packages were located one directory higher from your working directory - ../ConfigManager, ../NetworkManager, and ../Notifications.