dyld: Library not loaded realm - ios

i added a framework that i developed in ios to the new project. I tried to make the app universal (one framework work both in device and simulator) according to this tutorial
create an ios universal framework
. When i run my demo project using this universal framework i get this errors
dyld: Library not loaded: #rpath/Realm.framework/Realm
Referenced from: /private/var/mobile/Containers/Bundle/Application/DDF71B22-F535-43E5-B770-D3425419B108/DemoSDk2.app/Frameworks/#######.framework/#########
Reason: no suitable image found. Did find:
/private/var/mobile/Containers/Bundle/Application/DDF71B22-F535-43E5-B770-D3425419B108/DemoSDk2.app/Frameworks/########.framework/Frameworks/Realm.framework/Realm: mmap() errno=1 validating first page of '/private/var/mobile/Containers/Bundle/Application/DDF71B22-F535-43E5-B770-D3425419B108/DemoSDk2.app/Frameworks/##########.framework/Frameworks/Realm.framework/Realm'
both in device and simulator the demo app crash

Dynamic frameworks are by definition not statically linked into binaries that link them.
This means dynamic frameworks must be shipped with the binaries that link them.
The typical way to do this for iOS apps is to have a build phase to copy the framework into your app bundle after compilation.

Due to restrictions by Apple for app store deployment it is not possible to dynamically link frameworks. This is an issue that is common amongst frameworks and not specific to Realm.
The following link is from Realm's GitHub discussion and explains in further detail and offers some work arounds (though none are particularly elegant.
https://github.com/realm/realm-cocoa/issues/3051

Related

Proper way of embedding dylib into an iOS app

I have a project which consist of three elements:
C source code that is compiled to .dylib
Swift framework used to provide user-friendly swift API for .dylib
iOS app consuming both .dylib and swift proxy
I have added both swift proxy and .dylib as "Framework and libraries" dependency to iOS app project. Things work as expected on my iPhone. However when I attemt to send my app to Apple Store Connect I get following error:
ITMS-90429: Invalid Swift Support - The files libswiftDarwin.dylib, libswiftDispatch.dylib, libswiftCoreGraphics.dylib, libswiftCoreFoundation.dylib, libswiftCore.dylib, libswiftFoundation.dylib, libswiftObjectiveC.dylib aren’t at the expected location /Payload/Runner.app/Frameworks. Move the file to the expected location, rebuild your app using the current public (GM) version of Xcode, and resubmit it.
I figured this can be caused by .dylib file being embedded directly in iOS app, so I tried to embed .dylib into swift framework. Then I made iOS app embedding only swift framework, which consist of .dylib file. However I am getting following error in this configuration:
dyld: Library not loaded: #rpath/libX.dylib
Referenced from: /private/var/containers/Bundle/Application/.../swiftProxy.framework/swiftProxy
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/.../swiftProxy.framework/Frameworks/libX.dylib: code signature in (/private/var/containers/Bundle/Application/.../swiftProxy.framework/Frameworks/libX.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
This doesn't make sense for me, but I figured this is not the right way.
So the question is: how do I properly embed dylib so that it can be put on Apple Store Connect and then on Testflight?
I'm aware that this question was asked at least once, but there is no decent answer. Here for example: How to properly embed 3rd party .dylib files in iOS app project for App Store release?
Thank you

Linking only embedded framework with other dynamic framework fails when build & run on device

tl;dr
Linking your embedded framework with other framework and don't link other framework with your app cause required code signature missing when Build & Run on device.
description:
Setup:
My setup is pretty simple (Swift 2.3 & Xcode Xcode 8.0; Build version 8S162m):
Using Carthage (0.17.2) I have build Other.framework with xcodebuild 8.0 and TOOLCHAINS=com.apple.dt.toolchain.Swift_2_3 carthage build --platform iOS
MyApp has embeded My.framework.
The app and the framework projects are under one Xcode workspace.
I hade linked Other.framework to My.framework ONLY (that means, MyApp is not linked to Other.framework at all). The point here is that, MyApp does not need to use Other.framework API.
Problem:
Everything seems to work fine, until I Build & Run the app on the device. The app launched and than the process is aborted with the following Xcode error:
dyld: Library not loaded: #rpath/Other.framework/Other
Referenced from: /private/var/containers/Bundle/Application/DCF0331F-FF23-43CF-AE79-B3857D5A6EE3/MyApp.app/Frameworks/My.framework/My
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/DCF0331F-FF23-43CF-AE79-B3857D5A6EE3/MyApp.app/Frameworks/My.framework/Frameworks/Other.framework/Other: required code signature missing for '/private/var/containers/Bundle/Application/DCF0331F-FF23-43CF-AE79-B3857D5A6EE3/MyApp.app/Frameworks/My.framework/Frameworks/Other.framework/Other'
I have checked the signature of Other.framework and it looked OK to me. Moreover,
Solution (workaround)
Link MyApp with Other.framework. Horrible... This feels broken.
Linking the very same binary Other.framework to MyApp and solving the issue this way, points out, the Other.framework is built OK and able to be re-signed correctly. Possibly, nothing to do with Carthage.
NOTE:
There is a similar problem iOS 8+ framework with nested embedded framework, however, mine has slightly other reason.
The issue has nothing to dow with nested frameworks. It is entirely about codesignature validation. dyld is reporting that Other.framework is missing a codesignature. You need to sign the framework. This should be done for you by Xcode, so I'm curious how Other.framework is getting built.
You can probably work around this yourself by just signing it.
codesign --force --deep --preserve-metadata=identifier,entitlements,resource-rules,requirements,flags,team-identifier --sign - /path/to/Other.framework
or to just deeply resign your app:
codesign --force --deep --preserve-metadata=identifier,entitlements,resource-rules,requirements,flags,team-identifier --sign - /path/to/My.app
I fixed my exact problem by following this guidance
You don't need to link your 'Other.framework' to your MyApp. Just add run script to sign the whatever embed framework that required code signature missing
Discussing this issue on the Carthage github page, it's become clear that the workaround mentioned in the question, is actually an expected behaviour:
Carthage doesn't support nested frameworks.
Nesting frameworks doesn't let you reuse those frameworks. For instance, if A.framework and B.framework both depend on Other.framework, then neither of them can nest Other.framework—otherwise you might end up with 2 different versions, and the correct one might not be chosen at runtime.
The correct way to do this is to list it as a dependency, but link it into the app target.
Full discussion: Linking only embedded framework with other dynamic framework fails when build & run on device: "required code signature missing"
This was unclear from the README, so I raised another issue, requesting to update the documentation:
Update to README: Linking dynamic frameworks to embedded frameworks requires as well linking them to the app target #1427
This is resolved and closed in the scope of the PR:
#1427 README upd: link dependencies from embedded frameworks to the app target

dyld: Library not loaded for a Framework within a Framework

I am trying to embed a Framework that are using another Framework and this works just fine in the simulator, but it crashes on an iOS device:
dyld: Library not loaded: #rpath/FrameworkB.framework/FrameworkB
Referenced from: /private/var/mobile/Containers/Bundle/Application/B072CD7C-8595-4AE4-A506-26832A0F4402/FrameworkTest.app/Frameworks/FrameworkA.framework/FrameworkA
Reason: image not found
This is my structure in Xcode:
FrameworkTest.xcodeproj (the app project)
FrameworkA.xcodeproj (Cocoa Touch Framework)
FrameworkB.xcodeproj (Cocoa Touch Framework)
The app (FrameworkTest) uses a class A from FrameworkA (which is embedded in the FrameworkTest app). The class A uses the class B from FrameworkB (which is linked in FrameworkA).
This works just fine in the simulator, but it does not work on the device.
The structure may seem a bit strange, but I am developing the frameworks as I go when I develop the app, which is why I want to add the framework projects inside my app project.
I have uploaded the project on GitHub for you to see, if you need to take a closer look. (The class A is invoked in the AppDelegate.m file)
Why is this working in the iOS simulator and not on the device? And how can I make it work on the device?
EDIT:
As simonthumper suggests in the comments, I have also tried to add FrameworkB.framework to Copy Files as Frameworks destination in Build Phases for FrameworkA, but that gives me this error in the console:
dyld: Library not loaded: #rpath/FrameworkB.framework/FrameworkB
Referenced from: /private/var/mobile/Containers/Bundle/Application/2A38A2BC-9CD7-4AF6-9E50-42C16D92D6B2/FrameworkTest.app/Frameworks/FrameworkA.framework/FrameworkA
Reason: no suitable image found. Did find:
/private/var/mobile/Containers/Bundle/Application/2A38A2BC-9CD7-4AF6-9E50-42C16D92D6B2/FrameworkTest.app/Frameworks/FrameworkA.framework/Frameworks/FrameworkB.framework/FrameworkB: mmap() error 1 at address=0x10012C000, size=0x00008000 segment=__TEXT in Segment::map() mapping /private/var/mobile/Containers/Bundle/Application/2A38A2BC-9CD7-4AF6-9E50-42C16D92D6B2/FrameworkTest.app/Frameworks/FrameworkA.framework/Frameworks/FrameworkB.framework/FrameworkB
I contacted Apple with this issue and found a solution to my problem. Apple's Technical support made it clear, that I need to add the FrameworkB.xcodeproj to my application project, so my project structure is:
FrameworkTest.xcodeproj (the app project)
FrameworkA.xcodeproj (Cocoa Touch Framework)
FrameworkB.xcodeproj (Cocoa Touch Framework)
FrameworkB.xcodeproj (Cocoa Touch Framework)
When I have done this the application project can include FrameworkB.framework as an Embedded Library:
This solved my problem and made it possible to run it on an iOS device.
If the build crashes on Release:
Revoke your Enterprise Distribution certificate and create a new one to solve the problem. Once I did that it worked perfectly.
I also had similar issues with embedded frameworks and I just tried your code from GitHub.
Option 1 (not suitable for teamwork)
What made the error disappear was to add FrameworkB to Embedded Binaries in the General tab of your FrameworkTest target.
Option 2
Well, sharing project with other developers sure is important :). Did you try this approach? Add New Copy Files Phase In the FramewrokA's Build Phases and add FrameworkB into Frameworks destination.
But I'm not sure why does it work on the simulator. If anyone knows, please, feel free to comment.
cheers

iOS 8 Dynamic Framework: Library Not Loaded

I've been working on an iOS 8 app that includes a Share Extension. Both app and extension targets use a new iOS 8-style dynamic framework. In an effort yesterday to get the damned thing into the TestFlight Beta App Review (see here and here), I made a number of changes to my build configuration. The store eventually accepted the app for review, but today as I'm trying to run on my device I'm getting the following error:
dyld: Library not loaded:
/Users/aaron/Library/Developer/Xcode/DerivedData/VideoGrabber-gpyzpfvbijsnuyglzzvynckkuwee/Build/Products/Debug-iphoneos/MyAppKitiOS.framework/MyAppKitiOS
Referenced from: /private/var/mobile/Containers/Bundle/Application/4C6CFF22-0595-4222-A515-D0D5A1696DBF/MyApp.app/MyApp
Reason: image not found
Looking elsewhere for help, I've come across a number of proposed solutions:
Add the framework to the App Target's Embedded Binaries section of the General tab. Done.
Enter "#executable_path/Frameworks" into the Runpath Search Paths section of Build Settings on the App Target. Done.
Ensure there's an entry in the "Copy Files" build phase. Step one actually does this for you, so... Done.
Having followed the advice in this otherwise-excellent piece and looking at the solutions offered in the Dev Forums with the exact same issue, I'm totally flummoxed. Anything else I can try?
I got it working by comparing something known-good (Apple's Lister app) with my own Build Settings. By comparing the install paths for the framework, and then the search paths for my app target, I was able to get it working. In summary:
In the Framework Target's Dynamic Library Install Name Base, use "#rpath"
In the Framework Target's Dynamic Library Install Name, use "$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)" -- this automatically resolves to the name of your framework.
In the Application Target's Runpath Search Paths, use "#executable_path/Frameworks".
Ensure "Always Search User Paths" is set to No. Framework Search Paths could be blank too.
If it's after lunchtime, pour yourself three fingers of scotch. You've earned it.
Since it's morning still, I'll console myself with gentle weeping.

dyld isuess (Library not loaded)

I have this message when I build my project:
dyld: Library not loaded:
#rpath/iPhoneSimulatorRemoteClient.framework/Versions/A/iPhoneSimulatorRemoteClient
Referenced from: /Users/dev01/mobile/ios/Test/test/testTests/FoneMonkey/bin/iphonesim
Reason: image not found
This is dynamic link error and as I understand correct this error came because image not found. is this correct?
What steps should be taken to resolve errors?
I have found this link and as I understad this error came because I use xcode 4.3. Now I have try this on 4.2 and everething work good.
But I not have any idea how to run it on XCode 4.3
Maybe you have this problem after adding new library and you linked it in actual framework path, if you drag this library in embeded framework path then problem will solve. Another variant is that in build scheme you have enabled memory managment malloc, if you turn it off problem will be solved.
Check your SDK project settings (i.e. when passing from SDK 6.x to 7.x) maybe one of library was not compiled for architecture and project target. And the paths. Clean DerivedData and delete app from simulator (if it is there).
If you still need the Sdk just copy it from Xcode 4.6.(3) both for device and simulator and see if this solve your problem.

Resources