1

I have a source file in my project at app/src/(product name)/util. I also have two possible build variants of my product. You could view this as white labeling, but it's really just for targeting a test server vs. production. These files just contain a variety of string constants, used for things like the server address and access keys for the API. This is separate from the application's production vs. beta.

  1. I can't do an #ifdef, of course.
  2. Even if I put them in different folders, but I need to import them using com.productname.(target).ServiceConfig.java which I can't do.

How do I include a different set of string constants in each build variation?

The goal is to differentiate the builds by about 4-5 strings so I'm open to other options.

This is an inherited project, several years out of date, but I'm building it with the latest Android Studio and gradle.

(Suggesting tags in a comment would be welcomed, too, as would help with rephrasing unclear parts of this question. I don't have deep enough knowledge to be confident I've asked this well.)

Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
  • 1
    "How do I include a different set of string constants in each build variation?" -- for the sorts of things that you describe, I tend to use `buildConfigField` in Gradle, which results in the values going into `BuildConfig` in Java. See https://developer.android.com/studio/build/gradle-tips#simplify-app-development. – CommonsWare Apr 20 '20 at 20:35
  • That looks promsing. If you want to post that as an answer I'll happily accept it. This was really a place where I didn't know enough to ask the question well, so thank you for puzzling it out. – Steven Fisher Apr 20 '20 at 20:36
  • 1
    See also https://stackoverflow.com/a/50583577/115145 and https://stackoverflow.com/a/41649942/115145. – CommonsWare Apr 20 '20 at 20:43

0 Answers0