How to bundle CocoaPods dependencies with Cordova

2019-03-17 08:23发布

问题:

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?

回答1:

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.



回答2:

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.



回答3:

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.



回答4:

I am meeting a similiar situtation.

Here are two workarounds.

  1. Integrate Cordova into the plugin development environment, i.e, turn a pure Xcode project into a Cordova based project. If we want to use cordova plugins for iOS, they are available via Cocoapods too.

  2. Introduce Cocoapods to the Xcode project generated by Cordova. This way, we need to put the generated code into source control and be careful when we add other plugins since files we modified can be modified by cordova.

I don't know yet which one is a better choice.

The following pods info are helpful for workaround #1.

pod search cordova

-> Cordova (4.0.1) Cordova iOS pod 'Cordova', '~> 4.0.1' - Homepage: https://github.com/apache/cordova-ios - Source: https://github.com/apache/cordova-ios.git - Versions: 4.0.1, 3.9.1, 3.8.0, 3.7.0, 3.6.0, 3.5.0, 3.4.1, 3.4.0, 3.3.0, 3.2.0, 3.1.0, 3.0.0, 2.9.0, 2.8.0, 2.7.0, 2.6.0, 2.5.0, 2.4.0, 2.3.0, 2.2.0, 2.1.0, 2.0.0, 1.9.0, 1.8.1, 1.8.0, 1.7.0, 1.6.1, 1.6.0, 1.5.0, 1.4.1, 1.4.0, 1.3.0, 1.2.0, 1.1.0, 1.0.0 [master repo]

-> Cordova-Lib (3.9.1) 镜像自github,部署在git.oschina.net解决国内访问的连接速度。Apache Cordova is a platform for building native mobile applications using HTML, CSS and JavaScript. pod 'Cordova-Lib', '~> 3.9.1' - Homepage: https://git.oschina.net/liubiqu/cordova-ios - Source: https://git.oschina.net/liubiqu/cordova-ios.git - Versions: 3.9.1, 3.9.0, 3.8.0 [master repo]