Common cordova-android platform build errors and solutions

This topic includes some of the common Cordova CLI build errors that I’ve found, with the recommended solutions or the ones that worked for me.

Apache Cordova logo phonegap

 

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

This issue has two possible solutions:

  1. Solution 1: Run the skdmanager --licenses command in the Android SDK tools folder.
  2. Solution 2: Install or reinstall the required Android SDK Build-tools from the Android SDK Manager or the Android Studio SDK manager to get rid of this issue.

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 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.

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 DEP10402: Could not locate a deployable apk. You may need to build your project

This Visual Studio error was introduced by the folder structure change from [email protected] To fix this, create a settings file platforms/android/build-extras.gradle with these contents or download it here.

android.applicationVariants.all { variant ->
	variant.outputs.all { output ->
		if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
			/* Fix Visual Studio 2015 / 2017 [email protected]+ Error DEP10402: Rename and move APK one level up */
			println ">>> Renaming APK for Visual Studio [from https://andreszsogon.com]"
			output.outputFileName = "../../../../../build/outputs/apk/android-${variant.name}.apk"
		}
	}
}

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

Duplicate entry: android/support/v13/ …

Program type already present: android.support.v13.view.DragAndDropPermissionsCompat …

This error is be introduced by the inclusion of different API levels for the com.android.support library in your project properties or gradle file. To prevent this, edit project.properties and make sure all com.android.support entries use the same API level, for example:

cordova.system.library.1=com.android.support:support-v4:26.+
cordova.system.library.2=com.android.support:support-v13:26.+

Where X is any library number.

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;)

Solution 1: Change the Android Gradle Plugin version

Open build.gradle and change the com.android.tools.build:gradle version to one that is compatible with your gradle version:

dependencies {
    classpath 'com.android.tools.build:gradle:4.0.0'
}

To determine the right version for your platform, refer to the platform’s release notes in the Apache Cordova blog.

Solution 2: Clear gradle cache

Stop all running gradle instances:

gradle --stop

Delete the gradle cache folder:

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

Discussion about this error can be found here.

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 config.xml designer. Select Globally Installed Cordova version, then clean the project and retry.

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:

<method name="&lt;init>()V"/>

Replace with:

<method name="&lt;init&gt;()V"/>

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

Discussion about this error on the Google issue tracker.

Android resource compilation failed

This error is introduced whenever you add an <edit-config> group to config.xml, for example, the following code to allow moving the app to SD Card:

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest">
  <manifest android:installLocation="auto" />
</edit-config>

To fix this error, add this namespace attribute to your config.xml file:

xmlns:android="http://schemas.android.com/apk/res/android"

Discussion about this error can be found here.

Could not resolve androidx.core:core:1.6.+.

Error introduced by cordova-plugin-push with AndroidX enabled.

To fix, add full version numbers to these libraries in project.properties:

  • androidx.core:core:1.6.0
  • com.google.firebase:firebase-messaging:18.0.0

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 [email protected]

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

public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {

	final String packageName = parentEngine.cordova.getActivity().getPackageName();
	final PackageManager pm = parentEngine.cordova.getActivity().getPackageManager();

	ApplicationInfo appInfo;
	try {
		appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
		if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
			// debug = true
			handler.proceed();
			return;
		} else {
			// debug = false
			// ADD THESE LINES TO IGNORE INVALID SSL CERTIFICATE
			handler.proceed();
			return;
			// COMMENT THIS LINE
			//super.onReceivedSslError(view, handler, error);
		}
	} catch (NameNotFoundException e) {
		// When it doubt, lock it out!
		super.onReceivedSslError(view, handler, error);
	}
}

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

How to debug your Cordova Android app