swift-package-manager: SwiftPM can't properly download a binary dependency
Description
When adding https://bitbucket.org/usercentricscode/usercentrics-spm-sdk (a dependency that itself declares a zipped binary target), SwiftPM is unable to download the archive completely, reporting
Fetching https://bitbucket.org/usercentricscode/usercentrics-spm-sdk from cache
Fetched https://bitbucket.org/usercentricscode/usercentrics-spm-sdk (0.66s)
Computing version for https://bitbucket.org/usercentricscode/usercentrics-spm-sdk
Computed https://bitbucket.org/usercentricscode/usercentrics-spm-sdk at 2.8.1 (0.87s)
Creating working copy for https://bitbucket.org/usercentricscode/usercentrics-spm-sdk
Working copy of https://bitbucket.org/usercentricscode/usercentrics-spm-sdk resolved at 2.8.1
Downloading binary artifact https://bitbucket.org/usercentricscode/usercentrics-spm-sdk/downloads/Usercentrics-2.8.1.xcframework.zip
error: invalid archive returned from 'https://bitbucket.org/usercentricscode/usercentrics-spm-sdk/downloads/Usercentrics-2.8.1.xcframework.zip' which is required by binary target 'Usercentrics'
When investigating .build/artifacts/usercentrics-spm-sdk/Usercentrics, the Usercentrics-2.8.1.xcframework.zip file is not loaded completely (or correctly): wc reports only 6720 bytes, whereas the full archive is 12.4 MB.
unzip doesn’t work on it as a result with:
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
Downloading the archive by opening the link in a browser or by curl -L -O-ing the link loads the full archive, and unzip-ing it succeeds.
Expected behavior
The package loads, the archive unzips and the primary target compiles with no errors.
Actual behavior
See description.
Steps to reproduce
- Create an empty Swift executable and add
.package(url: "https://bitbucket.org/usercentricscode/usercentrics-spm-sdk", from: "2.0.0")
to dependencies.
- Run
swift build.
Swift Package Manager version/commit hash
Swift Package Manager - Swift 5.8.0
Swift & OS version (output of swift --version ; uname -a)
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100) Target: arm64-apple-macosx13.0 Darwin *** 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:53:44 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T8103 arm64
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 4
- Comments: 21 (3 by maintainers)
I also just faced the same issue on Xcode 15.3. but with a different dependency. Never encountered it on Xcode 15.2. or before.
Running
and reloading the packages worked for me.
Can’t reproduce this issue.
Maybe there is something wrong with your network connection or the cache.
You can remove all the cache by the following commands if you are on macOS.
Hi, I’m seeing this issue as well randomly for our binary dependencies (“invalid archive returned from …”) served from an internal Artifactory instance. Looking at the downloaded data in
~/Library/Caches/org.swift.swiftpm/artifactsshows the file is just a few bytes and the contents are plaintext/HTML, looks like auth errors are not handled properly when downloading binary dependencies.:Simply deleting the corresponding cached (and corrupt) file from the artifacts folder is enough for me to fix the issue. No need to nuke/reset the whole SPM cache.
I had the same issue. I solved it by removing my bitbucket username/password from keychain.
I’m getting this same error after following the official tutorial from Kotlin regarding exporting Multiplatform libraries to XCFrameworks (https://kotlinlang.org/docs/native-spm.html#create-the-xcframework-and-the-swift-package-manifest). I’m using Xcode 15.4 and Swift 5.10. I’ve cleared caches to no avail. I don’t have Bitbucket credentials in my Keychain. I didn’t try removing all my Github credentials from Keychain, but I suppose I can try that if we think it may do the trick.
Any ideas to resolve this error besides wiping out Bitbucket credentials?