I would like to make use of couple of cocoapods in my xamarin.ios project.
But I couldn't find those cocoapods in Nuget which is package manager for Xamarin.
I heard we can compile a xcode project into a static library ... that is .a file and use it in xamarin.
But I am getting confused on how to convert the pods into a static library or something so that I can use those pods in my xamarin.
You cannot take the Pod directly and create a static library but you can although create a static library from the Pod project which already contains your pod. But to be honest the best solution will be getting the source code of the project and create the static library from there. Most of the Pods out there are open source so grabbing the source code from github should not be a problem.
Once you have the source code follow this example to show you how to create static libraries from there.
Once you have created the static library you just need to follow this tutorial to create a Binding library that can be used in Xamarin.
Unfortunately AFAK there's not support yet for Swift libraries to create binding libraries so this will only work with objective-c code.
Related
Recently I started creating my pod in Swift. I used pod lib create command and declined offer to use Nimble/Quick as testing library because I hoped to use standard XCTest. However, when I try to run tests, build just fails with message Swift is not supported for static libraries.
I tried to reopen Xcode and clean project, not working.
What should I do in this situation?
Swift don't supported static libraries. If you create lib used objc so you have 2 ways (create static lib and write script for convert to framework) but if you write used swift only one.
So you need create pod. Just create framework in xcode and add files for configurate your project to pod. It't easy, for example you can watch this, I create pod after create project
For swift you need to have Cocoa Touch Framework
I'm trying to create a Cocoa Touch Framework. To create a framework is not a problem, I used this tutorial and it is good.
I need to use third party libraries inside: like openssl, XLForm, AFNetworking. I know that it is not correct to include them in my framework, I need to create a dependencies, but I can't find how to do this.
Moreover is it possible to use pods in my framework and just make dependencies to these libs. So user which will include my framework to his project will need just install these pods.
It seems that I found solution.
Thanks to #Droppy and thanks to this question.
What I did: I just installed pods to my Framework project but used this use_frameworks! key.
Then I dragged my Framework to my Project and installed pods there, also with same key, otherwise (when pod wasn't installed in my Project) I was getting error like:
dyld: Library not loaded: #rpath/XLForm.framework/XLForm...
I used XLForm inside my Framework.
I successfully compiled FFmpeg with iOS 8.2 SDK thanks to https://github.com/kewlbear/FFmpeg-iOS-build-script and last version of gas-preprocessor (https://github.com/libav/gas-preprocessor).
However, I would like to package FFmpeg libraries as a iOS 8 dynamic framework due to legal constraints. I found resources to create iOS 8 dynamic framework however I cannot find any solution for FFmpeg.
Can anyone help me to package these librairies ?
Thanks
David
As far as I know, FFmpeg-iOS repo in Github can build static libraries from FFmpeg source code. But I search throughout the network, no one show me how to compile with dynamic libraries.
But I wonder if we can create a new cocoa touch framework project, and drag all header files and libraries into this project, and do some header declaration into the base .h file, and drag the framework project into an existing iOS project as a sub project, add it as an embedded framework, and compile the whole project.
The reason why I use sub project, instead of giving out a final .framework file, is that static symbols can only be linked only if them are been using somewhere.
I will demonstrate this later. If anyone has better ideas, it will be grateful.
Edit:
After several days's researching, I found it is not easy to build dynamic framework easily, but I find a workaround to achieve the target:
Build a static libraries of FFmpeg
Create a new iOS dynamic framework project
Create a class that encapsulate the basic usage of the FFmpeg, such as encoding/decoding video
Copy static libraries into this dynamic framework project
Make sure your project build without error
Add this project as a subproject to your existing project
Add dependency in embedded binaries and Linked Frameworks and Libraries
Build and run main project
Open source this project as LGPL2.1+, the same as FFmpeg itself.
Through it is not perfect, but at least it works, and it complies with FFmpeg's LGPL license.
I want to know if you can define dependencies on an static lib in a podspec depending on the type of the Target that the Pods project is going to be linked to.
I need to be able to NOT add a dependency to an static lib if the target project is itself an static lib.
Why I need this?
I've built a podspec for cocos2d-iphone v3 and using it in a personal pet project. Works perfectly when you use it as a dependency for an executable. Unfortunately it doesn't works well the way I've organiced my project:
It's a multiplatform project app consisting in two xcode projects for the ios and osx executables. Both link to an static library with shared code (another xcode project). I've made the cocos2d a dependency for that last static library.
Unfortunately, cocos2d has a dependency over lib z, which is also static. As you can't link two static libraries the link phase fails. The error message is as follows:
file: -lz is not an object file (not allowed in a library)
It's easy to remove that dependency but I would prefer the process to be more easier for the end user.
My approach to solve this problem would be add a conditional in the podspec so the lib z only is added if the project is not an static library. I guess it can be done with pre_install hooks, but they are discouraged by the cocoapods team.
Is there any other way to accomplish this?
I followed the following tutorial to create a static library:
https://github.com/jverkoey/iOS-Framework/#developing-the-framework-as-a-dependent-project
It all works until I try to incorporate the RestKit into my static library. There I am completely lost. Am I supposed to include the RestKit library into my static library or only in the App which will use my library?
If I don't include RestKit in my library, I can't compile it as it depends on another library (RestKit) so what would be workaround for this?
I tried to look everywhere but haven't found a good step by step tutorial to create a static library which itself depends on other static libraries.
What I did to get this working was to add RestKit to my static library using their git-submodule instructions here. Then I performed the exact same steps on the projects that were going to use my static library EXCEPT:
I did not add RestKit to the "Target Dependency" section of the Build Phases
I did not add the libRestKit.a to the "Link Binary With Libraries" section. All other references still needed to be added.
I was then able to reference RestKit in both my static library and my iOS project.
COCOAPODS MEGA HACK
I was able to get this working with cocoa pods, but it will only work if this is your only cocoapods project. I started with all of my projects in a single workspace. Then I had my single podfile install RestKit to my static library and all projects that were going to reference my static library. Then for each project that I wanted to reference my static library I removed the pod reference under "Linked Frameworks and Libraries". Everything was then working as expected.
As you can expect, this would probably break all other pod references (unless you managed them all through that one static library), but it does seem to work.
Shorty after asking the question I finally managed to get it working here the steps if someone has a similar problem:
Create an actual app as explained int this section. After adding your library add all the other libraries you use to the application. (In my case it was the RestKit framework, add it as a submodule and not with cocoapods as with cocoa pods it didn't manage to get it to work properly).
After adding all your libraries, follow the third party libraries instruction for modification for the application and make the same modification for your static library.
e.g. for Restkit I had to add
-ObjC -all_load
to the Other Linker Flags and add
"$(BUILT_PRODUCTS_DIR)/../../Headers"
to the Header Search Path inside my static library.
I still couldn't build as the <RestKit/Restkit.h> wasn't found, so I needed to change the build order of the frameworks to assure that Restkit was built before my library.
This is done inside the edit Scheme of the build menu. Make sure that all the dependent libraries are on top of your library (if your static library or the dependent libraries aren't already in there add them with the '+')
Afterward everything worked for me. I am not sure if this is the best method to do it or if it would be better to include the third party library inside your statistic library.
Update I still run into problems when trying to build my library, if someone has a better solution or can shed some light on how to create a static framework which depends on other frameworks I would appreciate it.