Including ObjectiveGit library in iOS app
-
31-05-2021 - |
Question
When opening the ObjectieGitFramework.xcodeproj file I can now build the iOS scheme successfully. A whole lot of experimenting was required though. Lets start from the beginning – how I did that.
What I did:
First I cloned a fork of ObjectiveGit.
git clone git@github.com:Eonil/objective-git.git --recurse-submodules
cd objective-git
cd ./Scripts/libgit2-make-ios/; sh ./download-make-clean-deploy.sh "./../../libgit2.a"; cd ../..
Src: https://github.com/libgit2/objective-git/pull/54
Opening the project and building now results in one error and one warning. I let Xcode automatically update the project settings to solve the warning.
Now I go to the libgit2
directory and build using cmake:
$ mkdir build && cd build
$ cmake ..
$ cmake --build .
Src: https://github.com/libgit2/libgit2
This result, among other things, in the libgit2.0.15.0.dylib
file being created.
I drag it into the Xcode and add it to ObjectiveGit and the iOS target. Now I go to the build phases tab for ObjectiveGit-iOS and make it look like this:
The problem
At this moment I could build the project, and I could create classes within it successfully using the ObjectiveGit
. However when I dragged the project inside another project, added ObjectiveGit-iOS
as a target dependence and added libObjectiveGit-iOS.a
in link binary with libraries
I couldn't import ObjectiveGit/ObjectiveGit.h
plus I was getting some other weird errors (see images below). I know very little about libraries in xcode so I don't know at all why this is not working.
Now, this is an error I got once but not anymore. I don't know what I was doing to cause it.
Update
$(SRCROOT)/frameworks/ObjectiveGit/Classes
$(SRCROOT)/frameworks/ObjectiveGit/libgit2/include
$(SRCROOT)/frameworks/ObjectiveGit/Classes/Categories
When adding this to header search path
something strange happens. It result in no files not being found, but 70 other Mach-o errors instead.
```
Solution
Dynamic Libraries are not supported by iOS. You have to use static libraries.
To be clear: Of course iOS supports dynamic libraries, but only these which are distributed by apple.