I created a Xamarin iOS binding project that requires the following frameworks:
SystemConfiguration.framework
CoreTelephony.framework
libz.dylib
libsqlite3.dylib
I added the following line in my iOS binding project to the linkwith.cs file:
Frameworks = "SystemConfiguration CoreTelephony"
This seems to work correctly and tells that project to include these frameworks when binding. From what I have read, it sounds like the remaining 2 libraries need to be added as linker flags in the project referring to the DLL generated from my iOS binding project. So I created a test app, imported the DLL, and now need to add the linker flags but my project cannot find the right libraries.
My linker flags in Xamarin Studio are as follows:
-gcc_flags "-lz -lsqlite3.0"
When I build my Xamarin test app I get a few errors regarding the frameworks that cannot be found. Are there additional flags that need to be linked or do I need to do some additional configuration in my iOS binding project?
I found a great resource: http://ipixels.net/blog/specify-extra-gcc-flags-for-native-library-binding-in-xamarin-ios/
I needed to add LinkerFlags = "-lz -lsqlite3.0" to my .linkwith.cs file. I then rebuilt the library to generate a new DLL and added this to my test app. The test app builds correctly then.
If you are creating your bindings for a cocoapod using sharpie:
sharpie pod init ios nameOfCocoaPod
sharpie pod bind
you get a nameOfCocoaPod.framework file and .cs-binding files.
The nameOfCocoaPod.framework file should be added to your binding project under Native References. To change e.g. Frameworks or LinkerFlags, right-click and open properties.
Related
I have an iOS project in XCode 11.2 that requires a mix of Frameworks, some of which are available on Cocoapods and some are not. For the non-Cocoapod frameworks, I have the frameworks copied to the root of my project folder.
The trouble comes with getting XCode to be able to find both using the Framework Search Paths setting as shown here:
All of the entries following $(inherited) are actually the ones inherited from Cocoapods (these are not explicitly specified).
If I don't add the $(PROJECT_DIR) at the end then Cococapod frameworks are found fine, but my embedded non-Cocoapod frameworks get compiler errors that their header files are not found.
If I do add the $(PROJECT_DIR) at the end, then the Cocoapod frameworks are not found and I get a build error like:
ld: warning: directory not found for option '-F/Users/dyoung/Library/Developer/Xcode/DerivedData/MyApp-acdmyjbbrpbhlkfiyypetovwacrz/Build/Products/Debug-iphoneos/AWSAuthCore'
...
ld: framework not found AWSAuthCore
Why? How do I get XCode to find frameworks in both places?
Here's one way:
pod deintegrate
Open the .xcodeproj
Add the non-CocoaPods frameworks.
pod install
Open the .xcworkspace
The problem was that the CocoaPods Frameworks that I was trying to add were built only for iOS 11+, but my very old project had a deployment target of iOS 8.4.
Looking at error details in the Report Navigator as #paul-beusterien suggested was critical. I found this:
Ld /Users/dyoung/Library/Developer/Xcode/DerivedData/MyApp-acdmyjbbrpbhlkfiyypetovwacrz/Build/Intermediates.noindex/MyApp.build/Debug-iphoneos/MyApp.build/Objects-normal/armv7/Binary/MyApp normal armv7 (in target 'MyApp' from project 'MyApp')
The key thing there is the armv7 architecture. This architecture is only part of the build process if you have a deployment target of 10.x or earlier but not if you have 11.x or later. And if the frameworks you are including don't have armv7 architecture (e.g. if they are built for 11.0+), XCode gives very misleading error messages about the frameworks not being found. What really isn't found is that specific architecture inside the framework.
Bottom line: My problem had nothing to do with framework search paths. Removing $(PROJECT_DIR) from the framework search path only appeared to solve the problem by triggering a different compile-time problem to happen before it got to the linker problem.
The solution in this case is that I must change my deployment target to 11.0, then everything builds properly.
My iOS app follows the "Photos Extension" template:
- A standalone, "container" app
- A Photo Editing extension, which is deployed by embedding it within the app above.
As suggested by Apple, code that is shared by both the app and the extension is gathered in a "core" cocoa framework that is embedded in the app, and to which both the app and the extension are linked.
So my Xcode project contains three targets:
The Framework target,
The Photo Editing Extension target, which links to the Framework but does not embed it, and
The App target, that embeds the Extension binary and the Framework binary, and links to both.
So far, so good.
Furthermore, the framework, the app, and the extension depend on two libraries MyLibraryA and MyLibraryB I have on Github (and in turn, MyLibraryA depends on MyLibraryB).
I originally set the dependency on MyLibraryA and MyLibraryB using Carthage, and everything was working fine.
Then, I decided to migrate my libraries A and B to Swift Packages.
I removed all Carthage-related settings in project and targets, framework search paths, etc. to make sure the Swift Package versions of my libraries are referenced and not the cached Carthage builds. I also deleted the Carthage directories (checkouts and build).
The Problem
When I build the shared/embedded Framework target, there are no issues.
But when I try to build either the App or App Extension targets, I get an error pointing to the shared frameworks Swift header (MyFramewor-Swift.h):
// ...
#import CoreGraphics;
#import CoreImage;
#import Foundation;
#import PhotosUI;
#import UIKit;
#import MyLibraryA; <-- Module 'MyLibraryA' Not Found
// ...
And the resulting:
Could not build Objective-C module 'MyFramework'
I know frameworks that are distributed as binaries cannot depend on Swift packages, but this embedded framework is compiled locally from source code and then embedded.
Perhaps there are some changes I can make to my setup on Xcode to get it to work?
I tried changing Enable Modules (C and Objective-C) to No in the Build Settings for the Framework target, to no avail.
You can currently set Install Objective-C Compatibility Header to No in Build Settings for modules that require a Swift Package dependency.
This's probably due to "Swift Packages" being "Swift", but still looks like a bug to me.
I'm using an approach described here for my app.
Currently, I was able to setup such structure for Android and iOS platforms. In general, I have the global core (.NET lib), platform specific core (platform specific Class Library), and some extension (platform specific Class Library).
The problem appears when I try to configure in same way structure for macOS platform. I was able to create platform specific class Library with components that should be reused in apps (for now this is just 1 class with the xib file). But, when I want to use this package in macOS target I got runtime error specific to macOS platform:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[NSNib _initWithNibNamed:bundle:options: ] could not load the nibName: MainView in bundle (null).'
That's strange, because I set up in same way structure for iOS app, and within the iOS target, it's work just great: all source files, xib files, resources are visible and could be freely used from the package.
Note:
I found few issues like described above and some solutions that could resolve this blocking point:
rename xib file - doesn't work
put xib file in rootDir - doesn't work
make sure that BuildAction for file is "InterfaceDefinition" - doesn't work (it always set to InterfaceDefinition)
recreate files - doesn't work
clean all, remove file, reboot, create new - doesn't work
put files in resource dir - doesn't work
force include into package - doesn't work
check that class in VB is correct - doesn't work (was always correct)
check Xcode folder with autogenerated files - doesn't work (in general all files was always there, few times autogenerated h and m files were missed -> I receive another error, but when manually create them -> I faced again with such error)
manually specify bundle for resource - doesn't work (this is strange because for iOS lib all resources are available within the null (main) bundle) - I try to explicitly specify bundle - doesn't work.
So, how to prepare class library within some source files, xib, other resources, so it can be freely accessed from any project that uses this package? Or maybe some steps described above was incorrect?
According to Chris Hamonds from Xamarin Forum here is the answer:
I believe this is a bug we've fixed but is not in the latest builds in our channel. I can reproduce with our Alpha build but installing a build from: https://jenkins.mono-project.com/view/Xamarin.MaciOS/job/xamarin-macios-builds-master/
I want to add library to my iOS application in Xcode 8.3.
I've read a tutorial and so, I created a target 'DEST', after add this item in Target Dependencies and libDEST.a in Link Binary With Libraries. Also, I moved all forked library in project. Now, I'm trying to use this library as in example from git, but code doesn't work. What am I doing wrong?
I am unable to compile the Glympse API for iOS due to 4 duplicate symbol errors in the framework. Like the example projects, I only import the GlympseLite.h header in my .pch file. Is anyone else having this issue?
One of the duplicate symbols is: __ZN7Glympse15ControlsFactory9showAboutERKNS_1OINS_12IGlympseLiteEEERKNS1_INS_8IGlympseEEE
How did you add GlympseKitLite into your project? Could you provide exact steps.
Which XCode version are you using?
Is there anything special about compiler/linker flags in your project?
Is it brand new or existing project?
Were you able to build sample projects provided with SDK?
I just confirmed that it compiles fine in a brand new projects. Here are the steps I followed:
Created new iOS project.
Dragged GlympseKitLite.embeddedframework (from SDK package) to Frameworks.
Added all required standard frameworks (CFNetwork, libz, CoreLocation, AddressBook, Security, EventKit, MapKit, MessageUI).
Added import entry to PCH file.
Called Glympse::LiteFactory::createGlympse(...);
In the mean time you can try the following. Set C Language Dialect, C++ Language Dialect and C++ Standard Library to Compiler Default. Let me know, if it helps.