'dyld: Library not loaded' error inside iOS framework - ios

The problem
I have build an iOS framework which uses a 3rd party framework. When I try to use the framework inside an iOS app, the following error comes up noticing me that the 3rd party framework I used couldn't be loaded.
dyld: Library not loaded
If I copy the 3rd party framework into the iOS app, everything will work smoothly. Is there a solution out there that would allow me use a 3rd party library without the necessity to copy again the framework inside the iOS app?
Things that I have tried:
Creating a 'copy phase' inside the iOS framework with the destination 'Frameworks'. It will not work.

Related

Apple app store support ios app with dylib

I am trying to make an ios app with a dylib as framework instead of the standard .framework or .xcframework structure.
Does the app store review work with such a shared library structure.
I see from here that it might not be supported.
https://developer.apple.com/library/archive/technotes/tn2435/_index.html#//apple_ref/doc/uid/DTS40017543-CH1-TROUBLESHOOTING-BUNDLE_ERRORS
https://developer.apple.com/forums/thread/125796
Has anyone tried an app with a dylib inside ? Or it has to be packaged as framework instead ?
From your first link:
Dynamic libraries outside of a framework bundle, which typically have
the file extension .dylib, are not supported on iOS, watchOS, or tvOS,
except for the system Swift libraries provided by Xcode.
That seems unambiguous in saying that you can't include a dynamic library outside a framework.

How to add a framework to iOS library project?

I have very little experience in native iOS development but my current job is to wrap some specific native iOS framework to use it in React Native.
Preliminary data: common React Native tools generate an empty iOS library project and an example iOS app project that utilizes this library.
First I've tried to add the needed framework directly to the example app using CocoaPods - and it works fine, the framework became a part of linked libPods.a file, then if I add
#import MyTargetFramework;
to AppDelegate.m I can access different methods of the framework from it.
Next I switched to my iOS library project, applied the same setup (created a Podfile, added the same pod MyTargetFramework to it), then added the same #import MyTargetFramework to *.m file - but got a build error:
Module 'MyTargetFramework' not found
Also I've noticed that there is no libPods.a for iOS library project, all the pods are merged to a Pods.framework instead.
So my question is - what am I doing wrong? Why does it work for iOS app project, but not for iOS library project? How can I properly link my target framework to my own iOS library? I've already spent some time googling, but found nothing about app vs lib differences from this point.

Distribute an iOS framework with 3rd party libraries

I'm currently developing a custom framework that makes use of different dependencies such as Moya, RxSwift, ObjectMapper etc. The only issue is that whilst developing the framework I set the search path to the Carthage folder so it knows where the files are when I'm developing the framework.
So the issue is when it comes to distribution because there are so many 3rd parties getting the user to download frameworks and/or link them themselves seems like a long task and I'm unable to distribute the framework via Carthage or CocoaPods.
So I'm currently looking for advice/guidance on how to distribute my own framework and embed these third parties within it whilst still being able to prevent duplicate symbols if the user includes the library within their project i.e. My framework uses RxMoya and the user adds RxMoya as a dependency within the project via Carthage, CocoaPods or manually.

FCM integration in IOS swift framework

how to do FCM integration in ios framework. I have did and tested in application but i want to do in framework so that i can sell to someone to use my code. The problem i'm facing when u create xcode project on touch framework you cannot enable APNS option. Can anypne get me out of this. Thank You
First thing is first:
As you already stated that, you've successfully integrated FCM into your cocoa touch library, here one thing i wanted to suggest.
If you're shipping your solution as framework to third party. I'm assuming you are using Cocoapod. Declare the Firebase related pods (which you are using) as Dependencies. Cocoapod will automatically manage this dependency tree. If you are preparing just plain framework and included Firebase related frameworks within it, it's wrong. Because the third party developer cannot update the Firebase related frameworks while new SDKs are released. Another thing that, the third party developer may use firebase's other services which required them to integrate firebase sdks within their app. In that case duplicate class declaration error may arise.
Enabling APNS
Yes you cannot enable APNS from capability for touch framework. Instruct your third party developer to enable required fields for their project. Include it in your integration guide or README.md what ever you are using to help third party developer integrating your cocoa touch framework.
From https://github.com/firebase/firebase-ios-sdk/blob/master/docs/firebase_in_libraries.md
Conclusions:
The Firebase SDKs may be used from an embedded dynamic framework in your project (e.g. for code reuse purposes) only when Firebase is not used from the app directly.
The Firebase SDKs should never be used from vendor dynamic frameworks because the version of Firebase compiled into the dynamic framework will conflict with the versions compiled into the app or included in any app bundles.
Conclusions:
Using the Firebase SDKs in static frameworks and libraries is safe, meaning there will be no symbol collisions, for both vendor and in-app internal libraries.
If the static framework is used from an app and its extensions, then it will be copied to each target, increasing the app download size.
If the static framework is used from an app and its dynamic dependencies, then it will be copied in both the app and its dependencies, which will result in undefined behavior.

Could adding a framework to an iOS project block/hide access to other files in the project?

After adding the Dropbox SDK Framework to my Xcode project (iOS) my project fails to build due to errors shown in image 1 below:
Prior to adding the Dropbox Framework, or reverting to the previous commit, results in the project building and running with out issue. I have also tested the same Dropbox SDK Framework package in a seperate demo project to ensure it is not corrupted - and that demo project builds and runs just fine, accessing the Dropbox SDK as expected.
Is it possible that the Dropbox SDK Framework is hiding or blocking access to the GLKit Framework within my main project?
Or is there something else at play here? The second error shown in screenshot claims the bridging header also 'Failed to import' which is an error I have not seen before, usually it is 'not found'.
The Dropbox SDK Framework is being added by drag-and-dropping into Xcode and checking the copy if needed box. Immediately after adding the Dropbox SDK Framework the project no longer builds and reports these errors.
I am answering my own question for anyone else who might have similar problems. While I did not find the root cause of the problem, I did get around it with the following solution.
I ended up removing all third party frameworks from my project which were:
ResearchKit Framework
Dropbox SDK Framework
Charts Framework
And in addition I removed all the XCode supplied frameworks from the project in the left hand file list: 'Project Title -> General -> Linked Frameworks and Libraries'
I then installed and setup CocoaPods with the project, and used CocoaPods to install and manage my third party frameworks (ResearchKit, Dropbox SDK and Charts)
The project is now able to build and run successfully and has access to the GLKit framework along with all other XCode supplied frameworks, bridging header and Dropbox SDK.
I assume this issue was due to a setting in XCode that was preventing access to GLKit after the Dropbox SDK had been added, and using CocoaPods to manage the integration of the third party frameworks skirted this issue.
If anyone has any further insight I'd be very interested to hear you explanation.

Resources