尝试访问其他文件时切换至Kotlin DSL未解析的参考 [英] Switching to Kotlin DSL Unresolved reference when trying to access other file
问题描述
我的gradle文件尝试使用Kotlin DSL时出现错误.
I have an error when trying to use Kotlin DSL for my gradle files.
在build.gradle(app)
中,我有一个函数可以检索存储在
文件keys.properties
,Groovy中的函数如下:
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
}
切换到Kotlin DSL时,我天真地更改了功能,如下所示:
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?
,添加一个导入import java.util.Properties
解决了问题..但是其他问题来了,请参见此问题
as suggested by #bam bam, adding an import import java.util.Properties
solved the problems.. But other problems came, see this question
推荐答案
您是否导入了类?在build.gradle.kts顶部添加import java.util.Properties
did you import class? add import java.util.Properties
on top of your build.gradle.kts
这篇关于尝试访问其他文件时切换至Kotlin DSL未解析的参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!