android.useandroidx property is not enabled, enable androidx property, androidx, androidx dependencies, build.gradle

Android use androidx property is not enabled error [Solved]

While working with android studio while developing android applications, you should be careful to follow the right procedures and follow the documentation provided else your app will not build due to errors

Errors in android studio are common as you have to ensure that at every stage after adding any new feature that no errors are present

In previous articles, we have discussed various errors that occurs in android studio and how to solve them as listed below

In this article, we shall discuss how to solve an error that occurs due when android x is introduced in a project and yet the project is not enabled to use android x features

The error android.useandroidx property is not enabled error appears as shown below in android studio

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.

When the project detects the above error, it also shows the dependency that is making the error to appear in your project. For my project, the dependency added that is bringing the error is as follows

The following AndroidX dependencies are detected: androidx.annotation:annotation:1.1.0

What causes the error android.useandroidx property is not enabled

When creating an android app project, android studio determines automatically the features that your project will have depending on the android studio version you have installed.

For a project that does not have android x supported by default and you introduce android x features using the android x dependency and fail to enable it for use in your project, the above error will be visible and will stop your app from building successfully.

How to add android x library in android studio

According to android developers’ official website, Androidx is an improvement that has major changes to the initial android support library.

Android announced that it will no longer be supporting android support library therefore there is the need to move to android x since all libraries and features will be in form of android x.

To add android x library in your project so that you can consume the features provided by it follow these steps

  • In your project, open build.gradle file for app
  • In the dependencies section, the following dependencies are necessary though not all are required
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
  • Click sync button that appears at the top of the screen
  • Wait for gradle to build to finish

When the above dependencies are added and gradle builds successfully, your project will be ready to use android x features

When you build the project after adding android x features to your project after changing the xml files to android x support library, the error 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 will appear.

How to solve error android.useandroidx property is not enabled

 Once the android x library is added in the build.gradle for app as a dependency, it is now easier to solve the error android.useandroidx property is not enabled since you will only need to enable android x in gradle.properties file using the steps shown below

  • In the gradle scripts section at the left sidebar, click to select gradle.properties which is the file that contains project properties
  • You will need to add this two lines of code which sets or allows use of android x to true and also enable jefitier by setting it to true which converts third parties to automatically use android x as shown
android.useAndroidX=true
android.enableJetifier=true
  • Click sync button and allow gradle to build and finish

Once build has completed successfully, rebuild your project and at this stage the error android.useandroidx property is not enabled will be solved