• 28-Dec-2022
Lightrun Team
Author Lightrun Team
Share
This is a glossary of all the common issues in Apache Cordova Android

Troubleshooting Common Issues in Apache Cordova Android

Lightrun Team
Lightrun Team
28-Dec-2022

Project Description

 

Apache Cordova is a mobile application development framework that allows you to create mobile apps using web technologies such as HTML, CSS, and JavaScript. It provides a set of APIs that allow you to access native device features such as the camera, GPS, and more, from within your mobile app.
Cordova Android is the version of Cordova that allows you to build Android apps. It provides a set of APIs and tools that allow you to build, test, and deploy Android apps using Cordova. Cordova Android uses a webview, which is a browser component that allows you to run web-based apps within a native Android app.
Cordova Android is useful for developers who want to build cross-platform mobile apps that can run on both Android and other platforms such as iOS, Windows, and more. It allows you to write your app once and then deploy it to multiple platforms, saving you time and effort. Cordova Android is particularly useful for developers who want to build apps for Android devices but do not want to learn the native Android development languages and tools.

Troubleshooting Apache Cordova Android with the Lightrun Developer Observability Platform

 

Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.
  • Instantly add logs to, set metrics in, and take snapshots of live applications
  • Insights delivered straight to your IDE or CLI
  • Works where you do: dev, QA, staging, CI/CD, and production

Start for free today

The following issues are the most popular issues regarding this project:

Cordova 11.0.0 + Android 11.0.0 – cordova prepare android –debug command fails

 

It is possible that the cordova prepare android --debug command is failing because of issues with your Cordova project configuration or with the dependencies of your project. Here are some things you can try to troubleshoot the issue:

  1. Make sure that you have installed the required dependencies for your Cordova project. Cordova Android requires the Android SDK, which you can install using Android Studio or the standalone SDK Manager.
  2. Check the output of the cordova prepare android --debug command for any error messages or warnings that might indicate the cause of the failure.
  3. Try running cordova clean to delete any stale files that might be causing issues with the build process.
  4. Make sure that your Cordova project is correctly configured for Android. You can check the config.xml file in your project’s root directory to ensure that the correct target Android version and build tools are specified.
  5. If you are using any third-party plugins in your Cordova project, make sure that they are compatible with Cordova Android 11.0.0 and Android 11.0.0. You can check the documentation for the plugins to see if there are any known issues or compatibility issues.
  6. If you are still having issues, you may want to try running the cordova prepare android --debug command with the --verbose flag to get more detailed output that might help you troubleshoot the issue.

Android clicking input type=file brings up system file browser, not camera options

 

If you are using an input element with the type="file" attribute in a Cordova Android app, clicking on it should bring up the system file browser, which allows the user to select a file from their device’s storage.

If you want to bring up the camera options instead, you can use the capture attribute of the input element. For example:

<input type="file" accept="image/*" capture>

This will bring up the camera options (such as taking a photo or selecting a photo from the gallery) when the user clicks on the input element.

Note that the capture attribute is not supported on all browsers, so you may want to check for its availability before using it. You can use the navigator.mediaDevices.getUserMedia API to check for the availability of the capture attribute.

if ('capture' in document.createElement('input')) {
  // The capture attribute is supported
} else {
  // The capture attribute is not supported
}

 

gradlew: ‘sh’ is not recognized as an internal or external command

 

The error message 'sh' is not recognized as an internal or external command is usually encountered when running the gradlew command on Windows, and it indicates that the system cannot find the sh executable.

Here are some things you can try to resolve this issue:

  1. Make sure that you have installed the required dependencies for your Cordova project, including the Android SDK and the Gradle build tool.
  2. Check the value of the JAVA_HOME environment variable. This variable should point to the location of your Java installation, which is required by Gradle.
  3. Make sure that the sh executable is in your system’s PATH environment variable. You can check the value of the PATH variable by running the following command in a command prompt:
echo %PATH%

If the sh executable is not in the PATH variable, you can add it by modifying the PATH variable in the system or user environment variables.

  1. If you are still having issues, you may want to try running the gradlew command with the --stacktrace flag to get more detailed output that might help you troubleshoot the issue.

App config.xml does not update AndroidManifest.xml file’s versionCode, versionName or anything

 

In a Cordova Android app, the config.xml file is used to specify the configuration options for your app, including the app’s name, description, and other metadata. The AndroidManifest.xml file, on the other hand, is an Android-specific configuration file that is used to define the app’s package name, version code, and other system-level properties.

By default, Cordova Android will automatically generate the AndroidManifest.xml file based on the information in the config.xml file when you run the cordova prepare or cordova build command. If you make any changes to the config.xml file, you will need to run one of these commands again to update the AndroidManifest.xml file.

There are several config.xml elements that map to the AndroidManifest.xml file. For example, the widget element’s id attribute is used to set the app’s package name, and the version attribute is used to set the app’s version code and version name. Here is an example of how these elements are used in the config.xml file:

<widget id="com.example.app" version="1.0.0">
  <!-- other configuration options -->
</widget>

This will result in the following AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app"
    android:versionCode="10000"
    android:versionName="1.0.0">
  <!-- other manifest elements -->
</manifest>

If you are making changes to the config.xml file but they are not being reflected in the AndroidManifest.xml file, there might be an issue with your Cordova project configuration. Some things you can try to troubleshoot this issue include:

  1. Make sure that you are running the cordova prepare or cordova build command after making changes to the config.xml file.
  2. Check the config.xml file for any syntax errors or missing elements that might be causing issues with the build process.
  3. Try running the cordova clean command to delete any stale files that might be causing issues with the build process.
  4. If you are using any third-party plugins in your Cordova project, make sure that they are compatible with your Cordova and Android versions and are correctly configured in the config.xml file.

More issues from Apache repos

 

Troubleshooting apache-superset | Troubleshooting apache-airflow | Troubleshooting apache-openwhisk | Troubleshooting apache-cordova-ios | Troubleshooting apache-echarts | Troubleshooting apache-pulsar

Share

It’s Really not that Complicated.

You can actually understand what’s going on inside your live applications. It’s a registration form away.

Get Lightrun

Lets Talk!

Looking for more information about Lightrun and debugging?
We’d love to hear from you!
Drop us a line and we’ll get back to you shortly.

By submitting this form, I agree to Lightrun’s Privacy Policy and Terms of Use.