Search code examples
javaandroidandroid-studiobuild.gradleandroidx

Getting Androidx library issue even though its not enabled in android project


I am getting this issue

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.annotation:annotation:1.1.0

I keep getting this error and I have been searching the internet to figure out what is wrong and I cannot find anything

"And I can't use Androidx library in my project "


Solution

  • In many of the answers on SO on this problem it has been suggested to add exclude 'META-INF/DEPENDENCIES' and some other excludes. However none of these worked for me. In my case scenario was like this:

    I had added this in dependancies:

    implementation 'androidx.annotation:annotation:1.1.0'
    

    And also I had added this in gradle.properties:

    android.useAndroidX=true
    

    Both of these I had added, because I was getting build error 'cannot find symbol class Nullable' and it was suggested as solution to this on some of answers like here

    However, eventually I landed up in getting error:

     More than one file was found with OS independent path 'androidsupportmultidexversion.txt'
    

    No exclude was working for me. Finally I just removed

    implementation 'androidx.annotation:annotation:1.1.0'
    

    from build.grdle file. and finally I got rid of this

    ( More than one file was found with OS independent path 'androidsupportmultidexversion.txt' )

    "More than one file was found with OS..." build error.
    

    I wasted hours of mine.But didn't found solution of this. Then i just change my project

    minSdkVersion 19 
    

    to

     minSdkVersion 21 
    

    And finally i am able to build my apk file without any error