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

 

Fix app startup error with cordova-android@11 new splash screens

The new Android 12 splash screen implementation from cordova-android@11 can cause your app to crash at startup with an extensive and meaningless Java error such as this:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: io.cordova.hellocordova, PID: 14640
    java.lang.RuntimeException: Unable to start activity ComponentInfo{io.cordova.hellocordova/io.cordova.hellocordova.MainActivity}: android.view.InflateException: Binary XML file line #24 in io.cordova.hellocordova:layout/splash_screen_view: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f0300df a=-1}
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: android.view.InflateException: Binary XML file line #24 in io.cordova.hellocordova:layout/splash_screen_view: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f0300df a=-1}

This is caused by a wrong theme set in AndroidManifest.xml by some plugin or your very own config.xml file. Instead of wasting hours dealing with the offensive plugin, simple add this to your config.xml to set the proper theme on build time directly:

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
    <activity android:theme="@style/Theme.App.SplashScreen"></activity>
</edit-config>

Notice this requires the proper namespace set in your config.xml widget element as follows: xmlns:android="http://schemas.android.com/apk/res/android"

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.

Disclaimer

The content in this post is for general information purposes only. The information is provided by the author and/or external sources and while we endeavour to keep the information up to date and correct, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the website or the information, products, services, or related graphics contained on the post for any purpose. Some of the content and images used in this post may be copyrighted by their respective owners. The use of such materials is intended to be for educational and informational purposes only, and is not intended to infringe on the copyrights of any individuals or entities. If you believe that any content or images used here violate your copyright, please contact us and we will take appropriate measures to remove or attribute the material in question.