How to install a development Framework in MacOS for commandline build - ios

I have an iOS application that needs to be integrated into CI/CD pipeline in CircleCI. Most of my dependencies have been added using CocoPods. There is one particular dependency of OpenCV2 that is manually compiled and used. On the local development machine, It is simple to use with drag & drop in Xcode. But, while running the build on a CI server. We don't have access to GUI and need to link dependency from the command line. I have not found much of the resources dealing with this issue.
I have tried few options from this link
https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/InstallingFrameworks.html
The framework that I am trying to use is compiled and zipped in an archive (opencv2.framework.zip and uploaded on Amazon S3. It is because the compiled framework is about 300 MB in size. So, I can't push it to the source repository. So, I download it using curl and unzip on CI machine. I have tried unzipping it to
/System/Library/Frameworks
/Library/Frameworks
~/Library/Frameworks
gym --scheme "project" --workspace "project.xcworkspace"
None of them really worked.I would like a way to register this framework in the system so that linker can find it while linking.
Suggest a way to extract framework into a location which linker can automatically look into.
Suggest a way where I can link framework manually from command line build

I have never used OpenCV but a quick pod search gives this result, so looks like they are already supporting cocoapods.....
pod search opencv
-> OpenCV2 (3.2.0)
OpenCV (Computer Vision) for iOS.
pod 'OpenCV2', '~> 3.2.0'
- Homepage: http://opencv.org
- Source: http://github.com/bcomeau/opencv/releases/download/3.2.0/opencv-3.2.0-ios-framework.zip
- Versions: 3.2.0 [master repo]
Second:
You can use Carthage https://github.com/Carthage/Carthage
You can use both Cocoapods and Carthage at the same time as long as they are not downloading the same dependencies.
Create a private repo, follow the carthage tutorial for uploading frameworks https://github.com/Carthage/Carthage#supporting-carthage-for-your-framework
then put opencv2 to your repo.
Then add your repo to your cartfile
Then before or after you install cocoapods, install carthage frameworks too.
It is a bit work but can solve your problem.
Third:
Looks like they also support Carthage
https://github.com/card-io/card.io-iOS-source/issues/32
Look at the last couple of comments..

Related

Xcode Cloud No such Module Cocoapods library

I have a project using a Cocoapods as dependency manager and I am trying to create an Xcode Cloud workflow for it, everything look simple to configure and I added the ci_post_clone.sh to run the pod install command before start building.
Based on the logs all the dependencies are downloaded but whenever it starts building I have the No such Module X error, I am not sure what i did wrong but it looks like xcode Cloud misses the step of Building targets in dependency order and it starts building the main project before building the dependencies
Did anyone face this problem and how did you fix it
Thank you for your help
I found a temporary solution by adding the pod folder to my repository, this is not what most people are willing to do but for now it is working
do you have a screenshot for how you set this up? Because the script file ci_post_clone.sh needs to exist in a repository named ci_scripts that is at the same level as your workspace / xcode project. You also need to be sure to mark that file as executable
then you can brew install cocoapods and run pod install on that script. cheers! just got this working this morning by following notes found here: https://developer.apple.com/documentation/xcode/making-dependencies-available-to-xcode-cloud

Swift Package Manager Dependency Mirroring

I have a project and:
the company I'm working with is self-hosting their git
the CI can communicate only with company's network
That being said, if I want to install any dependency, I have to ask their dev ops to mirror the target repository and only then I can use it.
The problem arises when I want to implement Crashlytics which has a lot of dependencies. When I import the Firebase, it's fetched from the mirrored repo correctly, but it's dependencies are still being fetched from the original URLs (which makes perfect sense).
The question is - How do I tell Swift Package Manager to swap each URL with mirrors? I have all the dependencies mirrored. I only need to tell SPM to use it.
I have found this proposal which was implemented in Swift 5, but when I go to root of my project and run:
$ swift package config set-mirror --package-url <original URL> --mirror-url <mirror URL>
I get this error:
error: root manifest not found
Any ideas how to do this correctly? Thank you
EDIT:
As Florian correctly pointed out, the proposal works from the package's repository, not my projects! So:
I do clone mirrored repo in my project's root
I run set of commands to set mirror url for each dependency:
swift package config set-mirror \
--original-url https://github.com/google/GoogleAppMeasurement.git \
--mirror-url <company's url>/mirrors/githubcom-google-GoogleAppMeasurement
I go back to projects root and run:
xcodebuild -resolvePackageDependencies -project MyProject.xcodeproj -scheme MyAppScheme
But it's still fetching from original urls, not the mirrors!
Having an Xcode project makes this task basically impossible (at the time of writing). Xcode's integration with SPM works fine for most things, but is not (yet?) at par with what SPM can do in pure SPM packages.
The problem is, that swift package config is always only local to the package and does not have any effect on projects / packages that depend on the package. And with Xcode currently having no counterpart to swift package config, it's not possible to do this at the moment.
What you could do, however, is to clone all your dependencies locally and then reference them as local packages from Xcode (simply dragging the package folder into the open Xcode project will do so). Xcode will be smart enough to take the dependencies from the local local checkout (or at least it was smart enough last time I tried this).
Let's hope for a future Xcode version with full SPM support!

libPhonenumber (from Google) on iOS in a Kotlin Native project

I've been struggling to solve a problem.
I'm building a cross platform app (iOS and Android) using Kotlin Multiplatform (KMP) where I need a library from Google (https://github.com/google/libphonenumber).
For Android, I can point to a Maven repo (https://repo1.maven.org/maven2/com/googlecode/libphonenumber/libphonenumber/8.12.6/).
For iOS, I can use a ObjC port of libPhonenumber via Cocoapods.(https://cocoapods.org/pods/libPhoneNumber-ios).
But, I can't use Kotlin's (cocoapod plugin) to properly recognize the Pod. The plugin appears to fail to build.
Here's the details of my setup:
Xcode v11.5
IntelliJ IDEA v2020.1.2
Cocoapods v1.9.1
Gradle 6.0.1
Sample repo (https://github.com/touchlab/kotlin-native)
NOTE: Within the repo, I'm using ./samples/cocoapods
modify ./samples/cocoapods/kotlin-library/build.gradle.kts
commented out AFNetworking, remove AFNetworking pod
pod("AFNetworking", "~> 3.2.0")
add a new pod
pod("libPhoneNumber-iOS")
modify ./samples/cocoapods/kotlin-library/gradle.properties
change this line:
kotlin.native.home=../../../dist
to this:
#kotlin.native.home=../../../dist
in Terminal in this folder: ./samples/cocoapods/kotlin-library/
./gradlew podspec
This creates a podspec file (libPhoneNumber-iOS.def) in ./samples/cocoapods/kotlin-library/build/cocoapods/defs/
cd from kotlin-library to ios-app folder
cd ../ios-app/
Pod install using the command:
pod install
You'll see something like:
Downloading dependencies
Installing kotlin_library (1.0)
Installing libPhoneNumber-iOS (0.9.15)
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 2 total pods installed.
When I build the sample 'ios-app' target: simulator in Xcode, I get the error:
fatal error: module 'libPhoneNumber' not found
I have tried other libPhoneNumber pods, such as:
libPhoneNumberSwift
LTPhoneNumberField
Both fail to build using Kotlin's cocoapods plugin, but work as a Pod without Kotlin's cocoapod plugin.
What am I missing?
This particular problem seems to be caused by the dash in the pod's name. There was already an issue reported on GitHub. For now, it's recommended to workaround this problem by re-naming the module. Changing your kotlin-library/build.gradle.kts like
pod("libPhoneNumber-iOS", moduleName = "libPhoneNumber_iOS")
should help. Please give it a try and tell here or on GH if it works.
I have obtained excellent results by adding the unchanged Javascript version of libphonenumber using JavaScriptCore in IOS. The only part of the library not available yet in Javascript is the geocoder.
I used the concept explained here: https://www.appcoda.com/javascriptcore-swift .
Performance is great and there is no porting involved. Always the latest version available.

Swift and Xcode: How to Build and Run a GitHub repository of iOS Application?

I'm interested on Running this GitHub repository of an iOS Application: https://github.com/septadev/SEPTA-iOS I opened the iSEPTA.xcodeproj file on XCode from the iSEPTA folder, but I'm getting these Buildtime Errors. For example: No such module 'ReSwift', and this is the window I get prompted when I select any of the yellow alerts, I'm not sure if I should perform these changes, yet.
Could it be some incomparability with my XCode and Swift versions?
Please, help!!
This project uses Carthage as a dependency management system for using external dependencies.
You should install Carthage to your computer and then run carthage update from the terminal in the root directory of the project. This will instal the dependencies and will allow you to run the project.
Take a look at Cartfile: it indicates this repo is using Carthage package manager. Follow their instructions to install dependent libraries
This repository requires Carthage ( https://github.com/Carthage/Carthage ) - this is a dependency manager. You can install it using Homebrew (https://brew.sh/)
brew install carthage
then you have to run carthageBuild.sh script (which runs carthage update):
./carthageBuild.sh
and then you have to open: Septa.xcworkspace file
This would be the correct solution if the project used Cocoapods. Since it uses Carthage, look to others answers unless you are referencing this answer to a similar issue.
You need to use Cocoapods to integrate the pods attached to the project. Often times projects will not come with them precompiled. Either you opened the blue project file with the *.xcodeproj extension instead of the white project file with the *.xcworkspace extension.... or you don't have the pods installed at all. In which case read below.
Instructions as follows:
cd to project directory
Install Cocoapods
sudo gem install cocoapods
Ensure the you have the given pods in your repo collection for install
pod repo update
Install the pods
pod install
Validate Project Settings
This is necessary until cocoapods v1.6 release (beta is out).
Open the white project file with the *.xcworkspace extension
After those steps are complete, the project should run normally.

Is it possible to distribute binary ios framework using carthage

Please bear with me because I spent considerable amount of time on this. I am also relatively a beginner with swift and iOS.
What I did
- built a framework using cocoa touch
- clean, build and it succeeds without a problem.
- made the scheme shared
- did carthage build --no-skip-current
- did carthage archive
- copied only the zip file to a fresh new directory and uploaded with release in git.
- In a different project tried to pull the framework using carthage
and I get the error Dependency "xxx-ios" has no shared framework schemes then I copied the scheme directly and pushed it in the git along the zip. nothing. Tried without the zip together with the scheme. nothing.
Then I created a fresh framework and I did carthage build --no-skip-current and I uploaded the whole thing in the project folder to git. That pulls properly with carthage. Then I removed some part of that folder so that the scheme inside .xcodeproj and the carthage build folder remain, then I get a different error. At this point it got me thinking if carthage does support binary framework distribution.
In my company, they want it so that I don't expose the code - so I am trying to distribute built binary of the framework.
I would really appreciate any help or guides of what different things I could try to single out the problem. Thanks.
Edit
someone had almost exactly the same issue as mine in their issues here but a couple of conversations later it is closed without a solution.
It sounds like you're using a github dependency in your Cartfile and attaching a binary of your framework to the GitHub Release. But you don't have any code in the repository, so Carthage is complaining because it can't actually build it.
That's as designed—Carthage doesn't support distributing binary-only frameworks that way. Binaries attached to GitHub Releases are only meant as a way to speed up builds.
However, Carthage does have a mechanism for binary-only dependencies: binary dependencies.

Resources