Hotfix for Cordova Compile Issue with cordova-plugin-cocoapods-support

Erisu
The Web Tub
Published in
3 min readFeb 8, 2018

cordova-plugin-cocoapods-support is a Cordova/PhoneGap plugin which allows you to define plugin or project CocoaPods dependencies for iOS within the XML file. However, when using with cordova-ios@4.5.2 or greater, Cordova compile command will fail. This article will point out the changes that caused this issue and potential solutions to get your iOS builds passing again.

Cause

When Cordova released cordova-ios@4.5.2, the new variable, location, was introduced and contained the necessary information for the platform builder to fetch the bundle identifier. One of the attributes of the new variable was the path to the pbxproj file. This file is located in the xcodeproj directory.

After Cordova prepares the project, the cordova-plugin-cocoapods-support plugin’s after_prepare hook script is executed and made modifications to the platform build script. One of the modifications performed is a very loose find and replace all instances of xcodeproj with xcworkspace. Due to an unintentional change, when the builder attempted to parse the pbxproj file from the xcworkspace directory and failed because it could not find the file.

The issue can only be seen with the cordova compile command and not with the cordova build command. This because the build command performs all build steps and maintains the bundle identifier information from cache and does not need to parse the pbxproj file.

Solution 1: Remove Plugin Dependency

Not much is needed to be said for this solution.

If you are the plugin developer and if it is possible, removing the plugin dependency and using Cordova’s native implementation for CocoaPods support would be ideal.

Here is a example on how to load the OpenSSL pod file with Cordova’s implementation.

<platform name="ios">
<framework src="OpenSSL" type="podspec" spec="1.0.210" />
</platform>

You can find more detailed information here.

Solution 2: Create Hotfix for Plugin

If you are not the plugin developer and can not remove the plugin dependency, it is possible to create your own hook script to revert the breaking change.

First, we will need to create the hook script and lastly add it to the project’s config.xml so it will be used.

Creating the Script

Let’s create a new file called beforeCompileCocoapodsHotfix.js and add it to the hooks folder. The path should look something like this <project_dir>/hooks/beforeCompileCocoapodsHotfix.js.

Next, we will add the script content.

This script will explicitly search only for the breaking change and revert. This will not revert all of the plugin’s changes.

Finally, we will add to the project’s config.xml a reference to our new hook script to execute before compile. Since this is an iOS dependency, we will add it to the iOS platform declaration.

<platform name="ios">
<hook type="before_compile" src="hooks/beforeCompileCocoapodsHotfix.js" />
...
</platform>

Now you can continue to compile iOS builds!

This hotfix can be removed as soon as the plugin dependency is no longer used or when the plugin has been updated with a more permanent solution.

Happy coding.

--

--