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

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.

Related

Lipo Error while creating Universal frameworks in xcode 12

I am facing problem while making universal frameworks in xcode 12. following is the command that i ran:-
lipo -create build/simulator/FrameworkName.framework/FrameworkName build/devices/FrameworkName.framework/FrameworkName -output build/universal/FrameworkName.framework/FrameworkName
And following is the error that i am facing:-
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: build/simulator/FrameworkName.framework/FrameworkName and build/devices/FrameworkName.framework/FrameworkName have the same architectures (arm64) and can't be in the same fat output file
when i googled this error i found solution to set my 'Architectures', in 'Build Settings', to Standard, however it was already set to standard find the screenshot attached
Note: I was following this tutorial:- https://medium.com/#anuragajwani/how-to-build-universal-ios-frameworks-74b6b07bf31d
The error tells you that both your frameworks in build/simulator and build/device folders have been built for the same architecture (arm64, which is a device architecture). You can verify this by yourself, by looking inside the .framework file: FrameworkName.framework/Modules/FrameworkName.swiftmodule.
It is possible, that one of the folders (or both) contain more than one architecture like this:
Personally, I like to build my 'fat' frameworks outside the Xcode.app folders (just to make sure I have complete control over what is where). First, run your framework for simulator (select any simulator as build target). After the process has completed, go to Products folder in Xcode Navigator, click Show in Finder on FrameworkName.framework file. Copy the shown .framework somewhere more convenient (e.g. Desktop/simulator folder)
Then, build the framework again, only this time for device (select Any iOS device as build target). Copy second .framework somewhere like Desktop/iphone folder.
Create empty Desktop/universal folder for output framework. Copy .framework file there from Desktop/iphone folder and remove Desktop/universal/FrameworkName.framework/Framework executable file. This file will later be replaced by lipo.
Next, do the lipo magic:
lipo -create ~/Desktop/iphone/FrameworkName.framework/FrameworkName ~/Desktop/simulator/FrameworkName.framework/FrameworkName -output ~/Desktop/universal/FrameworkName.framework/FrameworkName
Last step, go to Desktop/simulator/FrameworkName.framework/Modules/FrameworkName.swiftmodule copy all files that start with x86_64 prefix, and paste them to Desktop/universal/FrameworkName.framework/Modules/FrameworkName.swiftmodule. Now your Desktop/universal/FrameworkName.framework contains both device and simulator architectures. Congrats, you've got your 'fat' library!
Disclaimer: Yes, I realise there are easier ways to do this with various scripts and terminal commands, but all of them do pretty much the same thing. Once you try to do this manually step by step, it will help you understand what goes where, and what are architectures and how they can be combined.
Disclaimer 2: Starting from Xcode 12, Apple insists you build .xcframeworks instead of 'fat' libraries. See here

How to avoid build and lipo of Universal Framework everytime project is built?

I have a project that uses a custom framework I've built. This framework provides a clean API based on Objective-c which hides c++ code.
The framework has a universal builder target that uses a Run Script to run xcodebuild and then lipo the binaries for the framework to include.
I realize that the project always wastes a lot of time calling the universal builder target which builds and lipos the binaries. My question is how can I avoid xcodebuild and re-lipo if the source files if they haven't changed?
Well, after much research and getting down and dirty I realized two things.
I did not need a universal build script target. The reason being that the framework project was included on the app I was working with. So xCode automatically is building the correct architecture for the framework. This speeds up the build process since now framework building will only happen when something changes.
So if you are still in need of using a universal build script use the Input Files and Output Files to define your script variables. This then allows xCode to check if the files need to be built and thus executing the script. More on that here: https://patrickbalestra.com/blog/2018/08/27/improving-your-build-time-in-xcode-10.html

Xcode build variables for iOS or Mac for carthage support

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?

Unity 4.6.5 project won't run on iOS simulator

Unity 4.6.5 project won't run on iOS simulator and I'm getting runtime error:
dyld: Symbol not found: _OBJC_CLASS_$_CBAnalytics
Referenced from: /Users/diverseconnection/Library/Developer/CoreSimulator/Devices/983BAC55-2713-423B-B5F3-C135ECCC2768/data/Containers/Bundle/Application/D4CAC0C7-E3D6-48F5-B264-E6EB715F9709/trouble.app/trouble
Expected in: flat namespace
in /Users/diverseconnection/Library/Developer/CoreSimulator/Devices/983BAC55-2713-423B-B5F3-C135ECCC2768/data/Containers/Bundle/Application/D4CAC0C7-E3D6-48F5-B264-E6EB715F9709/trouble.app/trouble
(lldb)
Any ideas how to fix it?
Well this error is usually rather broad as there can be number of causes. You can try these fixes
Add the correct libraries in the Link Binary With Libraries section of the Build Phases.
If you want to add a library outside of the default search path you can include the path in the Library Search Paths value in the Build Settings and add -l{library_name_without_lib_and_suffix} (eg. for libz.a use -lz) to the Other Linker Flags section of Build Settings.
You copy files into your project but forgot to check the target to add the files to. To resolve:
Open the Build Phases for the correct target, expand Compile Sources and add the missing .m files.
You include a static library that is built for another architecture like i386, the simulator on your host machine. To resolve:
If you have multiple library files from your libraries vendor to include in the project you need to include the one for the simulator (i386) and the one for the device (armv7 for example).
Optionally, you could create a fat static library that contains both architectures.
Also try this
Remove Build Active Architecture Only (build setting parameter key is 'ONLY_ACTIVE_ARCH') from all of your static libraries' project build settings or overwrite it with 'NO'

Building and debugging static library in Xcode using external build system

I'm trying to embed a set of static libraries that are made by an external build system into a project. I can get the external build system to build the libraries just fine in Xcode and I can use them in another project.
However, the project I am compiling (ffmpeg) produces several static libraries and I'm not clear at all how I should set this up in Xcode such that it can be referenced by another project and when I change the ffmpeg source it is rebuilt and can be debugged. Any pointers?

Resources