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.

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 someone Commented Apr 13, 2019 at 18:02

2 Answers 2

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.

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 :)

1
  • 1
    Have already tried that multiple times. There's nothing to migrate. Commented Jan 6, 2019 at 10:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.