Satisfying a framework's dependencies while within another project - swift

I am working on an iOS framework. My development environment is an iOS application project with the framework project within it, the framework's product is then added to the "Embedded binaries" and "Linked Frameworks and Libraries" sections of the application.
The previous setup works fine, but this particular framework I'm working on requires one other framework to function. I have installed this framework via Carthage and added it to the base application's project ("Embedded binaries" and "Linked Frameworks and Libraries") and then also the framework's project "Linked Frameworks and Libraries".
However when I run the application I get the following two errors (FrameworkOne is the framework I'm working on in a project, FrameworkTwo is the dependency):
dyld: lazy symbol binding failed: Symbol not found:
[symbol here]
Referenced from:
[path to iOS sim]/FrameworkOne.framework/FrameworkOne
Expected in:
[path to application]/Frameworks/FrameworkTwo.framework/FrameworkTwo
...and...
dyld: Symbol not found:
[symbol here]
...the same paths as above...
What am I doing wrong here?

The answer is simple and frustrating in hindsight: the version of the framework used within my application project and my framework project didn't match.
If you're having similar issues check that your application and framework are using the same version!

Related

Bundle all local transient Swift Packages into a single xcframework

I am developing a SDK and use SPM to modularise my code. All code is written in Swift.
My project structure is like this:
SampleApp (Workspace) -> SDK (SPM) -> ModuleA (SPM)
I can build and run the sample app locally successfully.
Now I want to archive/build the SDK package into a dynamic xcframework that my other clients can just drag and drop into their Xcode to consume.
I'm using xcodebuild -create-xcframework for that purpose and can successfully build a sdk.xcframework file.
But in a separated sample app where I embed the sdk.xcframework there, when import SDK module, I get this error
No such module 'ModuleA'
Failed to build module 'SDK' for importation due to the errors above; the textual interface may be broken by project issues or a compiler bug
I assume here, this is because the compiler can't find ModuleA
Is there anyway that I can bundle the ModuleA into sdk.xcframework statically, so that my clients can just drag only sdk.xcframework into their projects to consume the SDK module?
The question is pretty much: How can I bundle ModuleA and SDK into a single .xcframework for distribution

Link SDK only + Entity Framework = System.ComponentModel build error

With linking set to SDK Only, I have an error on iOS like this:
MTOUCH : error MT2101: Can't resolve the reference 'System.Void
System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider::.ctor(System.Type)',
referenced from the method
'System.ComponentModel.ICustomTypeDescriptor
System.Data.Entity.ModelConfiguration.Utilities.AttributeProvider::GetTypeDescriptor(System.Type)'
in 'System.ComponentModel.Annotations, Version=4.3.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
I use Entity Framework and a number of other 3rd party libraries that integrate with Entity Framework, and in the past I have needed to add a --linkskip argument for System.Core or a .Init call in my Appdelegate file for Sqlite, but these techniques havent helped me with this ComponentModel issue. I assume it's because of Entity Framework or one of the related 3rd party libraries I'm using since I know they use a lot of reflection. Has anyone run into this before?
EntityFrameworkCore.Triggers 1.2.2
LinqKit 1.1.17
Microsoft.Data.Sqlite.Core 3.1.6
Microsoft.EntityFrameworkCore 3.1.2
Microsoft.EntityFrameworkCore.Design 3.1.3
Microsoft.EntityFrameworkCore.Relational 3.1.2
Microsoft.EntityFrameworkCore.Sqlite 3.1.2
Microsoft.EntityFrameworkCore.Tools 3.1.3
Z.EntityFramework.Plus.EFCore 3.0.69
The projects using entity framework are class libraries that target .netstandard 2.0, and my main application uses xamarin forms 4.5 (have tried updating to 5.0 with no success)
I solved this problem manually referencing System.ComponentModel.Annotations.dll in .netstandard2.1 in nuget folder. You can try first to install the Annotations Nuget e if doesn't work you can try to manually reference.

dyld: Library not loaded: #rpath/RxSwift.framework/RxSwift

I created a custom framework that uses RxSwift, RxCocoa and others third-party frameworks. The custom framework compile correctly but when I added to the application it crash with this error :
dyld: Library not loaded: #rpath/RxSwift.framework/RxSwift
Referenced from: /private/var/containers/Bundle/Application/49800223-0217-4591-A8D1-
I tried to use module map to expose the third-party but without success :(
Any help please because I didn't found a solution since two days and I'm blocked.
Thank you
You need to copy framework dependencies to application. Process depends on way you add dependencies in framework.
For CocoaPods you can check my answer here: Xcode/Cocoapods: I can't access a dependency that's in a framework linked to my project

Cocoapods SwiftWebSocket in Xcode project - library is not found

I'm experimenting with SwiftWebSocket in Swift using Xcode 10.1.
I've added the pod via this podfile:
platform :osx, '10.14'
target 'ViewWebSocketLearning' do
use_frameworks!
pod 'SwiftWebSocket', '~> 2.7'
end
and I've loaded the pod as follows:
$ pod install
Analyzing dependencies
Downloading dependencies
Using SwiftWebSocket (2.7.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
which produces a workspace with the SwiftWebSocket project included in it. I compiled the projects and you can see that it is correctly compiling both my empty project and the SwiftWebSocket project properly. Everything is looking good so far.
However as soon as I try to include a reference to the SwiftWebSocket project in my project's unit tests, Xcode chokes. Here's a snip of my code:
import SwiftWebSocket
...
let ws = WebSocket("wss://echo.websocket.org")
I get "No such module 'SwiftWebSocket'". If I take out the import, I get "Use of unresolved identifier 'WebSocket'". So something isn't linking properly by the looks of it.
I've tried adding the compiled framework from the SwiftWebSocket project to mine in the project organizer on the left, no change. I've added it to the Linked Frameworks and Libraries in the target settings, again no change.
What am I missing?
I'm a relative novice to Xcode so apologies but I really would like to get past this point so your help is much appreciated! Thank you.
It's not exactly the solution I was shooting for, but I solved this by building a class in my project which contains the logic to control the SwiftWebSocket, then called that class from inside the unit tests.
Architecturally this is probably cleaner but I remain unclear on why I couldn't access the SwitfWebSocket directly from the unit tests.

Xcode compile error on Release Build on a project that uses some framework reference

I am working on a Swift project that uses some frameworks references. It works well when the debug compile. But, When I compile Release it throwing some reference errors like below;
That failed classes are in the CryptoSwift.framework library and MyFramework using this library. CryptoSwift.framework existing on build phases.
I tried "Optimization Level -> None [-Onone]" but failed.
Swift Version: 2.3,
Xcode Version: 8.0
It worked after I selected "Build Active Architecture Only" for Release Compile.
The reason for the error is that the frameworks do not support all architectures.