Xcode build variables for iOS or Mac for carthage support - ios

Overview
I am working on developing multiple cascading set of Dynamic Frameworks that are integrated by Carthage. I'm trying to adapt the principals in this blog post and the WWDC video Sharing code between iOS and OS X
My Situation:
I have 3 Dynamic frameworks who included each other in a cascading format:
Dynamic Framework: DataManager includes Dynamic Framework: GDL90 includes DynamicFramework: EGL96.
Work thus far...
The jist of what I'm doing is taking a single target and having it configured to build frameworks for both iOS and Mac explained here
Base SDK: OSX
Supported Platforms: machos iphoneos iphonesimucator
Valid Architectures: arm64 armv7 armv7s i386 x86_64
And then under your test targets you change the search paths:
Runpath Search Paths: $(inherited) #executable_path/Frameworks #loader_path/Frameworks #executable_path/../Frameworks #loader_path/../Frameworks
Framework Search Paths: $(SDKROOT) $(inherited)
Where the problem starts
I configured the EGM96 project as such to build multiple build for multiple targets. This works nicely and compiles fine. Where the trouble starts is once we get carthage involved.
In my GDL90 project I included EGM96 from carthage
After I run carthage update I end up with the following files:
./Carthage/Build/Mac/EGM96.framework
./Carthage/Build/iOS/EGM96.framework
I've also configured the GDL90 project to do a multi-platform build, but thats where the error starts. I'm unable to dynamically configure the build process (thus far) to pull in the correct framework version based on the correct target (i.e. OS X build pulls from /Carthage/Build/Mac/EGM96.framework).
I've spent some time looking through the build variables for Xcode and I have yet to find a working solution.
The caveat is as these were initially iOS projects i had linked in the iOS framework into Xcode and thus I end up with the entirely appropriate error:
ld: building for OSX, but linking in object file built for iOS, file '/Users/jstein/devel/DigitalCopilot/GDL90/Carthage/Build/iOS/EGM96.framework/EGM96' for architecture x86_64
Is there an easy solution to some hidden build variables I'm missing that would allow at compile time Xcode to pull the framework from the appropriate carthage build path?

Related

Pods copying headers from x86_64 and arm64 folders in frameworks and causes multiple commands produce error

I am trying to add a custom framework to my iOS app. The framework includes code for both x86_64 architecture and arm64 architecture.
When I try to build my project on my MacOS for simulator I receive multiple errors of the same form:
As I see the problem is that its trying to copy files from both folders, the ios_x86_64_simulator and ios_arm64 and thus produces same headers which causes it to fail.
I have tried doing clean install of my whole Pods, changing the order of build phases, excluding architectures "arm64" for debug and release builds both for my project as well as all targets however I keep getting the same error.

Xcode project giving pod file error for FIRAnalyticsConnector.framework . How to solve it?

I'm working on a book project and the project is connected by API . I'm working on the book app which has different libraries imported from the various places.
Recently, i cloned the project from bitbucket in Xcode and tried to run it. The result i got i error as follows:
enter image description here
It shows :
ld: in /Users/ishinfoservices/Documents/vadltaldhambooks/Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector(FIRAnalyticsConnector_a8eeba373b74508311b8b22b8d3202a6.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/ishinfoservices/Documents/vadltaldhambooks/Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Help needed to fix the error, as the project has lots of mixes of old libraries along with .h and .m files, the swift files with wireframes
According to the image I saw that you are trying run the app on the iOS simulator, then you could try to add the arm64 to the Excluded Architectures on the Build Settings section of your project or target, it would be like:
Take in mind that if you use Cocoa Pods is possible that also you should add the arm64 to the Exclude Architectures into the Pods project
After the above, clean, build and run the project on the iOS simulator, is possible that on your physical device you must remove the arm64 from the Exclude Architectures, it could depend on what you use in your project.
On the other hand, you can try the following: Select the project -> Select the target -> Go to the Build Phases -> Expand the Link Binary with libraries and add all pod libraries (remove if they exist in embedded binaries or Remove the old FrameWorks), after that, clean and build the project

How to use Realm (installed with Carthage) with a framework in a Swift app?

I'm working on an iOS App and a Watchkit App.
I read a few things regarding best practices and I decided to create a custom framework, as NathashaTheRobot advise here:
https://realm.io/news/architecting-app-apple-watch-natashatherobot/
So I'm trying to use Realm in my framework.
I followed the installation instructions for Carthage:
Add github "realm/realm-cocoa" to your Cartfile.
Run carthage update.
Drag RealmSwift.framework and Realm.framework from the
Carthage/Build/iOS/ directory to the “Linked Frameworks and
Libraries” section of your Xcode project’s “General” settings.
On your application targets’ “Build Phases” settings tab, click the
“+” icon and choose “New Run Script Phase”. Create a Run Script with
the following contents:
/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input
Files”, e.g.:
$(SRCROOT)/Carthage/Build/iOS/Realm.framework
$(SRCROOT)/Carthage/Build/iOS/RealmSwift.framework
Then I added my framework to the Target Membership of both Realm.framework and RealmSwift.framework.
But when I try to build the project, I get this error:
ld: framework not found Realm for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Then I gave a shot to lipo:
$ lipo -info Carthage/Build/iOS/Realm.framework/Realm
Architectures in the fat file: Carthage/Build/iOS/Realm.framework/Realm are: i386 x86_64 armv7 arm64
Do you have any ideas of what I might be doing wrong here? Thank you.
EDIT:
OK so I found the problem and it was totally unrelated to Realm...
It looks like I deleted the Headers and Resources sections of my framework Build Phases somehow (which were and are still empty). I just put them back and everything compiles/works like it should.
Don't be tempted to delete those two
Is it possible that it's your test target that can't find the frameworks? You'll have to add the parent location of the frameworks to the "Frameworks Search Path" section of your unit tests (likely $(SRCROOT)/Carthage/Build/iOS).
Here's a sample project of a Swift framework bundling RealmSwift as a dependency which you might find useful to compare your build settings against: https://static.realm.io/debug/ParentFramework.tgz

In XCode 6 is there a simple way to build an iOS universal application and 32/64 static library subprojects?

The common wisdom seems to be that to build a subproject as a static library so that it will link and run on all iOS architectures it is necessary to build an Aggregate target for the library, by running a build script which includes a lipo call to package the various binaries.
Is this still necessary in XCode 6?
Setting "Build Active Architecture Only" to NO sounds like it should do this without the need for a separate lipo script or an explicit Aggregate target.

Cannot Archive when a library is included in my own iOS custom framework

I created my own iOS framework by following this tutorial, https://code.google.com/p/ios-static-framework/, which uses a static library template and aggregate target with a custom run script to create a framework.
At first it works fine. After including another library in the framework project creates the error when archive or build for device. I think the problem is with some wrong settings for that library. But I just don't know what to try. I have tried setting some sensible Other Linker Flags from https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/ld.1.html , but no luck. Can anyone help please ;(
What steps will reproduce the problem?
Follow the tutorial, but change the Aggregate script architecture from armv6 armv7 to armv7 armv7s. Here is the part of the aggregate target script I changed. Everything else is the same.
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
then
SF_OTHER_PLATFORM=iphonesimulator
SF_ARCHS=i386
else
SF_OTHER_PLATFORM=iphoneos
SF_ARCHS="armv7 armv7s"
fi
Add an external library to the project, here I use libBlocksKit.a.
Build the framework, success.
In another child project. Include my built framework.
Add -ObjC in the app Target > Build Settings > Other Linker Flags
Archive and get error. Building for device (iPhone5) gives error too. But building for simulator seems to work.
What is the error?
This error, basically "ld: warning: directory not found for option ... ld: lto: could not merge in ... symbol multiply defined!".
ld: warning: directory not found for option '-L/Users/hlung/Dropbox/- Notes/stackoverflow/RealFrameworkApp/RealFrameworkApp/External/BlocksKit'
ld: lto: could not merge in /Users/hlung/Library/Developer/Xcode/DerivedData/RealFrameworkTest-evagqzwzyyolhjenkkjbvzibxppf/Build/Products/Debug-iphonesimulator/RealFrameworkTest.framework/RealFrameworkTest(NSObject+BlockObservation.o) because 'Linking globals named 'OBJC_CLASS_$_BKObserver': symbol multiply defined!', using libLTO version 'LLVM version 3.2svn, from Apple Clang 4.2 (build 425.0.28)' for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
If I archive my child project with only one architecture (like armv7), it works. It shows this error with armv7 armv7s architectures ( $(ARCHS_STANDARD_32_BIT) ).
What version of the product are you using? On what operating system?
OS X 10.8.5, XCode 4.6.3
== Update 1 ==
Posted an issue at the tutorial's code.google.com page Update: 2 weeks no answer.
I found a set of useful suggestions from this answer. Update: Doesn't work
I have created a project so you can run and see for yourself here
Linking against a static library from within a framework can create some interesting challenges... It sounds like you may be linking to BlocksKit from both your framework and your application projects.
You should link in only one of those places. Try removing libBlocksKit.a from the Link Libraries build phase of your framework, but leave it in the other project.
You can do like this:
Click on your project (targets)
Click on Build Settings
Under Library Search Paths, delete the paths
I hope it can help you.

Resources