Swift Package: Module not found - ios

I have created a non-syslib C module (let's call it CModule) and packaged it with Swift Package Manager such that my code is in $(package_directory)/Sources/CModule and my Package.swift in the aforementioned parent directory contains:
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "CModule",
products: [
.library(
name: "CModule",
type: .dynamic,
targets: ["CModule"]),
],
targets: [
.target(
name: "CModule",
dependencies: [],
path: "Sources",
cSettings: [
.headerSearchPath("CModule")])
]
)
The package compiles without errors, but after adding it to another Swift project with File -> Swift Packages -> Add Package Dependency and inputting the local repo (file:///Users...etc), which does give me the right target, doing import CModule within this new project gives me the Module not found error.
I have already relaunched Xcode, did Clean Build Folder followed by a normal Build, and tried another approach such as it was described in How to make custom C code into a SwiftPM package?

Try these steps:
1. File -> Swift Packages -> Reset Package Caches
After packages are reset, follow below steps:
2. File -> Swift Packages -> Update to Latest Package Versions

Related

SPM showing duplicate target name fatalError

I'm facing a problem with my lib using SPM.
I've developed it using a target into the project to test and works fine.
After finish I've added the lib using SPM into a final project using the branch develop and I was able to integrate lib and project.
When I saw that is all right, I made a tag from my lib and import into project using Up To Next Major (tag)
And using this way I'm getting this error:
I've checked all the code, compare Package.swift with other projects, change the name, change de folder and nothing.
Here my Package.swift
import PackageDescription
let package = Package(
name: "GloboUI",
platforms: [
.iOS(.v12)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "GloboUI", targets: ["GloboUI"]),
],
dependencies: [
.package(url: "https://github.com/rechsteiner/Parchment", exact: "3.1.0"),
.package(url: "https://github.com/onevcat/Kingfisher.git", from: "7.0.0"),
.package(url: "https://github.com/airbnb/lottie-ios.git", from: "4.0.0"),
.package(url: "https://github.com/googleads/swift-package-manager-google-mobile-ads.git", from: "9.0.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 this package depends on.
.target(
name: "GloboUI",
dependencies: [
.product(name: "GoogleMobileAds", package: "swift-package-manager-google-mobile-ads"),
.product(name: "Parchment", package: "Parchment"),
.product(name: "Kingfisher", package: "Kingfisher"),
.product(name: "Lottie", package: "lottie-ios")
],
path: "Sources/GloboUI"
)
]
)
I tried remove and change this path in target, change the target names...a lot of try
Here my folder structure of the lib
I've tried remove package.resolved form the main project, clean derivate data, cache, everything.
But I'm not know what is happening.
Anyone has a clue about this issue?
Regards

Add dependencies to binary targets in Swift Package Manager

I want to create a Swift Package with binary targets which has sub dependencies. As the binary targets not support sub dependencies out of the box, I have created a wrapper target that depends on both the binary framework and other dependencies as described here
Package has a target called Logger.
CocoaLumberjack is a dependency of Logger.
Logger I have generated as XCFramwork and hosted in a server as publicly accessible. Below I have added a screenshot of the Xcode project which I used to generate XCFramwork.
Please refer to the Package manifest file.
import PackageDescription
let package = Package(
name: "spmpoc",
products: [
.library(
name: "Logger",
targets: ["LoggerTarget"]),
],
dependencies: [
.package(
name: "CocoaLumberjack",
url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git",
from: "3.6.1"),
],
targets: [
.target(
name: "LoggerTarget",
dependencies: [.target(name: "LoggerWrapper",
condition: .when(platforms: [.iOS]))]
),
.target(
name: "LoggerWrapper",
dependencies: [
.target(name: "Logger", condition: .when(platforms: [.iOS])),
.product(name: "CocoaLumberjack", package: "CocoaLumberjack")
]
),
.binaryTarget(name: "Logger", url: "https://mypath.com/Logger.xcframework.zip", checksum: "mychecksum")
]
)
I am able to add Swift package via Swift Package Manager, but When I try to import Logger module build error occured as ..../Logger.framework/Modules/Logger.swiftmodule/arm64-apple-ios.swiftinterface:4:8: No such module 'CocoaLumberjack'
Could someone please help me to figure out what could be the issue here?
Error
XCFramwork code snapshot for reference
Update:
I have change import to #_implementationOnly import in Logger.swift. Now in the generated .swiftinterface files does not contains the "import CocoaLumberjack" hence, compile error went away. However, app crashing because it is still looking for CocoaLumberjack.framework but its not available. '.../Library/Developer/Xcode/DerivedData/TestSPMApp-gfbagjtzjrrkjuathrrienvklwxs/Build/Products/Debug-iphonesimulator/CocoaLumberjack.framework/CocoaLumberjack' (no such file)
CocoaLumberJack added to Logger framework as a pod dependency. It seems, inside the Pods-Logger.xcconfig file it is referring to CocoaLumberjack.framework. I believe this causes the issue now.
I think the real issue here is that the dependencies don't need to be a part of your modules's public interface. You would need to replace all instances of import for the dependencies in your code to #_implementationOnly import
E.g.
#_implementationOnly import CocoaLumberjack
You can read more about #_implementationOnly here

How can I include/bundle other Swift Package dependencies in a Swift Package that only contains binaryTargets (XCFrameworks)?

I am creating Swift Packages from various Objective-C Frameworks (via use of XCFrameworks).
I successfully created the SPs, but have run into an issue when it comes to the other SP dependencies it relies on.
If I only add the WrapperPackage to my DemoApp, the compiler fails due to missing the SubDependencyPackage frameworks.
If I add the SubDependencyPackage via SPM to the DemoApp, it compiles just fine.
Is it possible / How can I...
properly bundle the "sub-dependencies" (SubDependencyPackage) into the Swift Package (WrapperPackage) so that in the DemoApp I only need to add WrapperPackage via SPM and all dependencies are resolved?
Workflow
DemoApp adds WrapperPackage as a SPM dependency.
WrapperPackage contains 2 XCFrameworks.
The 2 XCFrameworks were generated from 2 Objective-C Frameworks.
The Objective-C Frameworks have "sub-dependencies" of a separate Swift Package (SubDependencyPackage).
DemoApp
|
--WrapperPackage (XCFrameworks)
|
--SubDependencyPackage (XCFramework Dependencies)
WrapperPackage.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: "WrapperPackage",
platforms: [.iOS(.v13)],
products: [
.library(name: "ObjectiveCFramework1", targets: ["ObjectiveCFramework1"]),
.library(name: "ObjectiveCFramework2", targets: ["ObjectiveCFramework2"]),
],
dependencies: [
.package(name: "SubDependencyPackage.git", url: "git#github.com:user/SubDependencyPackage.git", .branch("main")),
],
targets: [
.binaryTarget(name: "ObjectiveCFramework1", path: "XCFrameworks/ObjectiveCFramework1.xcframework"),
.binaryTarget(name: "ObjectiveCFramework2", path: "XCFrameworks/ObjectiveCFramework2.xcframework"),
]
)

Swift Package build failure. Remedy?

Background:
This code is based on dated PM example written by Mattt years ago.
Goal: I'm trying to get importing to work, so I created a basic package; based on Mattt's working package. His example works flawlessly. Hence attempting to recreate from scratch.
Scenario:
I've created a basic package.
I've added a Dependency.
I've added an 'import <Dependency' in package source but I'm getting the following build failure:
Here's the actual code:
// 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: "RicPackage",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "RicPackage",
targets: ["RicPackage"]),
],
dependencies: [
.package(name: "PlayingCard", url: "https://github.com/apple/example-package-playingcard.git", from: "3.0.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 this package depends on.
.target(
name: "RicPackage",
dependencies: ["PlayingCard"]),
.testTarget(
name: "RicPackageTests",
dependencies: ["RicPackage"]),
]
)
Question:
Why is this happening?
What am I missing?
Gremlins?
I played around with the package header to notice changes in syntax acceptance. Then I reverted to the latest and did a recompile.
This time it SUCCEEDED.
I did a Xcode restart just to be sure this is true.
I rebuild... again SUCCEEDED.
Note: be sure to be aware of the package header the says the version of the package. The package syntax (amongst other things) change/version.

Swift SPM Package minimum iOS version not propagating

I am creating a simple Library Swift Package:
import PackageDescription
let package = Package(
name: "dpo-sdk-spm",
platforms: [
.iOS(.v10),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "dpo-sdk-spm",
targets: ["dpo-sdk-spm"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.2.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: "dpo-sdk-spm",
dependencies: ["Alamofire"]),
.testTarget(
name: "dpo-sdk-spmTests",
dependencies: ["dpo-sdk-spm"]),
]
)
I specifically did not create a project file, as working with that in source control is a pain - and its not required to develop a library that will be consumed in a iOS App, that will have the necessary build settings etc. My Library was created using swift package init --type library and here is the structure:
I specified under the platforms node iOS V10, then pushed the package to my git repo. I added my git account to Xcode, created a App project, added my package via Xcode 11's built in SPM and had no issues, however trying to build I got:
Showing All Messages The package product 'Alamofire' requires minimum platform version 10.0 for the iOS platform, but this target supports 8.0
I did specify the platform and version in my Package.swift, why is the build pipeline ignoring this variable?

Resources