Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bundle CocoaPods dependencies with Cordova Plugin?

I'm developing a Cordova plugin, and for the iOS platform, I'd like to incorporate a few existing (non-cordova-specific) Cocoapods. I haven't been able to find any info or examples on how to get this working, and I would've expected this to be a fairly common use-case.

Note that I am not trying to use Cordova as a Cocoapod, for which there is a decent amount of information out there, but rather use Cocoapods from within the iOS platform of a Cordova plugin that I'm developing.

Cordova's plugin.xml generally needs to list all project dependencies to bundle things correctly. Does anyone know of a Cordova or PhoneGap plugin which internally uses Cocoapods?

like image 802
fisch2 Avatar asked Aug 20 '14 21:08

fisch2


3 Answers

I just wasted several hours on this so I thought I would put this here for anyone who is interested. Cordova as of Cordova-CLI version 6.4.0/Cordova iOS version 4.3.0 supports direct integration with CocoaPods.

Detailed information is here: https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html

Simply add something like:

<platform name="ios">
    ...Other iOS platform specific declerations...
    <framework src="OpenSSL" type="podspec" spec="~> 1.0.0" />
</platform>

To the plugin.xml file for your plugin. Cordova automatically generates an .xcworkspace. Use that instead of the xcodeproj file and you are good to go.

like image 84
Jarra McIntyre Avatar answered Oct 20 '22 12:10

Jarra McIntyre


I couldn't find a good solution to this problem so I created a plugin for it, https://github.com/blakgeek/cordova-plugin-cocoapod-support. It adds support for defining Cocoapod dependencies in the plugin.xml. It should be included as a dependency of another plugin and then that plugin can add entries in the ios platform section of the plugin.xml. It supports all of the pod dependency specifications like git repo, configurations, subspecs, etc. Hope this helps someone out.

like image 38
blakgeek Avatar answered Oct 20 '22 13:10

blakgeek


I couldn't find much info about this either, so I wrote a Cocoapods plugin to help: https://github.com/xdissent/cocoapods-cordova It manages your plugin.xml automatically and builds a universal static library which links in only non-cordova dependencies. Currently a WIP, but I'm using it successfully on a few plugins.

like image 5
xdissent Avatar answered Oct 20 '22 12:10

xdissent