eqtèöck
eqtèöck

Reputation: 1085

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

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

Upvotes: 10

Views: 4227

Answers (1)

zmunm
zmunm

Reputation: 436

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

Upvotes: 14

Related Questions