Common Apache Cordova build errors with Android

Apache Cordova logoThis topic includes some of the common Cordova CLI 7.1.0 build errors that I’ve found, with the recommended solutions or the ones that worked for me. References to Visual Studio included.

Cannot find module ‘android-versions’

Run the following command in the project’s folder to add the required dependency:

Discussion about this error on this stackoverflow topic.

No such file or directory: cordova_plugins.js

This is an erratic error that happens whenever you have removed the cordova-android platform and added it back. Using the cordova prepare and cordova clean commands with successful results should recreate your files from the platforms/android/app folder and fix this error. As a last resort, you can remove and readd the cordova-android platform again.

Could not determine the dependencies of task ‘:lintVitalRelease’.

Project : declares a dependency from configuration ‘releaseCompile’ to configuration ‘release’ which is not declared in the descriptor for project :CordovaLib

Your gradle version is too high, possible solutions:

  • Return to a previous Gradle version
  • Upgrade to a newer Cordova version
  • Upgrade your cordova-android version

Error: edge is not precompiled for Node (…)

This error was introduced by Node 6.x. To solve this issue, install edge-js from the command line:

Clean the project and build normally.

Error DEP10402: Could not locate a deployable apk. You may need to build your project

This error was introduced by the folder structure change from cordova-android@6.4.0. To fix this, create a settings file platforms/android/build-extras.gradle with these contents or download it here.

Warning: Remember to recreate this file whenever you remove the android platform!

Execution failed for task ‘:transformClassesWithDexForRelease’

If you are using cordova-android@6.3.0 or newer, you should uninstall the cordova-plugin-compat plugin because this cordova-android version already includes the BuildHelper.java and PermissionHelper.java files provided by the plugin.

Use this command to force the removal of the obsolete compat plugin:

Warning: Make sure the plugin was really removed; Visual Studio tends to keep plugin references in certain files like config.xml, android.json or fetch.json after removing the plugin from the IDE, and then re-adds the erased plugin on next build.

If required by another plugin (such as cordova-plugin-camera or cordova-plugin-geolocation) update those plugins to latest versions, then the depenency should be gone.

If you must keep another plugin that persists in the cordova-plugin-compat dependency, install cordova-plugin-compat version 1.2 from the command line:

Then Clean Solution from the Build menu. If the problem persists, delete the platforms/android folder and build again to re-create it.

The cordova-plugin-compat 1.2 won’t be actually installed if you have cordova-android 6.3.0+, but the reference in config.xml will be added:

Notice: When using cordova-plugin-compat@1.2, the following messages will show up in Visual Studio’s Error List on build time, since the plugin is not actually installed but skipped:

Error List

Visual Studio Error List

Discussion about this error on this stackoverflow topic.

Duplicate entry: android/support/v13/…

This error can be introduced by the repeated inclusion of the com.android.support library in your project properties or gradle file. To prevent this error, edit platforms/android/project.properties and comment the line:

Where “X” is any library number. Add # at the beginning to comment the previous line. You should already have another version of this library in this file, such as:

Clean the project and rebuild the APK to fix this error. Check out this post for additional notes.

Failed to notify project evaluation listener

com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V

Solution 1: Change the Android Gradle Plugin version

Open the platforms/android/build.gradle file from your project and change the com.android.tools.build:gradle  version to one that is compatible with your gradle version:

The following table shows the required gradle version according to the Android gradle plugin version. For more info view the Android Gradle Plugin release notes.

Android gradle plugin versions

Android gradle plugin versions

For Cordova 7.1.0 and cordova-android@6.3.0 with gradle 4.1, you can use version 2.3.3.

Solution 2: Clear gradle cache

Stop all running gradle instances:

Delete the gradle cache folder:

  • On Windows: %USER_HOME%\.gradle\caches\
  • On MacOS: $HOME/.gradle/caches/

Discussion about this error on this stackoverflow topic.

cordovaProject.projectConfig.getFileResources is not a function

When using Visual Studio, this error is caused by selecting an old (6.x) Cordova version from the confix.xml designer. Select Globally Installed Cordova version, then clean the project from the Build menu or the command line.

NDK is missing a “platforms” directory

This issue was introduced by the Android tools gradle plugin 2.3.0.

Solution 1

To fix this, open the platforms/android/build.gradle file from your project and change the com.android.tools.build:gradle  version with the non-bugged 2.2.3 one:

Solution 2

Installing the NDK would solve this warning as well, however this seems to require Android Studio, which is irrelevant for Cordova apps.

Discussion about this error on this stackoverflow topic.

The value of attribute “name” associated with an element type “item” must not contain the ‘<‘ character

To fix this error edit the api-versions.xml file in android-sdk\platform-tools\api and escape the “>” character properly. Find all occurrences of:

Replace with:

Notice: You must clean your cordova project afterwards for this error to disappear.

Discussion about this error on the Google issue tracker.

You have not accepted the license agreements of the following SDK components: Android SDK Build-Tools 26.0.2

Install or reinstall the required Android SDK Build-tools from the Android SDK Manager or the Android Studio SDK manager.

Android SDK Manager

Android SDK Manager

HTTPS connections rejected in Release configuration

Whenever your app tries to connect to an HTTPS URL with an invalid SSL certificate, or a certificate that requires latest Webview to be considered valid, the connection will be rejected with HTTP code 0. While the recommended solution is to buy a quality SSL certificate or use the free one from Let’s Encrypt, there’s a workaround to force your app to ignore invalid certificates.

Note: This fix was applied in cordova-android@6.3.0.

Locate and edit SystemWebViewClient.java, then edit the onReceivedSslError  method as shown in the following UPPERCASE comments:

Now SSL certificate errors will be ignored in both Debug and Release configurations.

Having another Cordova build-related issue?

You may leave your comment below with your error description and we’ll try to find a solution. Please include your cordova and cordova-android versions, and if using Visual Studio, mention which version do you have.

All product names, logos, and brands in this website are property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.