尝试访问其他文件时切换到 Kotlin DSL Unresolved reference

Switching to Kotlin DSL Unresolved reference when trying to access other file

我在尝试为我的 gradle 文件使用 Kotlin DSL 时遇到错误。

build.gradle(app) 中,我有一个函数可以检索存储在 文件 keys.properties,Groovy 中的函数如下:

// Retrieve key api
def getApiKey() {
    def keysFile = file("keys.properties")
    def keysProperties = new Properties()
    keysProperties.load(new FileInputStream(keysFile))
    def apiKey = keysProperties['API_KEY']
    return apiKey
}

当切换到 Kotlin DSL 时,我天真地更改了函数如下:

// Retrieve key for TMDB api
fun getApiKey() {
    val keysFile = file("keys.properties")
    val keysProperties = Properties()
    keysProperties.load(FileInputStream(keysFile))
    val apiKey = keysProperties["API_KEY"]
    return apiKey
}

构建然后returns出现如下错误:

.../app/build.gradle.kts:13:26: Unresolved reference: Properties

有谁知道如何解决这个问题?

编辑

根据#bam bam 的建议,添加导入 import java.util.Properties 解决了问题。但是其他问题出现了,请参阅 this question

您是否导入了 class?在 build.gradle.kts

之上添加 import java.util.Properties