You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已导入Multiplatform Settings依赖仍遇Unresolved reference错误

编译报错:Unresolved reference 'PreferencesSettings'

背景

实习开发模拟应用时使用multiplatform-settings库,Gradle同步未出现问题,相关依赖配置如下:

sourceSets {
    val desktopMain by getting
    
    androidMain.dependencies {
        implementation(compose.preview)
        implementation(libs.androidx.activity.compose)
        // https://mvnrepository.com/artifact/androidx.preference/preference-ktx
        //implementation("androidx.preference:preference-ktx:1.2.1")
        //other dependencies...

    }
    commonMain.dependencies {
        //Junit test
        implementation("com.russhwolf:multiplatform-settings-test:1.3.0")
        //other dependencies...

        implementation("com.russhwolf:multiplatform-settings:1.3.0")
    }
}

代码实现

编写TokenStorage对象使用PreferencesSettings:

import com.dian.prueba.model.Tokens
import com.russhwolf.settings.PreferencesSettings
import com.russhwolf.settings.set
import com.russhwolf.settings.Settings
import java.util.prefs.Preferences

object TokenStorage {
    private const val ACCESS_TOKEN_KEY = "access_token"
    private const val REFRESH_TOKEN_KEY = "refresh_token"
    val settings : Settings = PreferencesSettings(Preferences.userRoot())
}

报错情况

编译项目时收到错误:

Unresolved reference 'PreferencesSettings'.

但代码中的import com.russhwolf.settings.PreferencesSettings并未出现报错提示。

已尝试的操作

  • 重新导入Gradle项目
  • 清除IDE缓存并重启
  • 删除.idea目录后重新同步Gradle

内容的提问来源于stack exchange,提问作者Agnes Diana Carbajal Andia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 01:42:45