How to build Framework from Static library in iOS? - ios

I have .a files of all Architecture i.e. arm64, armv7,armv7s.
Now i want to build a Framework from all static library how to do that? now i have Universal .a file and headers how to convert into framework?

A static framework on iOS is basically a folder structure.
You could use command line tools (basically a script) to "create" the folder structure suitable for a framework after xCode has finished compiling the Library.
You would need to add "Run Script Build Phase" and add all the necessary commands.
Have a look at this tutorial:
https://www.raywenderlich.com/65964/create-a-framework-for-ios

Related

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

Module 'Swift' was created for incompatible target x86_64-apple-ios13.0

I'm creating an iOS framework and I want to copy some Xcode templates from my framework directory (that are not included in my .xcproject, but are in the folder that contains the project), when my framework is installed trought Cocoapods. In other words, when a developer installs my framework with Cocoapods or manually, I want to copy the templates into his Xcode Template Files folder.
I'm trying to execute a swift script file from the build phase of Xcode like this:
swift "${SRCROOT}/Folder/Folder/installer.swift"
But I get this error when I try to build it:
/<unknown>:1:1: module 'Swift' was created for incompatible target x86_64-apple-ios13.0: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64.swiftmodule
If I execute swift installer.swift from the terminal, the script works. So, I think there is a problem with my Xcode.
My installer.swift file copies the template files to the Xcode Template Files folder.
I don't know if this way is the correct one, but I didn't find any other solution so far.
When I tried something similar I had to tell swift to compile for macOS by adding the following "shebang" comment as the first line of the swift script:
#!/usr/bin/env xcrun --sdk macosx swift

How to add a library or framework to XCode project at the runtime?

I want to add a static library mylib.a to Xcode at the runtime via buildscript. It needs to copy to project directory if needed as well.
I'll need something like following line of command to add just before the xcodebuild command in the buildscript. If anyone have done this before please share some example.
frameworkGroup = project.get_or_create_group('Frameworks')
project.add_file(/Users/###/Desktop/mylib.a,
parent=frameworkGroup,
tree='SDKROOT',
weak=false)

Can't link fat iOS static library

I recently downloaded a fat, iOS static library for the popular C library boost. All my attempts in coaxing Xcode to link it have failed.
Things I have tried:
Adding it to Link Binary With Libraries.
Changing file type to Mach-O Object Code using File Inspector.
Renaming the file to libboost.a and adding -lboost to Other Linker Flags.
I am using Xcode 6.3 with the latest command line tools.
How To Link to an Xcode Project?
In Xcode Build Settings for your project: LIBRARY_SEARCH_PATHS
ofxiOSBoost/libs/boost/lib/ios
(Set this to the directory where the static library is)
In Target under Build Phases for your project
Add to 'Link Binary With Libraries' the boost.a found in the ofxiOSBoost/libs/boost/lib/ios directory.
Renaming to libboost.a may be breaking it. The ofxiOSBoost renames this file as to not conflict with internal OSX libs in the linking process if in path / sys, so it links correctly with the iOS Binary.
If you are still having this problem, please open an issue here:
https://github.com/danoli3/ofxiOSBoost/issues

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.

Resources