16

I am getting the following error while trying to build my android app:

Task :app:mergeDebugResources FAILED

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.versionedparcelable:versionedparcelable:1.0.0, androidx.slidingpanelayout:slidingpanelayout:1.0.0, androidx.fragment:fragment:1.0.0, androidx.core:core:1.0.0, androidx.customview:customview:1.0.0, androidx.swiperefreshlayout:swiperefreshlayout:1.0.0, androidx.interpolator:interpolator:1.0.0, androidx.loader:loader:1.0.0, androidx.drawerlayout:drawerlayout:1.0.0, androidx.viewpager:viewpager:1.0.0, androidx.collection:collection:1.0.0, androidx.localbroadcastmanager:localbroadcastmanager:1.0.0, androidx.lifecycle:lifecycle-common:2.0.0, androidx.arch.core:core-common:2.0.0, androidx.annotation:annotation:1.0.0, androidx.lifecycle:lifecycle-livedata:2.0.0, androidx.legacy:legacy-support-core-ui:1.0.0, androidx.lifecycle:lifecycle-viewmodel:2.0.0, 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.lifecycle:lifecycle-runtime:2.0.0, androidx.coordinatorlayout:coordinatorlayout:1.0.0, androidx.asynclayoutinflater:asynclayoutinflater:1.0.0, androidx.print:print:1.0.0

I modified the project's gradle.properties file and set "android.userAndroidX" to true. But everytime I try to build again it goes back to false automatically. Is there any chance that gradle.properties is being overwritten by any other task during the build?

Thanks!

Aurumque
  • 429
  • 1
  • 4
  • 8

9 Answers9

48

Presumably you are using cordova-android@8 (type cordova platform ls to find the platform versions in your project).

So you have 2 options:

  1. Update to cordova-android@9 which implicitly supports AndroidX:

    cordova platform rm android && cordova platform add android@9
    

    In your config.xml add the following line:

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

    More details here: cordova documentation

  2. Add cordova-plugin-androidx to your Cordova project, which persistently sets the native AndroidX flags for cordova-android@8:

    cordova plugin add cordova-plugin-androidx
    

If after adding one of these your project still fails to build, it may be because it contains Cordova plugins whose native Android code references the legacy Android Support Library (to which AndroidX is the successor). To resolve this, you can add cordova-plugin-androidx-adapter to your project which will dynamically patch the source code of those plugins to migrate them to AndroidX:

cordova plugin add cordova-plugin-androidx-adapter
DaveAlden
  • 30,083
  • 11
  • 93
  • 155
13

In your config.xml add the following line:

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

More details here: cordova documentation

user3980196
  • 493
  • 1
  • 5
  • 14
1

What worked for me was downgrading Cordova Social Sharing plugin to 5.6.8

cordova plugin add  cordova-plugin-x-socialsharing@5.6.8

(before doing that remove the previous version of this plugin, then remove all platforms, then reinstall all platforms)

Guy Sela
  • 78
  • 6
0

Add to gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

In AndroidStudio Click: File->Invalidate Cashes / Restart -> Invalidate and Restart

yangfengfan
  • 141
  • 4
  • 1
    Thank you for your reply. I set it to true directly, but it is changed everytime I try to build. I don't have AndroidStudio installed. I'm building through command line. – Aurumque Sep 10 '20 at 16:20
  • I'm not sure the cause of the problem,[this blog](https://medium.com/androiddevelopers/migrating-to-androidx-tip-tricks-and-guidance-88d5de238876) may help. – yangfengfan Sep 10 '20 at 16:37
  • 2
    You can change them in platforms/android/cordova/lib/configGradlePropertiesParser.js in the this._defaults objects – MonOve Sep 10 '20 at 18:40
0

You can try cordova prepare android if you are using latest cordova it will patch your source files and also update gradle.properties

Nandan
  • 172
  • 8
0

first Open your Project gradle scripts>> then open gradle.properties And Finally paste this two line code

android.useAndroidX=true

android.enableJetifier=true

enter image description here

Sarwar Ahmed
  • 657
  • 6
  • 9
0
cordova plugin add cordova-plugin-androidx

cordova plugin add cordova-plugin-androidx-adapter
0

I've updated my Android platform to 9.1.0 today as well as the plugins I use. However compilation of my projects started to output Task :app:mergeDebugResources FAILED error and This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled.. I've been looking for several reasons and tried different solutions proposed here on SO, but the most accurate idea was given by @Guy Sela who suggested a plugin can use the new AndroidX dependencies and this was the reason. So before you try to use the AndroidXEnabled property in Cordova config or plugin adapter for the AndroidX (which are both non-recommended by Cordova at the time of 9.1.0 Android platform) look for a plugin you recently updated.

-2

I was stuck for 2 days than I got this you just need to install these two plugin nothing else you'll have to do

  1. add plugin to enable AndroidX in the project

    cordova plugin add cordova-plugin-androidx
    
  2. add plugin to patch existing plugin source that uses the Android Support Library to use AndroidX

    cordova plugin add cordova-plugin-androidx-adapter
    
General Grievance
  • 4,555
  • 31
  • 31
  • 45
harun_me
  • 111
  • 1
  • 4
  • This is exactly the same solution as in [Kangudie Muanza - Killmonger's answer](https://stackoverflow.com/a/64972426/2227743). – Eric Aya Jan 06 '21 at 12:17