dyld: Library not loaded when build to iphone 4 - iphone

I am using a third-party library,say: libABC.dylib
I want use the dylib in an open source application,and want to install into my iphone 4,with ios 6,without jailbroken.
On doing a
$ otool -L libABC.dylib
libABC.dylib:
libABC.dylib (compatibility version 1.0.0, current version 1.0.0)
libXYZ.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
111.1.5)
Now i want to ship the dylib, with my app , install into my iphone 4.
For that i have changed the dylib paths as
$ install_name_tool -id #executable_path/../Frameworks/libABC.dylib libABC.dylib
also,I added libABC.dylib to Frameworks under the project in Xcode.
This changes the inside dylib paths as
$ otool -L libABC.dylib
libABC.dylib:
#executable_path/../Frameworks/libABC.dylib (compatibility version
1.0.0, current version 1.0.0)
libXYZ.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
111.1.5)
The problem is:
libABC is loaded at app launch time,
i am unable to change this path, to a path relative to my mach-o binary
(inside my app bundle)
So my app is failing to load.
Dyld Error Message:
dyld: Library not loaded: /usr/local/lib/libABC.dylib
Referenced from:
....
Reason: image not found
Please suggest me some direction.
The third party library is only creating dylib, no static libs
I also tried setting XCode options to get dylib from "#executable_path" but
it didnt work.
and I don not load my dylib through code?
Please suggest. I am clueless here.
Advance Thanks :)

Unfortunately NO, you are out of luck, start looking for alternatives. You can't add custom/third party dylibs to an iOS project, iOS project only support addition of built-in dynamic libraries. Moreover any tries and success to add dylibs may cause you app rejected from apple.
Why? Have a look at this post for detailed discussion. specially the 2nd comment on marked answer.

Like you could read in #Adil Soomro's reference, third party frameworks are not supported because of security reasons. That's why you have to delete all the frameworks that appear inside the log when you try to build an app. Normally it should work if these Frameworks are not included. If the debugger will turn on while building you should press play till the app will be installed.
But keep looking what kind of frameworks you are using so you don't get rejected when the app will be reviewed.
Further more, a related error method can occure if you start an app on ios 5.1 or less and some of your frameworks are not supported on these os versions.

Related

TestFlight build with error: One or more dynamic libraries that are referenced by your app are not present in the dylib search path

I've been recently trying to overcome the problem mentioned in the email I receive when I upload a build to TestFlight:
ITMS-90562: Invalid Bundle - One or more dynamic libraries that are referenced by your app are not present in the dylib search path.
I have added Google Admob via Cocoapods (it's the only library I have in Cocoapods) and I have several other libraries added via SPM:
I have also tried to validate the IPA generated for which I receive the dreadful email and Xcode says that it's a valid IPA.
I have also tried looking at https://medium.com/360learning-engineering/resolving-itms-90562-invalid-bundle-email-from-the-app-store-d4a1030418e5 and the frameworks that I get with the #rpath are the following, but the problem I have here is that since I'm using Cocoapods and SPM, there's no Frameworks folder:
#rpath/FBLPromises.framework/FBLPromises (compatibility version 1.0.0, current version 1.0.0)
#rpath/GoogleUtilities.framework/GoogleUtilities (compatibility version 1.0.0, current version 1.0.0)
#rpath/nanopb.framework/nanopb (compatibility version 1.0.0, current version 1.0.0)
#rpath/libswift_Concurrency.dylib (compatibility version 1.0.0, current version 5.6.0, weak)
This is the content of the folder:
I have also tried to add those libraries with the #rpath to the Link binary with libraries but I'm still getting the email.
I'm at this point completely stuck since I don't know what else I can do here, nor how to fix this, so any help is very much appreciated!
Thanks in advance!
The solution here is to disable bitcode

Xcode10 - dyld: Library not loaded for pod installed in framework

I have a project with target frameworks.
MainAppTarget
FrameworkA
FrameworkA is the only one to use a certain pod, hence in my pod file I have something like
target 'MainAppTarget' do
...
end
target 'FrameworkA' do
pod 'PodA'
end
the build succeeds with no problem, but when I run the app on a simulator the app crashes immediately with the following error message:
dyld: Library not loaded: #rpath/PodA.framework/PodA
Referenced from: .../Build/Products/Development-iphonesimulator/FrameworkA.framework/FrameworkA
Reason: image not found
I tried all the usual suspects (delete derived data, clean, pod deintegrate...) nothing worked so far.
Any idea why this would happen, and how I can make it work without having to install all the pods necessarily on both targets?
The app is in Swift 4.2.
From your error message, there are a few things that should be checked.
dyld: Library not loaded: #rpath/PodA.framework/PodA
Referenced from: .../Build/Products/Development-iphonesimulator/FrameworkA.framework/FrameworkA
Reason: image not found
The first thing that seems odd is that the path for the framework that is being loaded (FrameworkA.framework) is not embedded inside an app. Check the "General" tab of the MainAppTarget and make sure the framework is appearing in the "Embedded Binaries" and "Linked Frameworks and Libraries" sections.
Second, #rpath is a shorthand for the runpath search path list, which tells dyld where to look for needed libraries.
Here's an example project on Github with a main app that uses one Cocoapod, and a dynamic framework that the main app depends on that uses a different Cocoapod: https://github.com/dtweston/FrameworkPodTest
Build settings that you should check on all of the targets that are involved (including the framework targets built by the Pods project):
Runpath Search Paths (LD_RUNPATH_SEARCH_PATHS)
In the example project, these are determined by the cocoapod, but each one is set to $(inherited) #executable_path/Frameworks #loader_path/Frameworks
Dynamic Library Install Name (LD_DYLIB_INSTALL_NAME)
In the example project, this is unchanged from the default $(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)
Dynamic Library Install Name Base (DYLIB_INSTALL_NAME_BASE)
In the example project, set to #rpath (again determined by the Cocoapod)
Here's a screenshot of the built application bundle showing how it's laid out:
You can use otool to get information about how the application is assembled by xcodebuild.
Here's the main app binary:
otool -L FrameworkPodTest
FrameworkPodTest:
#rpath/KeychainSwift.framework/KeychainSwift (compatibility version 1.0.0, current version 1.0.0)
#rpath/Lottie.framework/Lottie (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/UIKit.framework/UIKit (compatibility version 1.0.0, current version 61000.0.0)
#rpath/Framework.framework/Framework (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 1560.10.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics (compatibility version 64.0.0, current version 1245.9.2)
...
And the framework binary:
otool -L Frameworks/Framework.framework/Framework
Frameworks/Framework.framework/Framework:
#rpath/Framework.framework/Framework (compatibility version 1.0.0, current version 1.0.0)
#rpath/KeychainSwift.framework/KeychainSwift (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 1560.10.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
#rpath/libswiftCore.dylib (compatibility version 1.0.0, current version 1000.11.42)
#rpath/libswiftCoreFoundation.dylib (compatibility version 1.0.0, current version 1000.11.42)
...
The reason the build succeeds is that the PodA framework is visible to the FrameworkA during compilation (it can link to it), but when the application launches, then it tries to find and load the dynamic framework PodA required by the FrameworkA, and it looks like the PodA is not embedded in the MainAppTarget, so the app crashes with the error message you saw.
To fix this, make sure that the PodA framework is embedded in the MainAppTarget. Specifically, you need to make sure that the final app bundle contains the PodA.framework in the Framewokrs subfolder. Usually cocoapods copies the frameworks automatically.
Check that the Build Phases for the MainAppTarget contains cocoapods's [CP] Embed Pods Frameworks and that the scripts' input files contain the path to the PodA framework. Something like this (example shows Alamofire pod):
I have set up a project with the details you posted, but it looks to me that cocoapods handles this case automatically in the created workspace setup (you can take a look at my demo project here: https://github.com/DmitryBespalov/StackOverflowPodFramework). If your setup is different, please let me know of the details and I can help you further with that.
I too was facing the same problem. All you need to do is set the third party frameworks you are using for e.g:- PodA as Optional instead of Required under Link binary with Libraries in build Phases section. That's all. try it again and it will run as expected.
Note:- You need to add the PodA in the app in which you are using your framework.
There is no other way except create a static framework consisting your PodA and use this newly created static framework inside your dynamic framework.
At first, check whether your CocoaPod is compatible (supported) or not.
Make sure you dragged FrameworkA to the Embedded Binaries section in your project's General settings tab. Also make sure you have Embed Frameworks (1 item) in Build Phases tab and FrameworkA is included there.
Here's a solution:
Step One: Drag and drop FrameworkA.framework in your project navigation. Link framework and Library added this library.
Step Two: In Xcode go to Project > General > Embedded Binary > Add FrameworkA.framework.
Step Three: Make sure that in Build Phases tab Link Binary with Libraries (1 item) and Embed Frameworks (1 item) do exist.
P.S. I did it in Xcode 10.2.1 but in Xcode 10.1 it works the same way.
I had similar issue. Just some notes. I was using 'pod Stencil' which imported Pathkit. and suddenly got this error 'Library not loaded'. If you expand the error and split the Reason: tried: string so all the paths are on one line.
Take each path and you can do a Terminal 'ls' on each.
Though the first one should point to the build object for PathKit.
'/Users/USERNAME/Library/Developer/Xcode/DerivedData/APPNAME-gequ....op/Build/Products/Debug/PathKit.framework/Versions/A/PathKit' (no such file),
When I did a 'ls' on first path it was not found.
But if you open it in Finder up to the Debug part
'/Users/USERNAME/Library/Developer/Xcode/DerivedData/APPNAME-gequ....op/Build/Products/Debug/'
Then dig down futher under Version/A PathKit object does exist. It has black icon
I put them side by side the path in the error and path to actual file in XCode and I noticed XCode was looking in
"/Debug/PathKit.framework"
should have been looking in
"/Debug/PathKit/PathKit.framework"
I couldn't fix it but I think it was my folder layout.
I was using a workspace with two subprojects ios and macos in seperate folders with workspace in common parent folder and one Podfile in parent folder.
The Podfile file specified nested projects.
When I took the ios and macos projects out and put them in their own projects and gave them their own podfile the app compiled and ran ok. Library not found disappeared.
You have to add pod 'PodA' in FrameworkA target into MainAppTarget also.
target 'MainAppTarget' do
pod 'PodA'
end
target 'FrameworkA' do
pod 'PodA'
end
This problem is just on iOS 13.3.1.
You can't fix it, Just you have to downgrade to iOS 13.3 or wait for Xcode new update.

Framework issue - Module file was created by an older version of the compiler

I'm using
newest OpenXSDKframework (debug)
included in embedded Binaries
Build Settings: Embedded Content Contains Swift Code YES
Other linker -Objc
XCode 7.31
swift
when import OpenXSDKCore
this error is showing
.../ViewController/OpenXBannerViewController.swift:11:8: Module file
was created by an older version of the compiler;
rebuild 'OpenXSDKCore' and try again:
.../OpenXSDKCore.framework/Modules/OpenXSDKCore.swiftmodule/i386.swiftmodule
is this related to the Framework producing Company ?
what should i do - to fix that error?
thanks
That error will occur if the compiled framework (binary) was compiled using earlier version of compiler and in the most of the iOS cases it means that the binary was compiled using some earlier versions of Xcode.
Most probably, your OpenXSDKCore was not built using Xcode 7.3 that you use. The best course of action would be downloading the framework source code and compiling it by yourself.
If you don't have that option you can only wait or downgrade to earlier Xcode version.

OpenCV.Framework does not compile for the armv7s architecture

I am working on an iphone application using openCV framework.
Everything was working fine. however lately with the release of iOS 6 and XCode 4.5 I was migrating my project to XCode 4.5
When building I encountered this error:
ld: file is universal (2 slices) but does not contain a(n) armv7s
slice:
/Users/jobs/iPhone_Client/workspace/MyProject/third-party/OpenCV.framework/OpenCV
for architecture armv7s clang: error: linker command failed with exit
code 1 (use -v to see invocation)
** BUILD FAILED **
The following build commands failed:
Ld build/MyProject.build/Debug-iphoneos/MyProject.build/Objects-normal/armv7s/MyProject
normal armv7s (1 failure)
As I understood this is due to the new armv7s architecture.
OpenCV is apparently it is not compiling with armv7s.
How can I fix this issue?
Where can I find a new release of the framework that is compatible with the armv7s architecture?
And if there is no compatible framework available, is there a way to get the source code and create my own library compiled against the new architecture? Maybe some quick steps on how to do it?
Note: Just to note that I need the build for armv7s not armv7.
Thank you
This answer builds upon the one given by n9986. As he suggested, I cloned the repository found at
https://github.com/jonmarimba/OpenCV-iOS
When I downloaded it several references inside the project to different libraries were broken which was strange but they were easy to fix. After they were fixed it behaved exactly as n9986 described, outputting libraries compiled for both armv7 and armv7s. For my purposes however I required that they be bundled into a .framework so that they could be a drop in replacement for the old .framework I have been using.
Previously I had downloaded the latest version of Opencv for ios here and spent quite a bit of time trying to modify their cmake files to compile with support for armv7s. jonmarimba has already restructured the xcode project file to strip away its cmake dependencies which makes changing the target architecture much more intuitive. Unfortunately he does not build as many libraries as come with the standard openCV build. I added a new target to jonmarimba's project for opencv_world which is the target used in the standard openCV release for converting into a framework. Once that was built I used it as a drop in replacement for the static library in the framework file structure generated by the standard openCV release.
The framework I created can be downloaded here. It works perfectly for me as a drop in replacement for my previous opencv2.framework. I did notice however that jonmarimba has not converted the targets for opencv_videostab, opencv_stitching, or opencv_nonfree. It is possible that if you use one of those libraries my framework will not work for you. If that is the case let me know and I can try to set those up as targets in the xcode project for you.
Update
To compile for other architectures, change the target architecture in the included xcode project to whatever you like for the opencv_world library. After you build it, go find the library you just built. Rename the opencv_world library to opencv2 and replace the library file found in the .framework with opencv_world.
Update2
OpenCV 2.4.3 now compiles with armv7s support by default so these solutions are outdated.
Clone the Xcode project for opencv and update the opencv git submodule as per the README:
https://github.com/jonmarimba/OpenCV-iOS
Check the build settings, make sure iOS6 and armv7s are present. Click build. You should now have the armv7s compatible .a files. I just tried this:
$ file libopencv_core.a
libopencv_core.a: Mach-O universal binary with 2 architectures
libopencv_core.a (for architecture armv7): current ar archive random library
libopencv_core.a (for architecture cputype (12) cpusubtype (11)): current ar archive random library
The last entry is for armv7s as per my research so far.
Edit: The last entry is indeed armv7s. I ran the Xcode's own lipo info command:
$ xcrun -sdk iphoneos lipo -info libopencv_core.a
Architectures in the fat file: libopencv_core.a are: armv7 armv7s
You can always just not target armv7s, and only target armv7. Your application will still run fine on the iPhone 5, it just won't be fully optimized for the new instruction set.
Simply, I cloned source from here and build with this tutorial.
Then I got opencv2.framewok that works with armv7, armv7s and simulator.
Stating the obvious, you will need to recompile and rebuild the library openCV.framework and target it for armv7s.
Adjust the library "project settings" and "target settings" before rebuild. good luck!
Probably its possible to build it with CMake. I had one year ago a problem with a medical library I wanted to build for iOS. I could handle that with CMake.
Perhaps this link can be a starter.
http://computer-vision-talks.com/2010/12/building-opencv-for-ios/
Good luck!
Pass -DCMAKE_OSX_ARCHITECTURES="armv6;armv7;armv7s;i386" to cmake when compiling OpenCV library/framework for iOS.

How to specify compatibility version for dylib in iPhone projects?

I recently added a static library (mobclix) to my iPhone project which required me to set the Base SDK to 3.0. This library is claimed to be compatible with 2.2 and so far it looks like it's true. I set the project's Deployment Target to 2.2. No problems there.
Now, I am also using libxml2 in this same project. Apparently, the libxml2.2.dylib in OS 3.0 is newer than in OS 2.X (version 10 and 9 respectively). However, my code that uses libxml2, was already compatible with the libxml2 version included with OS 2.X. Since I needed to set the Base SDK to 3.0, the "compatibility version" / minimum version requirement / dependency is automatically set to the newer version of libxml2. When I try to run the app in OS 2, I get this runtime error (obviously):
Dyld Error Message:
Library not loaded: /usr/lib/libxml2.2.dylib
Referenced from: /Users/Martijn/Library/Application Support/iPhone Simulator/User/Applications/4D5456DE-F297-4DF4-ACA6-DA8BBBBBA914/Luisterpaal.app/Luisterpaal
Reason: Incompatible library version: Luisterpaal requires version 10.0.0 or later, but libxml2.2.dylib provides version 9.0.0
Is it possible to override the version requirement somewhere?
Or other ideas to solve this issue?
The compatibility version is set according to the version embedded in the dylib of the current SDK during build. I have not found a way to change or override this.
However, in the target in Xcode under the "Link with binary with libraries" branch there is an option to link a dylib "weakly". This skips version checking at the time of loading the dylib (runtime). It's your responsibility then to only make calls to existing functions. Making calls to non-existent functions will crash the application.
Apparently there was a change with SDK 3.0 that broke compatibility with libxml. Apple have posted about it here:
http://developer.apple.com/iphone/library/qa/qa2009/qa1659.html