I developed a Xamarin Cross Platform application that is working perfectly on Windows but when I try to recompile for Android I get the following error:
Can not resolve reference: `Windows.Foundation.UniversalApiContract
I use the Windows.Foundation.UniversalApiContract reference because of the Windows.Storage class (generate files in internal memory).
I understand that I may have to change the recording method on Android but I can't even get to that stage...
How do I resolve this situation?
Just as ToolmakerSteve said, Windows namespace relies on features that exist only in Windows. The reference should not be in the main .Net Standard library but in the UWP Application.
First, you can move the code to the Windows folder or set the #if Windows around it.
Second, you can write the code for each platform. I found the answer you can refer to Can not resolve reference: Windows.Foundation.UniversalApiContract in Android Application.
My shared library cannot resolve using RestSharp; among other related namespaces. RestSharp is an installed package and is resolvable in the Droid/iOS projects but cannot be found in the Shared Library. I know this works because I'm using RestSharp in a MonoGame project in the same way. The shared library is referenced in the Droid/iOS projects but still fails during compilation.
Any advice? I tried clean all.
Update I created a new Cross Platform Native app solution and I was able to reference in my shared library without issue. That original project is a bit older and was created with PCL originally. I still want to know why it's not working in my original solution.
I continued to have lots of namespace and type not found issues. Once I showed warnings instead of just errors I found that the csproj was missing. After removing the reference in the native apps and re-adding the issue was resolved. Quite frusterating.
Alternative titles (to aid searching)
Cannot debug Swift 2.3 framework linked to an Objective-C app in Xcode 8
error in auto-import: failed to get module 'XYZ' from AST context Xcode 8
Xcode 8 cannot debug Swift framework
warning: Swift error in module <XYZ>
Workaround for; Xcode Debugger cannot debug apps written in Objective-C only but that link against frameworks written in Swift only. (28312362)
I have an app written in Objective-C that links against some modules (frameworks) written in Swift 2.x.
Question
Everything (debugging etc.) works fine in xcode7, however when moving to xcode8 and updating the modules to use swift2.3 I was unable to debug the modules.
LLDB reported these errors:
warning: Swift error in module XYZ.
Debug info from this module will be unavailable in the debugger.
error: in auto-import:
failed to get module 'ABC' from AST context
This does not happen if I link the modules to an app built in Swift 2.3.
For me it was just as simple as it was painful and time consuming:
import SDWebImage was the PROBLEM,
because one of the frameworks had the SDWebImage already packed in it(and I couldn't see it), and that framework happened to be Objective-C, and the app was Swift.
I also added the SDWebImage to the project, because I use it in the classes I write, and that what created the mess the Xcode debugger couldn't deal with.
So basically, make sure you don't have ANYTHING duplicated in ANY way, I'd check for common things like SDWebImage for example.
use fr v instead po for debugging
For more debugging
https://www.codeproject.com/Articles/1181358/Debugging-with-Xcode
I discussed this issue with an Apple engineer named Sean at WWDC 2017.
My team spent weeks trying to figure this out, and it ended up being a bug on Apple's compiler, which we could never have figured out by ourselves. Also, it has a VERY easy workaround.
There happens to be a bug with the way the compiling flags get aggregated from the frameworks and the project, and the "pure Objective-C" project "activates" it.
Solution: add one single, empty Swift file ("Whatever.swift", or whatever) in your Objective-C project, making it not-pure-objective-c anymore (new->file->Swift file, don't create the bridging header. The file will only contain the import of Foundation).
And that's it. Problem solved.
tl:dr
Add a user defined setting under "Build Settings" for your app target.
SWIFT_VERSION = 2.3
More Info
I'm unsure if this is an Xcode 8 bug or if it's Apple policy (to try an force developers to Swift 3.0?). But... by default Xcode 8 installs the Swift 3.0 versions of the standard Swift runtime libraries.
When it comes to debugging with LLDM the Swift 2.3 modules fail to load (in to the Swift 3.0 runtime).
Forcing the app to use Swift 2.3 (or legacy Swift as Apple call it), fixes the issue.
Swift apps have this setting exposed by Xcode but you have to manually add it for an Objective-C app.
Further Advice
Port your Swift 2.3 code to Swift 3.0 as soon as possible, Apple won't support 2.x for very long.
In my case, I had to remove Objective-C Bridging header from build settings file. My Bridging header file did not do anything.. so it was okay.
I ran into the error in auto-import: failed to get module 'XYZ' from AST context message while attempting to debug in an 9.3 simulator. Switching to a 10.2 simulator resolved the issue.
I ran into this when building a framework with Carthage. Trying to debug would print the error, which referenced an Obj-C framework dependency.
I found this blog post which suggested adding a the following user-defined build setting to my project:
For Debug: REMOVE_HEADERS_FROM_EMBEDDED_BUNDLES = NO
For Release: REMOVE_HEADERS_FROM_EMBEDDED_BUNDLES = YES
This fixed the issue for me.
Try to restart Xcode. In my case it resolved an issue.
In my case there was a compiler error in the "C" code which was reported in LLDB, after fixing the error LLDB started working again.
As suggested by Tim https://stackoverflow.com/a/41876400/1840269 the root cause to our problem was a matter of duplicates.
We had a obj-c wrapper category for SDWebImage that was used from both obj-c and Swift.
When Importing the category from Swift everything blew up because of redefinition/duplicate import since the SDWebImage pod already exposed it self as a Swift module.
The solution? We re-implemented the obj-c category as a Swift extension - and kept using it from both Swift and obj-c by adding #objc in front of the extension and importing the #import "product-Swift.h" file from obj-c.
And maybe start with checking: https://developer.apple.com/library/content/qa/qa1947/_index.html.
I just took 2 days for me to resolve and debugging through print command all the time. Now I got the issue:
My project is in Swift and I was using objective-C library same as imported in pods for swift(old Objective-C project merged in this one) and was using import IQKeyboardManager as well as import "IQKeyboardManager.h" header as well. That conflicts and deleting the header one resolved my issue finally.
You can check with this type of duplicity in libraries.
So I followed this tutorial:
http://locomoviles.com/ios-tutorials/create-ios-cocoa-touch-framework-using-xcode/
Everything went fine except when I went to run the program I got the following error:
> dyld: Library not loaded:
> #rpath/SwiftFramework.framework/SwiftFramework Referenced from:
> /Users/bluke/Library/Developer/CoreSimulator/Devices/40677D10-F22B-4AE4-B767-06439AB7887A/data/Containers/Bundle/Application/8C6A5F76-C666-4B69-9353-A0ABD7DA085B/UseFramework.app/UseFramework
> Reason: image not found
I was able to solve this problem by adding the framework as an embedded binary, but I don't understand why this was needed to solve the problem.
I thought that the framework would be included in my application bundle as a dynamically linked library (i.e. not embedded in my application's binary directly) and then linked at run time. Is this assumption incorrect?
Just in case my question was unclear, I've added the following pictures.
This is what was producing the error:
If I add the framework to the embedded binaries it works:
I thought that the framework would be included in my application
bundle as a dynamically linked library (i.e. not embedded in my
application's binary directly) and then linked at run time. Is this
assumption incorrect?
Yes, it's incorrect. iOS apps link 3rd party frameworks statically, not dynamically. This prevents apps from downloading and dynamically linking code that hasn't been vetted by the app store review process.
This allows apps coded in Swift to run on devices running a version of iOS pre-dating Swift (earlier than iOS8).
Non-Apple frameworks can be embedded on iOS8 and above only.
It is also nice to add a prefix the the name identifying the developer organization so as to avoid comflicts and confusion. "SwiftFramework" looks so much like an Apple framework.
I created a Cocoa Touch static library that I want to add to a project I'm working on. The project built perfectly before I added the library but now it gives me a "codesign failed with exit code 1" error. Why would the library cause this and how can I fix it?
I'm not sure. Did you code sign the library? I have several static frameworks I've built and used without a problem. I haven't code signed them which is why I'm thinking you may have if it's possible.