skip to Main Content

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

Answers


  1. 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
    
    Login or Signup to reply.
  2. If you are using Kotlin DSL you can use like this

    project.properties["BASE_API_URL"].toString()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search