Issue
I want to retreive key from local.properties
file that looks like :
sdk.dir=C\:\\Users\\i30mb1\\AppData\\Local\\Android\\Sdk
key="xxx"
and save this value in my BuildConfig.java
via gradle Kotlin DSL. And later get access to this field from my project.
Solution
Okay. I found one possible solution.
- In my build.gradle.kts I create a value that retrieves my key:
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
val key: String = gradleLocalProperties(rootDir).getProperty("key")
- And in the block
buildTypes
I write it:
buildTypes {
getByName("debug") {
buildConfigField("String", "key", key)
}
}
- And in my Activity now I can retrieve this value:
override fun onCreate() {
super.onCreate()
val key = BuildConfig.key
}
I think there should be another solution (through undocumented extensions)?
Answered By - i30mb1
Answer Checked By - David Goodson (JavaFixing Volunteer)