sdk inside iOS framework swift - ios

I'm new on iOS and i don't understand somethings.
First, I need to make a library as in Android. So it is correct to make a cocoa touch framework?
So i have this project structure :
Next, i need to import this sdk to use it inside my framework.
https://github.com/kontaktio/kontakt-ios-sdk
But i don't find how to import this one. I have try to drag and drop the KontaktSdk.framework inside the ..._library but i have this error when i run my app :
dyld: Library not loaded: #rpath/KontaktSDK.framework/KontaktSDK
Referenced from: /private/var/containers/Bundle/Application/7A74722F-D2C5-49F2-BC77-955B90B1A421/..._app.app/Frameworks/..._library.framework/..._library
Reason: image not found
(lldb)
I have tried to follow this instruction:
But in the framework, i don't have the "Embedded Binaries" section.
I hope you can help me =)
Thanks

You don't need to use CocoaPods.
You need to embed KontaktSdk.framework in your application's build phase. Since your library's output is not an .app bundle, it does not have a /Frameworks directory inside it. That's why it does not have a "Embed Framework" build phase.
You should link KontaktSdk.framework framework against your _library, but embed KontaktSdk.framework into your application target.

Related

FrameWork + Embedded Binaries

I have this issue when I attach my custom framework to a Test project.
dyld: Library not loaded: #rpath/FrameworkName.framework/FrameworkName
Referenced from: /Users/Me/Library/Developer/CoreSimulator/Devices/9C4B0FD8-200B-4FF1-AFEC-7D2316698CDA/data/Containers/Bundle/Application/9BAA9518-2FD0-4AAC-ABD8-F3842FA77A9E/TestProject.app/TestProject
Reason: image not found
I need to attach the framework to the Embedded Binaries to fixe this issue.
My question is:
Why for the other framework is not mandatory to add it to Embedded Binaries ?
What is missing in my framework project, or what I need to change in the build settings of the framework project ?
Ok i found the issue, i need to change the Mach-O Type in the build settings to Static Library.

Load custom dynamic library(.dylib) in iOS application

I have created one custom library called 'Library.dylib',now I am trying to add that dylib file in another iOS project and it is giving following error,
dyld: Library not loaded: #executable_path/Library.dylib Referenced
from:
/Users/xxxx/Library/Developer/CoreSimulator/Devices/4CCFE5F7-494B-41DE-AEB9-5040418518B4/data/Containers/Bundle/Application/A97A1947-80B5-9AA0-B46F-C11E25A94553/DyLibTest.app/DyLibTest
Reason: image not found
In Mac app if we copy it in /usr/lib/ path it is working, but not in iOS app.
Please let me know how to use custom dylib in iOS application?
FYI I want to use only dynamic linking not static linking(.a)
As far as I can see your app expects your library to be copied to #executable_path/Library.dylib. Yet, if you add your library to the Embed Frameworks build phase (which I assume you did) it will be copied to the Frameworks subfolder in your app bundle and therefore cannot be loaded by your app.
There are two solutions:
1) Change the destination of the Embed Frameworks build phase from Frameworks to Executables. In general, I wouldn't recommend to change that though.
2) Adjust the Runpath Search Paths in your build settings to include #executable_path/Frameworks.
Hope that helps.
You must put *.dylib file in Embed Libraries.
Project -> Build Phases -> Embed Libraries
Click to "+" and choose your *.dylib file.

dyld: Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib

I've built a Swift framework and now I'm trying to start building a Swift iOS application that will use that framework. I'm getting this error:
dyld: Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: /Users/tdean/Library/Developer/Xcode/DerivedData/NFLApplication-ejmafvjrlqgjaabggwvadjarjjlg/Build/Products/Debug-iphonesimulator/NFLStatsModel.framework/NFLStatsModel
Reason: image not found
I've scoured SO and found similar reports and tried the fixes listed there, including:
Clearing out my DerivedData folder
Restarting Xcode and the iPhone simulator
Ensuring that Always Embed Swift Standard Libraries = YES is set, both in my framework and my application's build settings
Ensuring that Enable Bitcode=NO is set, both in my framework and my application's build settings
Ensuring that Runpath Search Paths is set to #executable_path/Frameworks, both in my framework and my application's build settings
Copied all the libswift files from my Xcode installation into a local copy within my project, and added a custom build phase to copy those files into the frameworks folder.
In every case, I get the same error when I try to run my application.
Xcode Version 8.1 (8B62)
Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)
I eventually got this working using a mix of fixes. I'm not sure if all of them are needed, but I'm documenting what seemed to work for me here, just in case anyone else can benefit by what I've found.
I have set Always Embed Swift Standard Libraries to a value of YES in the build settings tab for both my Swift framework and in the Swift application that uses the framework.
I have added Foundation.framework to the Linked Frameworks and Libraries section of the general tab for both my Swift framework and in the Swift application that uses the framework.
I have added Foundation.framework to the Embedded Binaries section of the general tab for the Swift application that uses the framework.
With all 3 of these settings in place, I am able to build and run my application without encountering this error.
This might not be the case for everyone, but I solved it by actually writing some code in the main target.
I had an empty project consisting of a framework and a test target, and when running tests I was getting this error. Apparently Swift is pretty smart to detect that you don't actually need this library and does not link to libswiftSwiftOnoneSupport.dylib.
The fix is just to add some code, I just added:
class Test {
func a() { print ("something") }
}
and libswiftSwiftOnoneSupport.dylib got linked.
After several days of being stuck with this issue I finally found something that worked for me; hopefully this will help others too.
Turns out that specifically using print() anywhere in the code will somehow force libswiftSwiftOnoneSupport.dylib to be loaded and the issue will go away.
I'm using Xcode 10.1, Swift 4.2 and the pod that was giving me this issue was Nimble.
BTW, I am aware of #S2dent's suggestion to "just add some code" but in my case my framework already had several different classes so it didn't help me.
How are you installing your dependencies?
I had a similar issue:
dyld: Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: <internal framework>
Reason: image not found
It turned out to be related to Swift whole-module optimization.
Using Carthage as a dependency manager, they were being compiled for Release, and thus compiled with whole-module optimization, which Xcode suggested I turn on. Running the app on the simulator compiles it for Debug. I'm guessing that dynamic frameworks cannot be at a different level of optimization from the app running it.
The solution was to explicitly specify the configuration I wanted Carthage to build for. (carthage bootstrap --configuration Debug) Oh, and cleaning my build folder, of course.
I had the same issue, adding the library (my own build one) to Linked Frameworks and Libraries in General tab of the app solved the issue.
You can also provide an Host Application to your test target if you don't want to add Foundation.framework to Linked Frameworks or Embedded Binaries
You can solve this by setting "Always Embed Swift Standard Libraries" to "Yes" in the Build Settings of your target.
It is an dynamic linker error which links binary in load or runtime
[#rpath]

Xcode: create Framework with pod dependecies

I create a framework that use AFNetworking (installed with pod).
I can import this framework on my project and I can use all classes/methods that I exposed, so project compile.
When I try to run project on simulator, I obtain this error:
dyld: Library not loaded: #rpath/AFNetworking.framework/AFNetworking
Referenced from:
/Users/.../Library/Developer/CoreSimulator/Devices/F56F98F0-2AE0-4C87-AC9A-6E3B449762D1/data/Containers/Bundle/Application/BFA5359F-8FCE-4402-8487-CD9C002CB673/MyProject.app/Frameworks/MyFramework.framework/MyFramework
Reason: image not found
I already included 'MyFramework' under:
Build phases -> Embed Frameworks
I suppose I missing something on building Frameworks, but I can find out what! I already seen this unanswered question.
Who can I use MyFramework without installing Pod on MyProject again?
It is really delayed, for this issue but I have got my project working. It might not be the best way but it works. I am putting it here for future reference.
I wanted to do it without using Pods in the main project. The reasoning is, we are bundling our SDK into a framework.
So essentially, the first step I took was to get the framework project bundling without using the workspace. I just dragged the Pods project into the framework project.
Then I added the frameworks the the pods project creates and add them to my framework. I set them to optional and code sign. You can see them in the picture of where I added them under the build phases.
Then add them to your main project. not the framework the normal way by adding the project and or the framework. Then add it to the Embedded binaries and Linked Frameworks.
If it helps anyone, the solution mentioned by #ArtyomDevyatov does work. The trick is that you have to add 's.dependency' in podspec file.

dyld: Library not loaded: #rpath with iOS8

I'm creating an iOS framework with Xcode6 and iOS8. When I link this with an iOS app and try running it on the device I get this error
dyld: Library not loaded: #rpath/FrameworkName.framework/FrameworkName
Referenced from: /private/var/mobile/Containers/Bundle/Application/0F2C2461-A68B-4ABA-A604-B88E6E9D1BB1/AppName.app/AppName
Reason: image not found
The 'Runpath Search Paths' build setting for the framework is set by default to
'#executable_path/Frameworks', '#loader_path/Frameworks'
I could not find any documentation related to this. This was something new introduced with Xcode6 and I would expect it to just work by simply including the framework into any app that needs it.
To make this work
In the framework project settings change the install directory from
'/Library/Frameworks' to '#executable_path/../Frameworks'
In the project that includes this framework, add a copy files phase and copy this framework to the 'Frameworks' folder. Once you do this ensure that this framework is listed under the 'Embedded Binaries' section.
Issue resolved using this answer. According to #vladof81:
In the target's General tab, there is an Embedded Binaries field. When you add the framework there the crash is resolved.
Reference is here on Apple Developer Forums.
I also had same kind of problem where I was not able to launch the app & app was crashing with above message :
dyld: Library not loaded: #rpath/FrameworkName.framework/FrameworkName Referenced from: /private/var/mobile/Containers/Bundle/Application/xxxxxxxxxxxxxxxxxxx
Reason: image not found
Here is my approach that helped me to resolve this error:
From General Tab
Frameworks, Libraries, and Embedded Content
add the framework and make sure to make it Embed & Sign
From Build Phases
Dependences
add the framework to it
Check if you can find framework in context under :
Build Phases > Embed Frameworks >
If not just add that framework in "Embed Frameworks" after adding that framework in your project directory's "Frameworks" section.
I was getting this error on a library installed through CocoaPods. Cleaning the build folder (cmd + option + shift + k) and then doing a clean (cmd + shift + k) was what ended up resolving this issue for me.
If you are using Carthage
Run carthage update on terminal
Go to Project Settings -> Build Phases -> Carthage Copy Frameworks
Add line in Inputs files:
$(SRCROOT)/Carthage/Build/iOS/YOURLIBRARY.framework
Add this line to Output files:
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/YOURLIBRARY.framework
For me it was because of the SSL issue, I had set my developer, distribution certificates on my Mac(Keychain) to 'Always Trust' for one of my other project. I had to change them back to 'Use System Defaults'. it was working for me then!!
Made the library which shows not loaded changed from required to optional in Linked binaries and frameworks. It is working perfectly now
I also had same kind of problem where I was not able to launch the app & app was crashing with above message :
dyld: Library not loaded: #rpath/FrameworkName.framework/FrameworkName
Referenced from: /private/var/mobile/Containers/Bundle/Application/xxxxxxxxxxxxxxxxxxx
Reason: image not found
Here is my approach that helped me to resolve this error:
1.Please delete your app from device, Clean the build and and rebuild and run on the device.
2.If above steps does not help you, then please check for below settings :
From "TARGET">"Build Settings">"Runpath Search Paths" & then check for values "$(inherited)" & "#executable_path/Frameworks", Feel free to add incase they don't exist.
Build your app and run it on device
In addition to the above solutions, recheck the paths of frameworks included in your application under
Build Settings --> Search Paths --> Framework Search Paths
When non of those solution works:
(Optional) Get a clear knowledge from here on different search path type
Make sure that your .framework file paths are added in Build Settings -> Framework Search Paths. You can keep all framework files somewhere in App/libs/ and add this folder and enable recursively.
Make sure that your .a files paths are added in Build Settings -> Library Search Paths.
I installed third party libraries using Cocoapods. Got the same error, tried everything but finally realised I havent had use_frameworks! in my pod file.
So removed the currently installed library, added use_frameworks! line in pod file, reinstalled the libraries and all worked for me.
The way tested by me is well.
In "Linked Binary With Libraries" change the missing framework to "Embedded Framework".
Because, "Do not Embedded" do not copy to the App, but Embedded Framework will copy into it.

Resources