Search code examples
iosswiftfacebookswift-package-manager

Swift Package: Dependent Package can't be found. Remedy?


Background: I made a successful package <--- dependency earlier today using a different dependency as a 'proof of concept'.

However the Facebook SDK package dependency failed to be recognized:

enter image description here

Here is the package.swift:

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

import PackageDescription

let package = Package(
    name: "CVSFacebookAccess",
    platforms: [
           .iOS(.v13)
       ],
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "CVSFacebookAccess",
            targets: ["CVSFacebookAccess"]),
    ],
    dependencies: [
        .package(name: "Facebook", url: "https://github.com/facebook/facebook-ios-sdk.git", from: "11.0.1")
    ],
    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 this package depends on.
        .target(
            name: "CVSFacebookAccess",
            dependencies: ["Facebook"]),
        .testTarget(
            name: "CVSFacebookAccessTests",
            dependencies: ["CVSFacebookAccess"])
    ]
)

Here's the Facebook package:

enter image description here

Question:
Why can't the Facebook SDK be recognized?
I'm following the same Swift PM syntax as before.


Solution

  • Facebook SDK for iOS package includes several libraries such as: FacebookCore, FacebookLogin, FacebookShare, FacebookGamingServices and you should make a dependency to a needed one e.g.:

    ...
    .target(
        name: "YourPackage",
        dependencies: [.product(name: "FacebookLogin", package: "Facebook")]),
    ...
    

    Then you can use this library in your code:

    import FBSDKLoginKit
    
    func createLoginButton() -> FBLoginButton {
        return FBLoginButton()
    }