Determine the Swift compiler version used to create a Framework - swift

I want to know what compiler version was used exactly. In my example I tried the following:
otool -L TestFramework
TestFramework:
#rpath/TestFramework.framework/Versions/A/TestFramework (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1675.129.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 1281.100.1)
#rpath/libswiftCore.dylib (compatibility version 1.0.0, current version 1103.8.25)
It looks like 1103.8.25 could be useful, but when I look the version up (on Wikipedia) it doesn't help, as the versions there look like this:
5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1),
5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8),
5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
etc..
It looks like that my 1103.8.25 might hint to one of these:
5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29),
5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51),
5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53),
5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53),
5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
, because of the 1103 but which one is it?
I am aware that I can check the .swiftinterface file if the binary has been compiled with ABI stability, but let's assume it hasn't been. How does Xcode do it?
Is there a list of libswiftCore.dylib versions somewhere that can be used for lookup?

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

How to debug objc runtime linking multiple instances of the same library

I'm working on a Swift project which links agains libSDL2. I had to patch a few things in that library to fit my needs and thus it currently lives in the same directory as my project and is compiled and linked from there. When I run my application, I get a bunch of warning form:
objc[13894]: Class SDLApplication is implemented in both
/opt/local/lib/libSDL2-2.0.0.dylib (0x10f116228) and
/Users/<my-project>/Libraries/SDL-install/lib/libSDL2-2.0.0.dylib
(0x10ef6d240). One of the two will be used. Which one is undefined.
I do have a globally-installed instance of libSDL2 under /opt/local, installed via MacPorts and used by some applications also installed via MacPorts, so I can't remove that.
I tried looking at the libraries that the compiled binary links agains but could not find a reference to the instance installed in /opt/local.
$ otool -L .build/debug/TestLines
.build/debug/TestLines:
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1770.255.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 1292.60.1)
/Users/<my-project>/Libraries/SDL-install/lib/libSDL2_image-2.0.0.dylib (compatibility version 3.0.0, current version 3.3.0)
/Users/<my-project>/Libraries/SDL-install/lib/libSDL2-2.0.0.dylib (compatibility version 17.0.0, current version 17.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1770.255.0)
#rpath/libswiftCore.dylib (compatibility version 1.0.0, current version 1200.2.41)
<...>
How can I debug this issue?
In the end it was easy to figure out. It turned out that the libSDL2_image-2.0.0.dylib was linked against the instance of libSDL2 from /opt/local. To figure this out I simply had to follow the libraries linked by my binary and inspect those instead of just the main binary:
$ otool -L Libraries/SDL-install/lib/libSDL2_image-2.0.0.dylib
Libraries/SDL-install/lib/libSDL2_image-2.0.0.dylib:
/Users/<my-project>/Libraries/SDL-install/lib/libSDL2_image-2.0.0.dylib (compatibility version 3.0.0, current version 3.3.0)
/opt/local/lib/libSDL2-2.0.0.dylib
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)
/opt/local/lib/libiconv.2.dylib (compatibility version 9.0.0, current version 9.1.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 52.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1677.104.0)
/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1355.22.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1069.24.0)
/System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO (compatibility version 1.0.0, current version 1.0.0)
(The root cause in this instance was that I had to pass --sdl-prefix in addition to --prefix to the ./configure script from SDL_image)

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.

dyld: Library not loaded when build to iphone 4

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.

iPhone App call third-party dylib failed

Hey, guys! I want to wrap the vlc, importing the vlc dylibs. But this simple iPhone App call those third-party dylibs failed at the beginning of loading without any prompts. I even try to make a 'hello world' xcode project, just add libvlc.2.dylib & libvlccore.0.dylib but not calling, without any 1 more code manually. After download it to the iPhone device(3.1.3), it splash and exit immediately, no info throw out. BTW, all the dylibs imported were put to the right dirs. It really make me confused! Could any body show me the solution, appreciated!
run otool on device:
root# otool -L test1
test1:
/System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 678.51.0)
/System/Library/Frameworks/UIKit.framework/UIKit (compatibility version 1.0.0, current version 1000.0.0)
/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics (compatibility version 64.0.0, current version 359.16.0)
/System/Library/Frameworks/CoreData.framework/CoreData (compatibility version 1.0.0, current version 248.0.0)
#executable_path/PlugIns/libvlccore.0.dylib (compatibility version 1.0.0, current version 1.2.0)
#executable_path/PlugIns/libvlc.2.dylib (compatibility version 3.0.0, current version 3.2.0)
#executable_path/PlugIns/liblive555_plugin.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.2.1)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation (compatibility version 150.0.0, current version 478.52.0)
iPhone apps cannot link to any additional libraries except those that are on the iPhone already. You need to compile any external libraries into your binary (as a static library).