https://kotlinlang.org logo
Title
n

nuhkoca

05/22/2019, 7:23 PM
How do I retrieve val from
gradle.properties
and apply it with
buildConfigField
Below doesn’t work, I mean BASE_URL is not detected.
buildTypes.forEach {
        it.buildConfigField("String", "BASE_URL", BASE_URL)
        it.buildConfigField("String", "BASE_PLAYER_URL", BASE_PLAYER_URL)
        it.buildConfigField("String", "ACCESS_TOKEN", ACCESS_TOKEN)
    }
gradle.properties
BASE_URL = "url"
BASE_PLAYER_URL = "url"
ACCESS_TOKEN = "token"
2
s

snowe

05/22/2019, 7:24 PM
Your question isn't clear.
Could you post your
gradle.properties
?
If you are trying to retrieve properties from the
gradle.properties
file in your
build.gradle.kts
you can look here. https://github.com/gradle/kotlin-dsl/tree/master/samples/project-properties
👍 1
n

nuhkoca

05/22/2019, 7:25 PM
@snowe thanks, updated the question
s

snowe

05/22/2019, 7:25 PM
yes, ok, so you are doing what I thought. Kotlin doesn't dynamically add the variables like groovy. Follow the above link and see how they do it.
👍 1
n

nuhkoca

05/22/2019, 7:26 PM
Yeah, I checked this one but couldn’t make it. Let me give it a try once again. Thanks!
s

snowe

05/22/2019, 7:27 PM
yours would look something like
val BASE_URL: String by project
though I don't know if it works with all caps variables.
👍 1
n

nuhkoca

05/22/2019, 7:28 PM
ahh silly me, as it seems, a config was an obstacle, now I’ve fixed it. Thanks for your time!
s

snowe

05/22/2019, 7:29 PM
of course.