Xcode12 CoreNFC simulator library not loaded - ios

Our app uses CoreNFC to scan NFC tags or you can use QR if NFC is not supported. This worked pretty well and we were able to run the app in the simulator for (ui) testing purposes.
Until Xcode12 / iOS14 GM builds. In iOS13 (or lower) we wouldn't have any issues running it on a simulator.
But in Xcode12 running it on a iOS14 simulator iPhone11 we would get the following:
dyld: launch, loading dependent libraries
DYLD_SHARED_CACHE_DIR=/Users/xxx/Library/Developer/CoreSimulator/Caches/dyld/19G73/com.apple.CoreSimulator.SimRuntime.iOS-14-0.18A372
DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
DYLD_LIBRARY_PATH=/Users/xxx/Library/Developer/Xcode/DerivedData/xxx-awnlestrbvesqqbynrhmluzhbcsc/Build/Products/Debug-iphonesimulator:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSi
dyld: Library not loaded: /usr/lib/libnfshared.dylib
Referenced from: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreNFC.framework/CoreNFC
Reason: no suitable image found. Did find:
/usr/lib/libnfshared.dylib: mach-o, but not built for platform iOS-sim
That the simulator crashes makes sense to me, since the simulator can't scan NFC tags, but this is what I've done:
I already linked to the CoreNFC framework and made it optional, like described here: Xcode 10, Swift 4 app with CoreNFC crashes in review on iOS 12
Put #if canImport(CoreNFC) around import CoreNFC and it's underlying NFC code.
Cleaning the build folder and deleting derived data.
Created an empty Xcode12 project: https://github.com/basvankuijck/CoreNFCCrashProject, same result.
Removed all the listed simulators and re-added one
Added -weak_framework "CoreNFC" to the Other Linker Flags build setting
Obviously removing any references to the CoreNFC framework by either commenting out code sections and removing the framework link, makes the crash disappear. But that's not a suitable option.
Running it from Xcode12 on an iOS13 simulator 'device' works perfectly. So I can't seem to figure out what is causing this behavior

Apple obviously forgot to add libnfshared.dylib for whatever reason in the final version of Xcode 12 for iOS 14 simulators. A working workaround until Apple fixes this is to copy the missing lib from Xcode 12 beta 6 over (download the beta from Apple's developer download section). The missing lib can be found here and must go into the same directory for final Xcode 12
This works for me. 💯
If you want to avoid the hassle of downloading 11.25GB Xcode 12.2 beta for a single file. I have the file to share.
You may execute the following command to download and place it inside the Xcode package:
sudo curl https://storage.googleapis.com/mobile-simulator-build/libnfshared.dylib -o /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libnfshared.dylib
Hope it helps 😉

Apple obviously forgot to add libnfshared.dylib for whatever reason in the final version of Xcode 12 for iOS 14 simulators. A working workaround until Apple fixes this is to copy the missing lib from Xcode 12 beta 6 over (download the beta from Apple's developer download section). The missing lib can be found here and must go into the same directory for final Xcode 12:
Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib

Linker says that the file libnfshared (mach-o) doesn't include the binary for a simulator, which is strange because it's Apple core framework.
Create a new project with Xcode 12 and import the NFC framework. Build it and run it on a simulator. If it doesn't crash then compare the build settings specially for DYLD between those projects.
If this doesn't help, delete all the simulators and recreate new ones.
Updated:
It's bug in IOS 14 and someone has submitted a radar: openradar.appspot.com/FB8699389

A bit in later, but maybe useful for others...
scenario:
App must use NFC (where available)
Must work also on pre-NFC device (i.es. iPhone 6 with iOS12)
Build for iOS12
Some "good to use" technics:
#if canImport(CoreNFC)
import CoreNFC
...
instead of old:
#available(iOS 11.0, *) .. and similar..
Notes:
"canImport" works at compile time, so if You want to solve:
"dyld: Library not loaded: /System/Library/Frameworks/CoreNFC.framework/CoreNFC
Referenced from: /var/...
Reason: image not found" message
we have to pay attention to LINK section.
Link section:
Xcode 12.5 does not allow "optional" linking in its menus
we must go to "Other Linker flags" and add:
-weak_framework
CoreNFC
on 2 lines
(in text will be:
OTHER_LDFLAGS = -weak_framework CoreNFC -lstdc++
)

I was having same issue with my application, Although I wasn't using CoreNFC framework. this gets solved with
Xcode-12.2 beta 2. Released on September 29, 2020

Related

Build fails due to architecture deprecation armv7 in Xcode 14

I am trying to build and run my unity application in my iOS device for debugging purpose. I get a build file from Unity. Then I open .xcodeproj file in my xcode 14. When I run the app, it gives this error:
When I google it, I find out that Xcode 14 does not support this architecture anymore:
So I cannot debug my unity app in my iOS device. You may say that okay use older version of Xcode like 13, however xcode 13 does not support iOS 16 or later (my device has iOS 16). I am little bit stuck in there. How can I get rid of this situation? Is there any way to change the armv7 architecture that is created by unity build file?
I tried to solve armv7 error but I could not. Is there any way to handle this problem with unity and Xcode 14 environments?
I ran into this as well and don't see a solution with Xcode 14. I may have to investigate how to revert to Xcode 13 as I don't think I use any advanced iOS features and have older devices to test on.

AppTrackingTransparency module not found in Xcode 11.6

I am trying to compile my Flutter project in Xcode 11.6, however it shows me the error -
ld: framework not found AppTrackingTransparency
All my code seems to be working fine, however after research I found out that this is something that is required for iOS 14, but if I download Xcode 12 I won't be able to publish my app in release mode as Apple doesn't accept builds from beta versions.
You either wait for the Xcode 12 official release or copy the AppTrackingTransparency.framework into the Xcode 11.6's frameworks folder
What worked for me was that I was using a pod that was only supported for Xcode 12 that contained the AppTrackingTransparency framework as it is now a requirement if you are integrating any API that is an ad network, so check if your pods have gotten updated automatically and downgrade it if you want it to work.
If you need help implementing the 'AppTrackingTransparency', you can refer to the following question:-
No such module 'AppTrackingTransparency' Error
Hope this solves your problem:)

Xcode 10.2 Failed to Run App on Simulator with iOS < 10

I was playing around with Xcode 10.2 since the update and when I try to run my app on ANY simulator with iOS version less than 10, the simulator will not start and crash then show the error below:
dyld: Library not loaded: /usr/lib/libauto.dylib Referenced from:
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
Reason: no suitable image found. Did find: /usr/lib/libauto.dylib:
mach-o, but not built for iOS simulator
I tried to create another new project fresh without touching anything, set the deployment target to iOS 9 and run on iOS 9 simulator again, same error was shown.
UPDATE
It seems like this issue only occur when your code base contain swift. Created a new project with objective c code base did not crash the simulator. For swift yes.
SUMMARY
Xcode 10.2 contain swift code unable to run app on simulator with iOS 9
I have done all the cleaning and delete derive data and the issue still persist.
Anyone has any idea ?
FINAL UPDATE
Apple just release Xcode 10.2.1 and it is part of the known issue for simulator, please refer to the link below for the workaround/fix:
https://developer.apple.com/documentation/xcode_release_notes/xcode_10_2_1_release_notes
Appreciate #russbishop 's reply, answer accepted
This is a known bug affecting iOS 8.x and 9.x. You can work around it by creating /usr/lib/swift directories in the relevant simulator runtime root.
Downloaded simulator runtimes are located in /Library/Developer/CoreSimulator/Profiles/Runtimes.
For example, to fix the iOS 9.3 simulator:
sudo mkdir '/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 9.3.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift'
Me also got the same problem when run in iOS 9.0 simulator.
From https://developer.apple.com/documentation/xcode_release_notes/xcode_10_2_1_release_notes
Simulators for iOS 9.3 and earlier might fail to launch Swift apps with the message: “dyld: Library not loaded: /usr/lib/libauto.dylib”. (49326587)
Workaround: Run the following command in Terminal for the relevant version of iOS:
sudo mkdir '/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 9.3.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift'
For this apple given above solution in that link.
Simply
--> open Terminal
--> Type this line with your required version (In my case i changed into iOS 9.3 to iOS 9.0)
Ex: sudo mkdir '/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 9.0.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift'
--> Enter password
--> Now clean Xcode and run again
This above solution worked for me.
This seems like an iOS Simulator bug. I see this happening on simulators with iOS 12.0 but not on those with 12.4.
Still get this bug with Xcode 10.3. (Skipped over 10.2.)
I ran into this issue when I was doing unit-testing for iOS11 and iOS12.1 on Xcode11.1
The solution was to just run the unit-tests with an iOS13 simulator.
A rather annoying workaround: use Xcode 10.1 to deploy on 9.x simulators for now. It's the only way I've been able to get around this.
None of the above worked for me.
My issue is the same as this but was building an app for macOS.
Running Xcode 11 project target 10.4 whilst my OS is Mojave 10.4.6.
I had to install Xcode 10.3 and use that instead. No problems since.
My guess is its a problem with OS, Xcode version and project target.
Having to use Xcode 10.2.1 I had this issue with another library and ended up having to set always embed swift libraries to YES in build settings since the library in question was in a framework file I had.
Updating to Xcode 10.3 has fixed it for me.

Xcode: dyld: Library not loaded: AVKit - image not found

I'm trying to get a project running on an iPhone 5C, one that needs a lot of frameworks. I added all that was needed in Link Libraries.
The project works on an iPhone 5S and an iPad, but on an iPhone 5C it returns the following error:
dyld: Library not loaded: /System/Library/Frameworks/AVKit.framework/AVKit
Referenced from: /var/mobile/Applications/28EC3D4B-1011-45EA-8A6C-7D62DBC9CC09/cnContainerApp.app/cnContainerApp
Reason: image not found
Then it would seem as if AVKit.framework has not been added. Oh, but it is.
Now some of the suggestions I've read online was to:
Put it in Embedded Binaries - Tried that, but it didn't do anything. I'm also reluctant to try and touch anything on a project that works on every other device.
Clean and build - Tried it, didn't do anything.
Delete derived data - Nope.
Switch Embedded Framework with Swiftto Yes - Eh, my project was exported from Unity. No real Swift files as far as I know.
My Runpath Search Paths has #executable_path/Frameworks already.
iPhone 5C has the version of 7.0, while the Xcode project has the deployment target of 6.
If it means anything the version of the iPhone 5S it worked on was 8.4.
Any other suggestions?
Your iPhone5C iOS version is lower than iOS 8.0.The lowest iOS version to support embedded frameworks is iOS 8.If you deploy the app on a device running 7.x with the embedded frameworks, it would crash with your error log(dyld : image not found) at runtime because it is not supported.
To solve this, just upgrade your target iOS version at least to above 8.0.If you still need to keep support under 7.x for some reason, you should use static libraries instead of embedded frameworks.
here is related link

Consequences of "Embedded dylibs/frameworks only run on iOS 8 or later" warning

With Xcode 6.x we can use CocoaTouch Framework template to build a framework library and Xcode will create the .framework for us when we build, which is awesome. In our framework we want to support iOS 7.1 and up, so for Deployment Target (in our framework) we specified 7.1. Now when we build we see a warning: "Embedded dylibs/frameworks only run on iOS 8 or later". I've since read a number of blog posts on the subject that as far as running it on iOS 7.1 this warning can be ignored because it will run fine (still need to test to make sure). What concerns me is that I read a post on Stack Overflow which says an app may be rejected by Apple in the App Store (see: Xcode 6 and Embedded Frameworks only supported in iOS8)
Does it only apply when in Xcode the app links to it in General > Embedded Libraries?
The way we want our customers to link to our framework is:
Via CocoaPods
By referencing .framework in Build Phase > Link Binary With Libraries
I need to understand under what conditions App Store will reject an app which uses our CocoaTouch framework and supports 7.x iOS.
The app wont be rejected if you'll change the type of your framework to Static. See my answer here.
I believe that as long as the app deals with the framework correctly there shouldn't be any issues. Mixing with cocoapods could be tricky and honestly I don't know the best way to tackle it.
But from what I understand, if an app supports iOS 7.X -> 8.X and uses an embedded cocoa touch framework, as long as the compatibility checks are there to ensure the app doesn't crash in 7.X, there shouldn't be any reason for the app to be rejected.
We tried running the latest code on the following configurations:
iOS 8+ — iPhone 5s
iOS 7.1.2 — iPhone 4
iOS 6.1.3 — iPad 4
The App is working fine on all the three devices but the warning is present in the Xcode while compiling .
"embedded dylibs/frameworks only run on iOS 8 or later”
Also I tried to Archive the App in order to submit it to the app store it went on fine.
Also, found out a link where in an apple developer stated this to be a bug:
https://devforums.apple.com/message/999579#999579

Resources