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

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)

Related

Firebase Crashlytics | Swift Package Manager (SPM) Run Script?

I want to add Crashlytics to my app using the Swift package manager.
Now, since the usual way to install Firebase is through CocoaPods, the tutorial on how to set up Crashlytics properly is also adjusted for CocoaPods.
In other words - the run script we should copy from the tutorial is not compatible with SPM, as you can see here:
${PODS_ROOT}/FirebaseCrashlytics/run
So how can I find the file location of Crashlytics using SPM to get the correct run script?
Thanks!
Turns out its inside the DerivedData folder:
~/Library/Developer/Xcode/DerivedData/YOURAPP-.../SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run
For your convenience, you can use a build variable to generalize the folder path:
${BUILD_DIR%Build/*}SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run
Finally, your run script should look something like that:
And another quite important thing if a non-default name for the firebase configuration file is used.
This flag is needed to denote it:
-gsp ${PROJECT_DIR}/PATH-TO-CONFIG/GoogleService-Info-Dev.plist
Thus final script should look like
${BUILD_DIR%Build/*}SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run -gsp ${PROJECT_DIR}/PATH-TO-CONFIG/GoogleService-Info-Dev.plist
Where PATH-TO-CONFIG is the path to the firebase configuration file in the project.
Thanks for the suggestions. I'm unable to make this work. I get a crash and the following error message:
/Users/[path-to-my-project]/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code
I don't understand why it tries to find the crashlytics script in my Xcode project folder and not in the derived data folder at runtime.
This worked for me, but I had to change Project Settings.
"${BUILD_DIR%Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run"
Add a package by selecting File → Add Packages… in Xcode’s menu bar.
Search for the Firebase Apple SDK using the repo's URL:
https://github.com/firebase/firebase-ios-sdk.git
Next, set the Dependency Rule to be Up to Next Major Version and specify 8.10.0 as the lower bound.
Then, select Add Package.
Choose the Firebase products that you want installed in your app.
If you've installed FirebaseAnalytics, add the -ObjC option to Other Linker Flags in the Build Settings tab.

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

QNX momentics linked source files not compiling

I am creating a QNX port for a Linux application. As a test, i copied all source code and header files into /src/ directrory and built the code. the binary was created, and I was able to execute on target VM. but now I have to create the momentics project inside the project folder, without altering or creating duplicate copies of existing source files.
I found that I can use linked resources. So I followed steps provided here and could add the file to project.
but when I compile the project, it is not taking the linked files.
As one can clearly see the process is directly going to linking stage.
but if I add a new cpp file without linking, only that particular file is getting compiled, not the linked file.
only the new main.cpp is getting compiled.
Can anyone help me to get this project built, only using linked resources?
I was able to use IDE for compiling my writing a Makefile and importing it to IDE.

How to build Framework from Static library in 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

how to build DLIB for iOS

I'm trying to build DLIB for an iOS project. Running the cmake results in a libdlib.a and a load of .o files.
When I add the library to an Xcode project I get warning that the library hasn't been built for arm64.
My question is two-part:
How can I build DLIB for iOS (I tried cmake **path_to_source** -DCMAKE_OSX_ARCHITECTURE="arm64" but it caused loads of errors e.g. unknown type name '__uint32_t'; did you mean '__uint128_t')?
What is the purpose of all the .o files that get built when you run cmake? Do I need to include them in an Xcode project?
I finally figured out how to do this:
Requirements
X11 (on a mac you can just open the X11 app and if X11 isn't installed it'll take you to the download).
Xcode
cmake (you can use home-brew for that)
Steps
In terminal make the lib-xx.xx/examples your root
Run:
mkdir build
cd build
cmake -G Xcode ..
cmake --build . --config Release
This will create a folder called dlib_build in which you can find an Xcode project that compiles the library. In the build settings of that Xcode project you can set the build architecture and SDK for any Xcode supported OS you like!
EDIT:
You have to include a lot of custom compiler flags and 3rd party libraries to get dlib to work in a project. Check out the examples.xcproject build settings.
To compliment RASS's answer, I am attaching screenshots showing how to change this to and from an iOS and OSX lib
After opening the project,
Select the project file from the project navigator
Select the dlib target all the way down the bottom
Select 'Build Settings'
Expand 'Base SDK' drop down
Select either iOS or macOS (OSX)
I hope this helps some people out! gl
Rob Sanders and mylogon already show how to build dlib for ios, here is how to use it:
add libdlib.a to project, and add path to library search paths
add all source to include directory(do not add to project), and add path to header search paths.
add accelerate framework, which contains blas symbols.
add preprocessor macros, from building settings, "custom compiler flag"/"other c flags". these macros make sure the header files match the lib.
-DDLIB_JPEG_SUPPORT
-DDLIB_NO_GUI_SUPPORT
-DNDEBUG
-DDLIB_USE_BLAS
-DDLIB_USE_LAPACK

Resources