user8542613 user8542613 - 3 years ago 107
Android Question

Android.Gradle. Separate data from code

In my app/build.gradle I have about 30 defined constants.
Something like this:

def MY_CONST1 = "http://..."
def MY_CONST2 = "dB_name"
...
def MY_CONST30 = "some value"


As result data (constants) and code that process this data is mixed. I think this is not good. So I want to separate them. What is the best way to do this?

Answer Source

Just use different gradle files to separate them:

constants.gradle:

 def MY_CONST1 = "http://..."
 def MY_CONST2 = "dB_name"
 ...
 def MY_CONST30 = "some value"

In your app/build.gradle:

...
...
apply from: 'constants.gradle'

Also you could put all your custom gradle files in a folder called gradlescript (or as you want). In this case in your app/build.gradle use:

apply from: 'gradlescript/constants.gradle'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download