npm uninstall -g ionic cordova
npm install -g cordova@{selectedCordovaVersion} ionic@{selectedIonicVersion}
Common Cordova / Ionic build errors
We’ve put together a quick guide to help teams troubleshoot the most common causes for Cordova / Ionic build failures.
First, we’ll describe the steps buddybuild performs when setting up a Cordova / Ionic build environment. Then, we’ll walk through the common causes of build failures, and how to resolve them.
Cordova / Ionic setup in buddybuild
First, we analyze your repository for any directories that contain the following files/folders:
-
config.xml
-
www
For ionic, there’s an additional requirement:
-
package.json
If we find a directory containing the aforementioned paths, we will perform the following steps:
Install Cordova and Ionic dependencies
Install node dependencies
In addition to installing node dependencies, you can be execute postInstall tasks that perform additional setup required for buddybuild to build your application.
npm install
Install Bower dependency
We’ll only install Bower if you’ve there’s a bower.json
file checked
into your project.
if [ -e bower.json ]; then bower install; fi
Rebuild node-sass dependency
If the node version or platform has changes, we’ll rebuild node-sass
.
npm rebuild node-sass
Add Cordova / Ionic platforms if necessary
If you haven’t checked in your platforms folder, buddybuild will perform a "platform add" on your behalf.
if [ ! -d "./platforms/{platform}" ]; then {framework} platform add {platform}; fi
Restore platforms/plugins/resources (Ionic projects only)
We’ll restore your plugins/resources to ensure they’re correctly setup in your repository so buddybuild can build your application.
if [ {framework} eq 'ionic' ]; then ionic state restore --plugins && ionic resources; fi
Prepare platform
This is the final step to ensure buddybuild can build your application.
{framework} build {platform}
Pseudocode Script
Here’s a summary of the steps buddybuild performs when preparing to build your Cordova / Ionic app.
# variables
framework = ['ionic' OR 'cordova']
platform = ['ios']
# Install core dependencies
npm uninstall -g cordova ionic
npm install -g cordova@{selectedCordovaVersion} ionic@{selectedIonicVersion}
# Install dependencies and execute any postInstall tasks
npm install
# Install bower dependencies if necessary
if [ -e bower.json ]; then bower install; fi
# rebuild node-sass dependencies
npm rebuild node-sass
# add platform folder if necessary
if [ ! -d "./platforms/{platform}" ]; then {framework} platform add {platform}; fi
# restore platforms/plugins/resources if ionic
if [ {framework} eq 'ionic' ]; then ionic state restore --plugins && ionic resources; fi
# prepare/build platform
{framework} build {platform}
Troubleshooting Build Failures:
Here’s what you can to do quickly diagnose and likely resolve build errors:
-
Clone your repo and check if your app builds locally
-
Double check your third party dependencies
-
Double check your platform tool versions and folders
Clone your repo and check if your app builds locally
It’s important to make sure there are no discrepancies between your remote branch and local git state.
Buddybuild creates a fresh clone of your code and executes build commands on every commit.
Here’s how to replicate this process and ensure your remote branch is up to date:
-
Clone your repo into a new location / folder on your machine
-
Make sure that the cordova/ionic/node versions installed on your machine are what’s being used on buddybuild
-
Make sure to run the same series of commands used in buddybuild’s Cordova / Ionic setup in the same order on your local machine.
Double check your third party dependencies
Node (package.json)
A common cause of issues is a package.json
that specifies non-explicit
versions of package dependencies (i.e. using carets ^
and tildes ~
).
This might result in failed builds because different versions of
dependencies are being installed on buddybuild than what is being used
on your local machine.
Cordova / Ionic plugins (config.xml)
If the plugin versions are not explicitly defined, in other words, they are using tildes/carets, then you might have problems very similar to what happens with non-explicit versions for node.
There have been instances where a non-explicit version resulted in a
plugin being downloaded on buddybuild that is dependent on a newer
version of a platform tool than what is specified in your config.xml
.
In these instances, we’ve had to ask the customer to update their
platform tool versions in their config.xml
.
<engine name="ios" spec="" />
Dependency Post-Installation Steps
There have been instances where a customer’s dependency invokes an executable as a postInstall task (i.e. running CocoaPods). This can lead to issues depending on the version of the executable being run.
Double check your platform tool versions and folders
In the past, we’ve seen a few cases where checked in platform folders fail on CI machines. If possible, please avoid checking them in.
Also, make sure that there are engine entries in your config.xml for all your platforms of interest. This guarantees that buddybuild is using the exact platform tool versions that you’re using locally.
<engine name="ios" spec="" />
We have also noticed instances where the platform tool versions
specified in the config.xml
are incompatible with the project and
needed to be either upgraded or downgraded.
Troubleshooting Common Errors
MainActivity.java:*: error: package org.apache.cordova does not exist
If the platform folder is committed, this generally indicates that it’s misconfigured and cannot be built. We recommend you delete the platform folder and then commit the change.
error: The app icon set named "AppIcon" did not have any applicable content.
This indicates that the iOS platform tools version we’re using is
incompatible with your project. In these instances, the best way to
guarantee that buddybuild is using the exact version you’re using is to
ensure that there’s the below entry in your config.xml
:
<engine name="ios" spec="" />
Cannot find module 'shelljs'
This indicates that buddybuild’s cordova/ionic setup steps were not run because we didn’t recognize your project as a cordova/ionic project. Please make sure that your project satisfies the prerequisites listed under "Cordova / Ionic setup in buddybuild", namely that it at least has the following:
-
www
folder -
config.xml
Error: Cannot find module 'unorm'
This generally indicates that there’s an issue with your committed platform directory. It’s generally recommended to not commit the directory unless you have to.
Error: Source path does not exist: resources/{platform}/icon/drawable-hdpi-icon.png
This generally indicates that your repository is missing a icon resources directory for a platform we’re trying to add. Our suggestion is to make sure the icon resources directory is already submitted for the platform in question at "resources/{platform}/icon" by using "ionic resources {platform}"
"Caught exception: undefined" when building plugins
This indicates a failure that’s been masked by the ionic CLI while
running requisite commands to build the plugins. Please contact
buddybuild support so that they can attempt to manually add the plugins
using "cordova plugin add
Failure to build a committed platform directory
Generally, committing any platforms directory is unnecessary and tends to lead to build issues on CI systems. It’s recommended that you delete it as we automatically add the platforms directory on your behalf if it’s not already present.
fatal error: 'Cordova/CDVPlugin.h' file not found
This indicates that buddybuild’s cordova/ionic setup steps were not run because we didn’t recognize your project as a cordova/ionic project. Please make sure that your project satisfies the prerequisites listed under "Cordova / Ionic setup in buddybuild", namely that it at least has the following:
-
www
folder -
config.xml
Error: Cannot find plugin.xml
for plugin "blah". Please try adding it again.
This generally indicates that you have an invalid plugins directory
checked in. When we attempt to add the appropriate platform using
cordova/ionic platform add
, that will not generate the plugins
directory if the plugins directory is already present.
Our recommendation is to either fix the checked in plugins directory or remove it altogether.