Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm getting the "AndroidX dependencies" error with android.useAndroidX enabled

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!

like image 374
Aurumque Avatar asked Sep 10 '20 14:09

Aurumque


People also ask

What is Cordova plugin AndroidX?

This Cordova/Phonegap plugin enables AndroidX in a Cordova project (AndroidX is the successor to the Android Support Library). This plugin is useful if your project contains plugins which have migrated to AndroidX or if you otherwise want to enable AndroidX in your Cordova Android platform project.


2 Answers

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
like image 80
DaveAlden Avatar answered Oct 28 '22 14:10

DaveAlden


In your config.xml add the following line:

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

More details here: cordova documentation

like image 26
user3980196 Avatar answered Oct 28 '22 13:10

user3980196