Android Studio does not recognise androidx preference library in xml
Asked Answered
M

2

10

I am trying to use the new androidx preference library but Android Studio simply does not recognize it in the xml. In my res/xml/setting_prefs.xml, I have

<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:key="@string/settings">
    <androidx.preference.SwitchPreference android:key="test"
        android:title="test"/>
    <androidx.preference.SeekBarPreference
        android:title="Stopwatch frequency"
        android:summary="The time (in ms) between each update of the stopwatch"
        android:defaultValue="100"
        android:min="50"
        android:max="200"/>
</androidx.preference.PreferenceScreen>

Although this works fine when run, android studio simply does not recognize anything and does not provide autocomplete suggestions.

I have added the relevant dependencies in the build.gradle file:

implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation 'androidx.preference:preference:1.1.0-alpha02'

and android studio is set to use androidx with

android.enableJetifier=true
android.useAndroidX=true

(Note that this is a completely new Androidx project and not an old project I migrated. I used migrate to androidx immediately after starting a new project)

I am using Android Studio 3.2.1 and have already tried common solutions like invalidate cache+restart, removing the .idea folder, removing the dependencies and adding them again (and even changing the version), deleting the xml file and creating a new one and even trying to run a clean gradle build. The only things it recognizes or provides suggestion on are the android.preference.PreferenceScreen class and some other classes from the default (non androidx library). Note that the androidx preference class is being recognized in the java code without any trouble.

Mablemabry answered 4/1, 2019 at 13:5 Comment(1)
To give a status update:- No, the problem was not solved. I abandoned that project as it was just a test project and never faced similar issues with anything else. So, if someone figures it out or this issue is fixed in some later version, do leave an answer.It might help someoneMablemabry
W
0

Just use <PreferenceScreen> tag instead of androidx.preference.PreferenceScreen.

This is a bug, I hope it will solve soon. To sure that <PreferenceScreen> not appear any issue, just rename it when completed working with xml file.

Whereof answered 22/6, 2019 at 10:6 Comment(0)
E
0

What helped me was to click on refactor --> migrate to androidX in the top bar menu in android studio.

I than needed some manual work to make the build pass, but that was peanuts :)

Epistaxis answered 6/1, 2019 at 9:47 Comment(1)
Have already tried that multiple times. There's nothing to migrate.Mablemabry
W
0

Just use <PreferenceScreen> tag instead of androidx.preference.PreferenceScreen.

This is a bug, I hope it will solve soon. To sure that <PreferenceScreen> not appear any issue, just rename it when completed working with xml file.

Whereof answered 22/6, 2019 at 10:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.