How to use a property from gradle.properties inside android activity? Whenever I build the code it throws error. Is there a particular way that the properties can be accessed inside the activities?
You can't access the gradle.properties
from your Activity.
The gradle.properties
is used while you are building the app, it doesn't exist in runtime or inside your apk.
However you can set some values inside the BuildConfig
class from your build.gradle
script (reading from the gradle.properties for example).
Just use somenthing like:
buildConfigField "boolean", "MY_FLAG", "true"
buildConfigField "String" , "MY_KEY" , "\"XXXXX-XXXXX-XXX\""
in gradle.properties:
SIMPLE_STRING=ABC
in build.gradle:
android {
buildTypes {
debug {
buildConfigField 'boolean', 'PREPROD', 'true'
buildConfigField "String" , "MY_KEY" , SIMPLE_STRING
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With