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

寵の児 提交于 2019-12-24 07:27:09

问题


I have an error when trying to use Kotlin DSL for my gradle files.

In build.gradle(app) I have a function to retrieve an api key stored in an file keys.properties, the function in Groovy is the following:

// 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
}

When switching to Kotlin DSL I naively changed the function as follow:

// 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
}

The build then returns the following error:

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

Does anyone know how to fix that?

Edit

as suggested by #bam bam, adding an import import java.util.Properties solved the problems.. But other problems came, see this question


回答1:


did you import class? add import java.util.Properties on top of your build.gradle.kts



来源:https://stackoverflow.com/questions/59046413/switching-to-kotlin-dsl-unresolved-reference-when-trying-to-access-other-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!