Xcode Issue: Library not loaded: #rpath/libswiftAppKit.dylib - swift

I've finished working on a Cocoa (not iOS) application with Swift 3. I've tested it on a desktop computer. It works fine. I've tested it on another desktop computer. It works fine. I have even managed to send it over to iTunes Connect. But I have not submitted it because the same application fails to run on a MacBook Pro (2013). Anyway, I've tested it on a MacBook Pro with a retina display. That's when the entire problem started happening. Actually, this desktop application ran on the same MacBook Pro a few days ago. I think it was not sandboxed yet. Now, every time I send a binary copy that runs on different iMac models to MacBook Pro through AirDrop and try to run the application, I get an error that says EXC_CRASH (Code Signature Invalid). So I've deleted some files inside Developer /Xcode / DerviedData. Now, I cannot even debug the application. When I debug it, it hangs up with a fatal error message, which I have never seen before.
Now, if I double-click on an application that Xcode has generated, I get a crash report that says Library not loaded: #rpath/libswiftAppKit.dylib. I thought that I might have deleted some system files by accident. But if I debug existing macOS and iOS apps, I have no problem running them. Fortunately, the entire problem occurs on this particular Xcode project.
One topic that I've found here suggest that we set the Always Embed Swift Standard Libraries option to Yes. I've done that with no vail. I have also read a suggestion that says something about setting the When using this certification option on a developer certificate to Use System Defaults, which doesn't help. Another suggestion that I've tried is clearning cache (Command + Shift + Option + K).
If you have any suggestions, please let me know. Thanks.
More information
I have also seen a bizarre alert message repeatedly on MacBook Pro that says "%#" cannot be found. This error message poped up when I double-clicked on the application icon. It may refer to
String(format: NSLocalizedString("whatever", comment: ""), variable name)

I have solved the problem! I had the same problem with you. But from the answer in https://www.reddit.com/r/swift/comments/4nac9s/using_swift_frameworks_with_command_line/, I have known that the key is the rpath.
So I try to add this path to the project in the following two settings:
${DT_TOOLCHAIN_DIR}/usr/lib/swift/macosx/
Runpath Search Paths
Library Search Paths
I don't know why need to add both the two settings, but it works!

Related

Unable to run app in Simulator Xcode 6

Yesterday i was testing my app in the iOS simulator and everything was working fine. I then decided to run the app on my iPhone and i got the error unable to install application, Unknown error occurred this has happened before so I cleaned my build folder (as this has fixed this issue before) however, the same error occurred. I then ran the app in the iOS simulator again and now i get the error Unable to run app in Simulator, An error was encountered while running (Domain = LaunchServicesError, Code = 0). I find this very weird as i didn't change anything besides trying to run the app on my iPhone. I have tried every solution given on this post and still no luck.
I'm sorry if my question doesn't contain much detail but as I said I didn't change anything and it was building and running fine a minute before plugging in my iPhone and trying to run it on there.
Any help would be much appreciated.
edit
I tried running other projects (with and without extensions) and they are working on both simulator and iPhone, therefore the problem must be within my project. (my project does have a today extension)
In that kind of cases I usually :
Product > Clean
Close xCode
Delete the Derived Data (in ~/Library/Developer/Xcode/DerivedData subfolders)
Delete the app on the iPhone
Reboot the iPhone
Restart and rebuild
I had this problem. In my case, it was caused by the Build value being blank. After putting a value there, and resetting the simulator once more, the issue went away.
I had the same problem and checking the system log carefully helped me to identify a coliding library that was causing this error. You can also check this answer if you are using extensions.
Generally it means there is a problem with the build, it may be due to old cache (solved by a clean build) or a project definition error (missing library, bad definition in info.plist, etc).
In my case it happened only on iOS 8, turns out that my widget had the wrong bundle ID.

Guard Malloc doesn't work

I'm experimenting with different profiling options that Xcode provides, but when I enabling Guard Malloc option in Diagnostics tab and trying to run, I'm getting this error with immediate crash:
dyld: could not load inserted library: /usr/lib/libgmalloc.dylib
And it is right, /usr/lib/ doesn't contain this library. I've located it in:
Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/lib/
So I've created link, and started Command Line Tool (just to be sure, because it apparently part of MacOS SDK), enabled Guard Malloc again but the problem remains.
I don't quite get where is a problem: does it new Xcode 4.3 inadvertence, problem with my system or planned decision by Apple to replace it with something else (maybe Instruments)?
on device or simulator?
According to http://developer.apple.com/library/ios/#DOCUMENTATION/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html
You can use this option both Mac apps and also for iPhone applications running in the simulator.
Well, I got stuck by this too. From an apple list:
http://prod.lists.apple.com/archives/xcode-users/2012/Feb/msg00197.html
That's a known issue that's being investigated. I think that you may be able to work around it by installing the 10.7.3 combo installer
Which means you need to download the combo installer from: http://support.apple.com/kb/DL1484?
I'm trying it now to make sure it works, but the person on the mailing list said it worked.
Problem came up again recently, combo update didn't helped (libgmalloc.dylib was in place).
New solution was to Repair Disk Permissions in Disk Utility:
It looks like you can't enable Guard Malloc when debugging directly on a device (at least iPad in my case), even when running the latest and greatest versions of everything. Running still works in the simulator though.

XCode error "The application bundle does not contain a valid identifier."

Recently, after upgrading to Lion and Xcode 4.2.1 I am getting this error when trying to run my app on my iPhone 4S:
"The application bundle does not contain a valid identifier."
My identifier is indeed valid, and I have been able to run my app with this identifier earlier.
The problem might appear when I change computers.
I have two computers that I am using to code my app, and I am using Dropbox to keep track of my files.
Restarting XCode, my mac and my iPhone does not work.
Cleaning the target and rebuilding does not work.
The only thing I have been able to do to fix it is to create a completely new project and moving my files. This made things work until I swapped computer. Now I am in the same trouble again.
Any idea? Anyone?
Three suggestions:
Check that your developer key is in both computers
Did you try to update the project? There is a strangly-named key in the middle bottom under the project's properties. Try this.
I had similar issues. I found that some things weren't updated when I updated osx and xcode. To get out of the situation, I would suggest creating a new project and copy paste code, files and build settings. This might seem stupid, but you know apple is not good at creating IDE's. You might just get your self lost in the undocumented settings.

Debug and Release Build works fine but the Distribution/AdHoc Crashes

HI there,
Some users of my application have reported me that my application is no longer working. It closes just after launching it.
I have been trying to identify the crash for days with no luck using builds debug and release and testing it in several devices. This morning I was surprised when I was able to reproduce the problem by generating a AdHoc version and installing it on my iPhone.
I have already tried to remove all the custom configurations and recreate them using a copy of the release version but it did not work.
I got this error below when I was running in the simulator and the crash reports also points to the same place...
Detected an attempt to call a symbol in system libraries that is not present on the iPhone:fwrite$UNIX2003 called from function -[My7zipExtract extract7zFile:]
So, my question is: What is the difference between build Debug/Release and Distribution (App Store/Ad Hoc). I have double checked everything and the only difference are the certificates.
Any help is appreciated.
Many thanks
I'm having precisely the same problem right now. I copied my Debug Xcode configuration to create the AdHoc one, adding entitlements and changing the certificate.
Doing good old printf-debugging ;) i found that the c++ constructors seem to be called differently / not called at all on the iPhone when using the AdHoc build.

Error Installing iPhone App on Device

I set up all my certificates and keys today and am trying to run my project on my iPhone.
I'm encountering this strange error:
Your mobile device has encountered an unexpected error (0xE800003A) during the install phase: Verifying application
Poking around the Apple Developer forums, I've attempted to set new certificates and provisioning profiles as well as editing Info.plist, but no matter what I do I can't seem to run the app on my device.
The only think I can currently think of is that my project name in Xcode differs slightly from my development provisioning profile (it uses a question mark), but I've named it according to Apple's conventions: com.mycompany.myapp, so I'm unsure if that's the problem.
Any ideas?
Edit: I've hard restarted the phone, rebooted Xcode, cleaed my targets, set up a new wildcard App ID and respective provisioning profile and still nothing. Any other ideas?
It turned out that I had 2 certs in keychain that were simultaneously overwriting each other! I hope this helps people in the future.
You should create a wildcard app ID; com.mycompany.*. That may help.
I've encountered this on many occasions. What i do is clean all targets, shut down xcode, and hard reboot my phone.
This is a different error than the more common problem of getting the cert wrong...
Restore the phone (using the XCode Organizer to reload the latest OS), to be safe do not restore from backup when you sync with iTunes the first time (it'll still keep your number when you sync even if you don't use the backup). I've had to do this a very few times, the last one was when it was in the middle of deployment when I unhooked the phone from the cable (had to answer a call).
Try the reboot (of the phone) first, hooking it up with XCode off. But if that does not solve things, restore is the way.
The console tab in the XCode Organizer sometimes gives helpful hints as to what happens during the install phase. In one case my problem was my app already existing on the phone. I deleted my app and the install succeeded.
Regardless, it looks like a lot of error messages are bundled into this one cryptic message and to really diagnose what is going on, I found the Console tab very useful...
One other thing to try is reinstalling the iPhone SDK. I ran into an error like this when I first got my developer key and this was the only way around.
Just want to say to everyone, when you go to edit Targets-> be sure to set "configuration" in the top left corner to "All Configurations" or the correct config you are building for (Debug or Release). You might think you have things set correctly but it will be for the wrong configuration.
I've seen that error on a correctly provisioned device that has had success installing apps from XCode before, and I've had luck restarting the device and trying again. Maybe that will help.
Try running in Release mode instead of Debug. I have a working project with this problem. No idea what the issue was, but running it in Release mode works, but Debug mode produces the error code.
I have a support ticket open with Apple dev support for the same problem, and (FWIW) I'll post their recommendations if and when they can get my toolchain working.
Try this: (source: http://ephemera.lifewithalacrity.com/iphone_development/)
Even though this is supposedly only for Distribution builds, it helped me to be able to install my Debug version on my iPhone again, after it mysteriously broke yesterday.
"just triple check that all the code signing in your project properties are clear or default"
Note, this is the PROJECT properties as opposed to the TARGET properties. I set my Code Signing Provisioning Profile back to the default and removed the Code Signing Identity string.