Package.swift resolution fails with error about duplicate targets that aren’t duplicates

I have a package with two products and two targets, which have different names, but the package graph won’t resolve. Anyone know why it might think there’s two targets with the same name when there isn’t?

Could not resolve package graph. Cannot continue.

multiple targets named 'AppModule' in: 'examplekit', 'temporarypackagebuild-99f78d06-b5a3-418d-b906-75d721c6b6d4'; consider using the `moduleAliases` parameter in manifest to provide unique names
Package.swift
// swift-tools-version: 5.8

// WARNING:
// This file is automatically generated.
// Do not edit it by hand because the contents will be replaced.

import PackageDescription
import AppleProductTypes

let package = Package(
    name: "Example",
    platforms: [
        .iOS("16.0")
    ],
    products: [
        .library(
            name: "ExampleKit",
            targets: ["ExampleKit"]
        ),  
        .iOSApplication(
            name: "ExampleApp",
            targets: ["AppModule"],
            displayVersion: "1.0",
            bundleVersion: "1",
            appIcon: .placeholder(icon: .tv),
            accentColor: .presetColor(.brown),
            supportedDeviceFamilies: [
                .pad,
                .phone
            ],
            supportedInterfaceOrientations: [
                .portrait,
                .landscapeRight,
                .landscapeLeft,
                .portraitUpsideDown(.when(deviceFamilies: [.pad]))
            ]
        )
    ],
    targets: [ 
        .target(
            name: "ExampleKit",
            dependencies: []
        ),
        .executableTarget(
            name: "AppModule",
            dependencies: ["ExampleKit"],
            swiftSettings: [
                .enableUpcomingFeature("BareSlashRegexLiterals")
            ]
        )
    ]
)

What is temporarypackagebuild-99f78d06-b5a3-418d-b906-75d721c6b6d4? :thinking:

I was trying to figure that out as well, and it led me to a solution.

The default target name for the target that goes in the targets parameter of the .iOSApplication product in every Swift Playgrounds App package is “AppModule” and so because my package I was trying to add as a dependency also had an AppModule target, there was a conflict trying to build the graph.

I think that temporarypackagebuild-99f78d06-b5a3-418d-b906-75d721c6b6d4 must be the internal name of my app that Swift Playgrounds builds. By simply changing the target name in my Package.swift file for my combined executable and library project, another app is able to add it as a dependency and successfully resolve the graph.

I’m going to publish my findings on GitHub as soon as I finish some updates to my README.md file explaining how I did everything.

This all came about from my experimentation trying to find a way to develop libraries in Swift Playgrounds on iPad. I’ve written up a bit of a how-to and published a repository on GitHub so that others can see how I did it.

In-App Libraries for Swift Playgrounds

1 Like