Xcode Cloud Can't Upload Archive that has embeded Package Dependencies - ios

On the post-actions after archiving the app on Xcode Cloud, There was a task that set to upload to TestFlight. It failed with an error.
ITMS-90334: Invalid Code Signature Identifier. The identifier “XyzSDK-55554944d176df9a74f43236a8f1ccb71ea4d480” in your code signature for “XyzSDK” must match its Bundle Identifier “XyzSDK”
XyzSDK is a package that import to the app via Swift Package Manager (right-click on project >> add package >> insert repository url).
I also wonder why a package that imported to the project had bundle identifier with a generated id (55554944d176df9a74f43236a8f1ccb71ea4d480) after the archive phase. that cause the error. It seems hard to edit the bundle identifier since it's a package dependency.
Is there anyway to disable this? Are there any missing things I have to do after import a package dependency? Or Is it a Xcode cloud bug?
P.S. I have sent this issue to Apple via Feedback Assistant but there is no response for now.

Seems like this is caused by having a dynamic library as a Swift Package Manager dependency. If you're targeting iOS, you'll need to make sure your dependencies are building as static libraries.
Some Swift packages have multiple targets to this effect, so depending on the specifics of the dependency, you may have to replace your Package.swift's targets -> .target -> dependencies from something like ["XyzLib"] to be something like [ .product(name: "XyzLibStatic", package: "xyzLib") ].
This was happening to me today for example as I had this library as an SPM dependency: https://github.com/launchdarkly/swift-eventsource/blob/master/Package.swift
The fix was to target the type: .static version of the dependency (LDSwiftEventSourceStatic).

Figured out a fix here if you are willing to change your frameworks to static/do not embed: https://stackoverflow.com/a/73653319/1920561

Related

Flutter Plugin -- build for iOS works in xCode, but doesn't work with flutter build because of package dependency

I am developing a Flutter plugin, which requires a third party library. This library is hosted on GitHub, and to add it to my project, they tell me to use XCode's package manager (File -> Add Packages). When I do it this way, I can use the package just fine, compile my code and run it on my iPad. However, when I try to use "flutter build ios", it doesn't work.
When building, I see a series of (with actual framework names and file names instead of ...):
note: Removed stale file ...
note: Removed stale file ...
note: Removed stale file ...
Then eventually I will see that the compilation has failed due to being unable to import the library I need. Additionally, when I go back into XCode, I find that the package dependency I had installed is no longer there.
So, what I suspect is happening, is when Flutter builds it is cleaning up all the old frameworks, and running its own pod install. However, since my package is not part of my podspec file, it is being left behind. I am unsure how to get this to work. I've tried adding a line in my podspec file like:
s.dependency 'PackageName'
s.source { :git => 'https://linkToTheGitRepo' }
and then running pod repo update, but when I go to build I still get "Unable to find a specification for PackageName depended upon by my_plugin".
At this point, I just build in XCode and then don't touch it, however this has also caused issues when I go to use the plugin later in another project -- I also cannot use flutter build ios in that project, and I have to do it through XCode. This is an annoying workaround, since I lose the hot reload ability and other nice features of working with Flutter. Any suggestions are appreciated. Thanks.

Swift Package Manager - copy files build phase for a dynamic dependency

I'm working on an iOS application, and the core of it we are going to open source as a standalone Swift Package for other developers.
The Swift Package depends on Sodium (https://github.com/jedisct1/swift-sodium). There is an issue with this library when using SPM, that during archive (and sometimes during compile locally in Xcode) that it will fail to find the embedded CLibrary, making it impossible to release to the app store if using this package, or having it embedded in your own. (This is recorded as a bug in SPM / Xcode but will take sometime to fix)
Someone made a Fork that solves some of the problems here. They solved the issue by splitting the Clibrary out as a separate .xcframework hosted somewhere else. Then making a new Package.swift that imports it as an external dependency. This updated Sodium Package has been set to type dynamic.
Including this in my Swift package, and then including my package in my iOS application ... it builds fine, runs in Xcode fine, runs on simulators fine, throws no errors when exporting or upload to TestFlight.
However after downloading from TestFlight, I get this error saying the Sodium framework can't be found
Termination Description: DYLD, dyld: Using shared cache: <hash> | dependent dylib `#rpath/Sodium.framework/Sodium` not found for <path-to-ipa>/<appname> tried but didn't find <path-to-sodium>
Using other dependency management tools, the solution is usually to add a "Copy Files Build Phase" to the iOS application's xcode project and add the framework. If I try to do this in my Xcode project, I can't find the Sodium framework, and I can't find a way to tell SPM to copy the framework inside the Package.swift.
How do I update my Package.swift so that it copies this framework for any app that uses it?
If thats not possible, how do I copy it inside the Xcode project? Its not visible in the dropdown
Currently my Package.swift looks like this:
import PackageDescription
let package = Package(
name: "<package-name>",
platforms: [.iOS(.v14)],
products: [
.library(name: "<package-name>", targets: ["<package-name>"]),
],
dependencies: [
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.2.1"),
.package(name: "Sodium", url: "https://github.com/junelife/swift-sodium.git", .branch("spm"))
],
targets: [
.target(
name: "<package-name>",
dependencies: [
"Sodium",
"BigInt",
]
),
.testTarget(
name: "<package-name>Tests",
dependencies: ["<package-name>"]
),
]
)
Workaround for now:
If I import the dynamic package into the iOS app as well, I get the option to "Embed and sign" next to the Sodium framework under Frameworks, Libraries, and Embedded Content under the general tab of the target. Which forces it into the bundle.
Note:
I attempted to make my Package Dynamic, to see if including it would embed everything automatically and avoid having to give users instructions to users to embed it separately. But it didn't work. It only embedded my package and not the dynamic dependency.
If anyone has a way to modify a Package.swift to force it to embed dynamic dependencies ... or knows how to clean up this mess entirely. Please comment

Module 'SocketIO' was not compiled with library evolution support; using it means binary compatibility for framework can't be guaranteed

When I install SocketIO in my Framework project using Swift Package Manager the build is successful but there is a warning "Module 'SocketIO' was not compiled with library evolution support; using it means binary compatibility for 'framework name' can't be guaranteed".
Note: I enabled Build Libraries for Distribution to YES in both project target. Socket IO framework I installed in my framework project using Swift Package Manager.(Using cocoa pods xcframework generation is not working for SocketIO).
Eventually I have to generate XCFramework out of this framework project, even If I generate XCFramework with the warning the final .xcframework is not support when I import it any project. Xcode says "Fail to load module SocketIO"
Can any one help me on this? I tried many possibilities from last one week.
Thanks in advance.
I have the same problem. I think, that we have to wait for Xcode 11.4 and Swift 5.2 release. Then, we can try to create Package.swift for our xcframework and list all dependencies there e.g. SocketIO.
The client app will fetch this manifest and resolve all dependencies.

No such module "PackageDescription"

I just started with swift 3 and made a simple app in xcode using Swift 3.0 . Now i want to add a third party library using Swift Package Manager . I am following installation method given in this link . I created Package.swift file which looks like this
import PackageDescription
let package = Package (
name : "SwiftPM",
dependencies : [
.Package(url: "https://github.com/ArtSabintsev/Siren.git", majorVersion: 1)
])
but i get error No such module "PackageDescription"
The Swift Package Manager and Xcode are orthogonal. That is, you can't expect to compile Package.swift in Xcode; it simply won't work. Instead, until Xcode supports the package manager, you need to have two distinct builds - one with the package manager and one with Xcode.
So, using the Swift Package Manager, once you've defined Package.swift and formulated your directory structure as expected by the package manger, you perform simply:
swift build
Then for Xcode, you create an Xcode project that uses your source code, but not Package.swift. You'll need to clone the Siren.git project, explicitly - into your Xcode build's source files.
Swift 3/4
Navigate to your project folder through a terminal and run these commands swift package init --type library first and then swift package generate-xcodeproj
Reference
For me the issue turned out to be Target Membership. I created the Package.swift file manually inside an iOS app project.
Solution:
Select and go to the Package.swift file
Open the File Inspector on the right side
Deselect any modules inside Target Membership section
Refer to the solution in this link:
https://forums.kodeco.com/t/server-error-no-such-module-packagedescription/177438
Command:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
For other people who faced the same error as this:
Fix your Package.swift syntax
I got this error because Xcode hadn't parsed Package.swift fully yet, because of syntax errors.
In my case, I had a .target(name: "name-of-target", dependencies: [""]). As soon as I removed the empty dependency string (""), Xcode immediately parsed the file, and the error disappeared. Remember to save the file though.
Also, GoZoner and Pratiks answers are outdated:
Xcode has integration with Swift Packages now (as shown above)
swift package generate-xcodeproj is deprecated, shown by the error message when using it:
warning: Xcode can open and build Swift Packages directly. 'generate-xcodeproj' is no longer needed and will be deprecated soon.
More information about what that is, and why its gone here.

How do I use SwiftyJSON in my iOS App?

I recently added SwiftyJSON into my xCode project using Carthage.
Cartfile
$ cat Cartfile
github "SwiftyJSON/SwiftyJSON" >= 2.1.2
I ran this command to install SwiftyJSON
$ carthage update
I added the built Framework to my xCode project
I imported the Framework at the top of my project
But I still get this error:
Use of unresolved identifier 'JSON'
Seriously, what am I doing wrong? I'm new to iOS development.
UPDATE: I tried removing the Frameworks and re-dragging the frameworks to the Linked Frameworks and Libraries and Adding the "Run Script" section to "Build Phases" as the instructions in Carthage asked.
I'm convinced that something went awry during the Carthage Update process because I received this error on my initial attempt:
$ carthage update
*** Fetching SwiftyJSON
*** Fetching Alamofire
*** Checking out SwiftyJSON at "2.1.3"
*** Checking out Alamofire at "1.1.4"
*** xcodebuild output can be found in /var/folders/0x/swzt630n3_575tglljpwhn4h0000gn/T/carthage-xcodebuild.Pc6rLg.log
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
*** Building scheme "Alamofire OSX" in Alamofire.xcworkspace
*** Building scheme "SwiftyJSON" in SwiftyJSON.xcworkspace
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
After looking up the problem, I was told that you could run
carthage update --configuration Debug
Which installed it fine, but something is still amiss...
It seems like you missed a step during the addition of SwiftyJSON and Alamofire frameworks from Carthage. Check out these steps from the Carthage readme page :
Steps :
Create a Cartfile that lists the frameworks you’d like to use in your project.
Run carthage update. This will fetch dependencies into a Carthage/Checkouts folder, then build each one.
On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.
On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script with the following contents:
/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input Files”, e.g.:
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework
$(SRCROOT)/Carthage/Build/iOS/SwiftyJSON.framework
Looks like you missed step 4. I tried these steps myself in a demo Swift project and they are working great. Try these steps out, and if you still have problems, leave a comment. Thanks!
I switched over to Cocoapods and it just worked. Again, I'm a total noob when it comes to iOS development. When looking for a dependency manger I looked at Cocoapods and Carthage for what they had to offer. I was intrigued by Carthage's claim of keeping things simple:
"Carthage because we wanted the simplest tool possible—a dependency manager that gets the job done without taking over the responsibility of Xcode"
While I always will choose the simpler tool when given a choice, I think I don't know enough of the iOS ecosystem (read: Xcode) to use Carthage.
TL,DR: Can't use it inside of Emulator, Use iPhone.
I also followed your way, and I found out that --configuration debug will code-sign "iOS Developer" identity as SwiftyJSON's project property.
AFAIK, Code-signed "iOS Developer" identity wasn't run with Emulator.
My issue was resolved when I run it at my iPhone 6.
I do not know why you can not add this resource with help of Carthage but if you need use SwiftyJSON you only need:
Enter this URL: SwiftyJSON
Clic the button "Clone or download" and then in "Download ZIP" like the next image shows:
Clic the button "Clone or download" and then in "Download ZIP" IMG
You will get a ZIP file with name "SwiftyJSON-master"
Extract the files
Enter the path:
SwiftyJSON-master/Source/
You will see a file with name:
SwiftyJSON.swift
Copy that file into the files of your project.
Add that file into your project directory.
That file will be like other class into your project that you may use.

Resources