Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved reference importing kotlinx.android and androidx.preference?

So having used one of the default templates in android studio I added a couple of imports and hit the error "unresolved reference" on preference and android.

Unsure if it was a minSdk issue I bumped the minSdk to 25 in build.gradle and re-synced it, still the same issue.

Any ideas anyone ?

like image 612
dave selby Avatar asked Oct 20 '25 05:10

dave selby


1 Answers

OK so I am sure I never used to have to add anything to build.gradle, guessing it was done automatically and somehow I have turned that feature off ?, but apparently I do now to solve this ...

So for anyone else stuck with this :

Want … import kotlinx.android.synthetic.main.fragment_button.*
Make sure you include id 'kotlin-android-extensions' in build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

Want … import androidx.preference.PreferenceManager.getDefaultSharedPreferences
Make sure you include “implementation 'androidx.preference:preference:1.1.1'” in build.gradle

dependencies {

    implementation 'androidx.preference:preference:1.1.1'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
…
like image 53
dave selby Avatar answered Oct 22 '25 19:10

dave selby