build.gradle file does not access to gradle.properties

1k Views Asked by At

I have an android project. I am attempting to call buildConfigField() function in build.gradle file, but the property that I have declared in gradle.properties file cannot be found.

I have used this code in gradle.properties:

ACCESS_KEY="access_key"

and this code in defaultConfig block in build.gradle file:

buildConfigField("String", "ACCESS_KEY", ACCESS_KEY)

but the last parameter is unknown! I have selected that and pressed ctrl + Q on my keyboard, the message is No documentation found.

I have rebuilt and made my project but it still is not working!

2

There are 2 best solutions below

0
On

The double quote in the gradle.properties it not required.

ACCESS_KEY=access_key

Try to print the ACCESS_KEY in the gradle file and check your build console for the output of this:

print("Access key $ACCESS_KEY")

enter image description here

If you are using the Kotlin gradle script, you can get the gradle property values as below.

val ACCESS_KEY: String by project
0
On

If you are using Kotlin DSL you can use like this

project.properties["BASE_API_URL"].toString()