I'm currently building an Umbrella framework (before anyone say so, I know this is discouraged by Apple, but I am in the case were I'm the owner of all the sub-frameworks, they are not distributed if they are not part of this or another Umbrella framework I may create, and we are in a closed source configuration) within Xcode 8.
I've followed this post to create the framework: https://stackoverflow.com/a/41815368/2572568
Everything is working fine except that I got the following error:
dyld: Library not loaded: #rpath/B.framework/B
Referenced from: /private/var/containers/Bundle/Application/E0113060-CA91-47F8-BEE3-BDF1F847DB3A/app.app/Frameworks/A.framework/A
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/E0113060-CA91-47F8-BEE3-BDF1F847DB3A/app.app/Frameworks/A.framework/Frameworks/B.framework/B: required code signature missing for '/private/var/containers/Bundle/Application/E0113060-CA91-47F8-BEE3-BDF1F847DB3A/app.app/Frameworks/A.framework/Frameworks/B.framework/B'
app is the Application using the Umbrella framework A which has a sub-framework B
I found that disabling bitcode from all the projects is solving this issue (and that's what I am doing now) from this thread : https://github.com/CocoaPods/CocoaPods/issues/3661
So here are my questions:
What does disabling bitcode is exactly doing ? I found that Apple can run optimization after you submitted your code. Are these speed optimization or disk space optimization, or any other optimization ?
Am I doing something wrong building my Umbrella framework ? Is it possible not to disable bitcode ?
First of all:
I came into the exact same problem today and I couldn't fix it. But removing Bitcode fixt it for me. Thanks for that
To your questions:
Bitcode is something kind of similar to Java's Bytecode. Your app gets compiled completely, but not in machine code (like assembler). Your app is compiled to Bitcode. This helps Apple to build different versions of your app on their server. One for 64bit and one for 32bit devices. Then they separate both apps, which saves disk space on the actual device.
And they probably have some further optimisations, which could speed up the app. Generally it's not needed today.
I tried almost everything I could imagine and at the moment I would say: No it's not possible to disable bitcode, if you have a big umbrella framework. Can you check if you have sub-frameworks in your umbrella framework which do not support Bitcode ? Like AWS SDK, Facebook SDK...
It may be possible to support Bitcode if all sub-frameworks support Bitcode. This answer seems promising me, but it's a bit old: https://stackoverflow.com/a/27638841/1203713
Regards,
Alex
Ok so after a few more researches on completely unrelated questions, I found this thread : https://github.com/Carthage/Carthage/issues/535
In substance, this solve question 2 and another one : Yes, you can enable bitcode for your Umbrella framework.
To do so, you must manually set a User-defined setting (inside Build settings, click on the plus in the top bar) named BITCODE_GENERATION_MODE to bitcode. This will force Xcode to build you project with real bitcode and not only a bitcode subset.
You have to set this flag for all the frameworks under your Umbrella framework.
Related
Question stated simply in title. Here is my setup:
Building a dynamic framework that optionally links (weak link) to GoogleInteractiveMediaAds.framework. For apps that use my framework, GoogleInteractiveMediaAds is an optional dependency, and the framework will work fine without it. This is currently working.
However the problem arises when attempting to rebuild from bitcode, as typically happens when exporting an Ad Hoc build with "Rebuild from Bitcode" selected. The bitcode compile process fails with:
ipatool failed with an exception: #<CmdSpec::NonZeroExitException: $/Applications/Xcode.app/Contents/Developer/usr/bin/bitcode-build-tool ...
And looking deeper into the log file I find the error description:
Failed to resolve linkage dependency MyFramework arm64 -> #rpath/GoogleInteractiveMediaAds.framework/GoogleInteractiveMediaAds: Could not resolve #rpath in #rpath/GoogleInteractiveMediaAds.framework/GoogleInteractiveMediaAds from MyFramework
error: GoogleInteractiveMediaAds not found in dylib search path
Note: GoogleInteractiveMediaAds.framework does include bitcode.
Obviously this error is avoiding by not selecting "Rebuild from Bitcode". If I were to answer my own question, I'd say, no, it looks like when compiling from bitcode, you cannot use weakly linked frameworks. Simply from the fact that the bitcode compilation step is trying to link to a framework which isn't included in the app target. However I haven't been able to find any official documentation surround using weak linking with bitcode, or any relevant StackOverflow answers about it, so I'm not sure if I'm missing something or if there is some relevant compiler/linker settings that I am missing to get this to work.
In your case, you will need to wait for the fix in framework itself.
We've got similar issue while distributing our framework, which I described here and I just wan't to share results of our investigation, because seems that no-one has published their results.
No needs to distribute without bitcode. Long story short, there were LLVM instrumentation included, which prevents AppStore processing. I've written a whole blog about XCode 12 and BigSur issues with XCFramework.
To sum up, here is a few required steps to make sure while creating XCFramework for distribution:
Using archive builds is a MUST, release build isn't enough
BUILD_LIBRARY_FOR_DISTRIBUTION must be set to YES
SKIP_INSTALL must be set to NO
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO to turn off GCC instrumentation and remove them from the binary
CLANG_ENABLE_CODE_COVERAGE = NO to turn off code coverage tools from the binary
Having all of the above helped to solve our preparing and distribution problem and hopefully save you some time if you happened to face same issues as we did.
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]
I'm trying to use a fat dylib I've made that contains the latest version of tbb with code for all architectures I may be targetting (armv7, arm64, i386 and x86_x64)
Since iOS8 using dylib(s) is meant to be possible, in fact one of the error messages I found googling was the following one:
ld: embedded dylibs/frameworks are only supported on iOS 8.0 and later
Which seems to suggest that embedding dylibs is actually possible and we aren't only restricted to the new so called dynamic frameworks, yet, when I try to run my project I get the following:
dyld: Library not loaded: #rpath/libtbb.dylib
Referenced from: /Users/user/Library/Developer/CoreSimulator/Devices/B4DCFF3E-10B2-4C01-953F-BD26D14300E7/data/Containers/Bundle/Application/8C84A844-97FC-4993-A37E-A456C4E2240F/TestTBB.app/TestTBB
Reason: image not found
I thought it would be due to the dylib not being automagically copied into the app being built so I added it to the "Copy Bundle Resources" section in the projects "Build Phases" and I've since made sure that the libtbb.dylib is in fact being copied into the app and yet I keep getting the message saying that it can't be loaded.
I've tried using the "Embedded Binaries" section under "General" but it seems to be restricted to using only the new framework types.
Is there anything I might be missing?
As you may have noticed I'm trying to use TBB which comes with its own build makefiles that generates dylibs, I'm assuming that if it does it's because dylibs can be used, legally since the iOS8+ update.
I have seen ways of getting dylibs to load, but these aren't the ones that Apple would accept in their AppStore, I'm trying to do this for an app that is currently on the AppStore and I have no plans of getting it removed or not accepted after an update so I'd like to go with whatever the new "legal" way is to get dylibs loaded. My app is targetting iOS9.2+ since the latest update so this shouldn't be an issue.
All I can find are ways to get dynamic frameworks loaded but no info about actual dylibs even though the error message clearly states that they could be used.
Alternatively, is there a way to build a dynamic framework out of existing dylib files?
Thanks in advance.
I have to admit that with the release of iOS 8 I am a bit confused about dynamic and static frameworks in iOS.
I am looking for a way to distribute a library that I created, and I need to support iOS 7 and above. (Note: This will be a proprietary framework. I cannot use cocoa pods, and I also cannot distribute the source). Here is what I already know:
iOS 8 introduced "embedded frameworks" for iOS, but, as I understand, they do not work for iOS 7, only for iOS 8 and above.
I have the option of distributing my library as a static library (.a file) and also distribute the headers. I know that this is a common way of dealing with the situation, but I would like to find something simpler than that (and also to bundle some resources with it, if possible).
I have also found that iOS 7 does not support dynamic .framework libraries (only static) because it doesn't support dynamic linking. But iOS 8 does, as well as static linking.
And here are my questions regarding this information:
I saw that I can create a .framework target, and make it static, by changing the Mach-O type to "static library. Would that be enough in order to support iOS 7 without any problems, and also to distribute my library as a .framework bundle? If so, why is "embedded frameworks" in iOS 8 that big of a deal, as many resources on the internet are suggesting? Am I missing something?
Is it necessary to codesign the .framework just as I do with any other application I make?
What if I need to include other resources (like Core Data or Images) with my .framework file? Will I need to make a separate .bundle file for that?
Before iOS8, Xcode only allowed the option of creating static libraries for iOS. The common problem with that was we had to ship the binary and headers separately.
Later, some developers came with the idea of creating 'static frameworks'. [the .framework is just a folder with symbolic links to the lib and the headers]. One such example is https://github.com/jverkoey/iOS-Framework
This option will work for iOS 7 or 8 or before that. Because they are just static libraries with the convenience of bundling the headers files along.
As for your questions of the resources, we would need to bundle them in '.bundle'.. For shipping them i am not sure if we can enclose them in the .framework folder.. In the past i used to ship my libs as a static framework and bundle...
However the above option will not work for you if you use Swift. Xcode does not support building static libraries that include swift code.
You must go with Dynamic frameworks if there is swift usage. In theory, Dynamic frameworks work in iOS7.. But, i think iTunes Connect will reject if the app is targeting iOS7 and uses Dynamic frameworks :-).
Hope this helps
Static vs Dynamic linking
static or dynamic in name usually points into a Linking[About] type
Frameworks can be static or dynamic[Check static or dynamic]
You can change the format of library that will have an impact on a Linker by changing Framework target -> Build Settings -> Mach-O Type[About] to Static Library or Dynamic Library. By default Xcode has Dynamic Library value.
Depends on this setting different types of binary will be generated
After you successfully configure a consumer[Link vs Embed]
Static Linker ld: at compile time will include all code from the static library into the executable object file.
Dynamic Linker dyld: at load/run time will try to find the embedded framework using #rpath[About] and link it
[Vocabulary]
With Xcode 9 onwards you can create static frameworks for Swift as well. This is possible due to ABI source compatibility. All you need to do is just change the Mach-O type under build settings of the framework target.
This technique is also applicable to Hybrid Frameworks(frameworks with Swift and Objective-C code).
I don't have all the answers but I'll try to address some of your questions here.
You will get a warning for using these frameworks in iOS 7, however that's all it is, a warning. See this answer.
You can include other resources like CoreData however you'll need to create them in code manually. Here's a tutorial showing how to create a core data model.
You have to code sign dynamic libraries for iOS.
You need to make sure your framework supports both simulator and device architectures if you're planning to distribute it.
Swift does not work in static lib. If you have to use dynamic framework, you have to set min iOS to 8.0 because AppStore reject ios 7 with dynamic framework
As a followup to my other question, I'm continuing to have issues submitting my iOS 8 app (which includes a Sharing Extension and a framework target). On a submission attempt I receive the above error message. Others with my issue (as pointed out in the afore-linked question) have the same issue, but resolved it in ways that aren't relevant to my case.
The error message implicates my Sharing Extension target, which links to a framework that I wrote, which is shared between the Extension and the app. I'm pretty sure Apple was clear that I'm allowed to use frameworks in Extension targets (in fact, it's preferred!). So what other causes might there be for this error?
Well, the answer seems simple enough: in the Extension target I was embedding the framework (Build Phases > Embed Framework). Once I removed that setting, everything works fine.
Sigh.
I had to remove
(Build Phases > Embed Pods Frameworks)
From the today excitation.
Was able to upload to appstore but this bring other problem the today excitation is not working
dyld: Library not loaded: #rpath/AFNetworking.framework/AFNetworking
For me, Aaron's answer was only half the answer.
After removing my framework from my extension's Embedded Binaries, I had to add it to my extension's Linked Frameworks and Libraries.
(Both can be found in the extension's General tab.)