rkmax
rkmax

Reputation: 18133

How to NOT hardcoded project settings

I'm making a simple android application and i want share the repo with other developers but i want write settings to external file and use into the android Code, this is possible with gradle?

example i want put in a file project_settings.gradle something like

APP_HOST=192.168.0.1

and in any place of my code i want use something like

String url = "http://" + BuildConfig.APP_HOST

that way i can share a project_settings.gradle.dist with the others developers

Upvotes: 0

Views: 176

Answers (1)

hidro
hidro

Reputation: 12541

You can try to set resValue in your build.gradle. This will create Android resources that will be available to access through your code.

https://plus.google.com/+XavierDucrohet/posts/UVKA58MZV3J

For example:

defaultConfig {
    minSdkVersion 9
    targetSdkVersion 21

    resValue "string", "country", "US"
    resValue "string", "oauth_token", "some_token"
}

In your code if you need to access country, call context.getString(R.string.country)

Upvotes: 2

Related Questions