Android Build Error - android.useAndroidX property is not enabled

I got an below error when building the android apk, What I need to update ? Please help…

UserError: FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ‘:app:mergeDebugResources’. > This project uses AndroidX dependencies, but the ‘android.useAndroidX’ property is not enabled. Set this property to true in the gradle.properties file and retry. The following AndroidX dependencies are detected: androidx.slidingpanelayout:slidingpanelayout:1.0.0, androidx.versionedparcelable:versionedparcelable:1.1.0, androidx.fragment:fragment:1.1.0, androidx.customview:customview:1.0.0, androidx.swiperefreshlayout:swiperefreshlayout:1.0.0, androidx.lifecycle:lifecycle-viewmodel:2.3.0-alpha03, androidx.interpolator:interpolator:1.0.0, androidx.loader:loader:1.0.0, androidx.drawerlayout:drawerlayout:1.0.0, androidx.activity:activity:1.0.0, androidx.collection:collection:1.1.0, androidx.viewpager:viewpager:1.0.0, androidx.savedstate:savedstate:1.1.0-alpha01, androidx.localbroadcastmanager:localbroadcastmanager:1.0.0, androidx.arch.core:core-common:2.1.0, androidx.lifecycle:lifecycle-runtime:2.3.0-alpha03, androidx.annotation:annotation:1.2.0-alpha01, androidx.lifecycle:lifecycle-common:2.3.0-alpha03, androidx.lifecycle:lifecycle-livedata:2.0.0, androidx.legacy:legacy-support-core-ui:1.0.0, androidx.core:core:1.4.0-alpha01, androidx.appcompat:appcompat:1.3.0-alpha01, androidx.appcompat:appcompat-resources:1.3.0-alpha01, androidx.lifecycle:lifecycle-livedata-core:2.0.0, androidx.legacy:legacy-support-v4:1.0.0, androidx.media:media:1.0.0, androidx.arch.core:core-runtime:2.0.0, androidx.legacy:legacy-support-core-utils:1.0.0, androidx.documentfile:documentfile:1.0.0, androidx.cursoradapter:cursoradapter:1.0.0, androidx.vectordrawable:vectordrawable-animated:1.1.0, androidx.coordinatorlayout:coordinatorlayout:1.0.0, androidx.asynclayoutinflater:asynclayoutinflater:1.0.0, androidx.vectordrawable:vectordrawable:1.1.0, androidx.print:print:1.0.0

You need to add this line to your config.xml:

<preference name="AndroidXEnabled" value="true" />

Now I got the below error

UserError: FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ‘:app:compileDebugJavaWithJavac’. > Compilation failed; see the compiler error output for details.

Task :app:compileDebugJavaWithJavac FAILED
/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:40: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
^
/platforms/android/app/src/main/java/org/apache/cordova/camera/CordovaUri.java:25: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
^
/platforms/android/app/src/main/java/org/apache/cordova/camera/FileProvider.java:21: error: package android.support.v4.content does not exist
public class FileProvider extends android.support.v4.content.FileProvider {}
^
/platforms/android/app/src/main/java/io/github/pwlin/cordova/plugins/fileopener2/FileProvider.java:28: error: package android.support.v4.content does not exist
public class FileProvider extends android.support.v4.content.FileProvider {
^
/platforms/android/app/src/main/java/de/appplant/cordova/emailcomposer/Provider.java:22: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
^
/platforms/android/app/src/main/java/de/appplant/cordova/emailcomposer/Provider.java:24: error: cannot find symbol
public class Provider extends FileProvider {
^
symbol: class FileProvider
/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:303: error: cannot find symbol
this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
^
symbol: method getUriForFile(Activity,String,File)
location: class FileProvider
/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:801: error: cannot find symbol
Uri tmpFile = FileProvider.getUriForFile(cordova.getActivity(),
^
symbol: method getUriForFile(Activity,String,File)
location: class FileProvider
/platforms/android/app/src/main/java/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java:119: error: cannot find symbol
path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + “.fileOpener2.provider”, file);
^
symbol: method getUriForFile(Context,String,File)
location: class FileProvider
/platforms/android/app/src/main/java/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java:127: error: cannot find symbol
Uri path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + “.fileOpener2.provider”, file);
^
symbol: method getUriForFile(Context,String,File)
location: class FileProvider
/platforms/android/app/src/main/java/de/appplant/cordova/emailcomposer/AssetUtil.java:276: error: cannot find symbol
return Provider.getUriForFile(ctx, authority, file);
^
symbol: method getUriForFile(Context,String,File)
location: class Provider
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
11 errors

Task :app:mergeDebugJavaResource

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:app:compileDebugJavaWithJavac’.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use ‘–warning-mode all’ to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2s
26 actionable tasks: 26 executed
Command failed with exit code 1: /platforms/android/gradlew cdvBuildDebug -b /platforms/android/build.gradle
Error: Command failed with exit code 1: /platforms/android/gradlew cdvBuildDebug -b /platforms/android/build.gradle
at makeError (/node_modules/execa/lib/error.js:59:11)
at handlePromise (/node_modules/execa/index.js:114:26)
at processTicksAndRejections (internal/process/task_queues.js:97:5)

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:app:compileDebugJavaWithJavac’.

Compilation failed; see the compiler error output for details.

Build af09bf9e-9ed6-4594-aa32-617ad5c7df6c failed

In cases like this, you have to look at the log. Here’s the key message Cordova returns:

/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:40: error: package android.support.v4.content does not exist

There are similar messages for several other plugins.

What is the solution to fix these errors, please help on this.

Please help me on this, how to fix this issue when build for the android ?

You may need to ask the author of the plugin for help.

VoltBuilderSupport is for help with VoltBuilder itself. I only wish we were experts in all of the 700+ plugins which can be used!

on Phonegap, when we add these 2 plugins, these type of errors were fixed on Phonegapbuild.

cordova-plugin-androidx
cordova-plugin-androidx-adapter

But here not able to build the android properly. Please help us on this.

PhoneGap was using older versions of the Android SDK and Cordova. It’s not surprising that AndroidX is handled differently in newer versions.

It’s not anything which VoltBuilder is doing (or not doing). We organize your files and submit them to the standard build tools. The messages come from those tools, not VoltBuilder.