-1

I have a .property file which at the moment is like this: com.myapp.token = myGenericString

What I would like to have is to have different values for different build variants. Something like:

if (BuildConfig == Release) {
    com.myapp.token = myReleaseString
} else {
    com.myapp.token = myOtherString
}

I'm new to Android so I'm not even sure it's possible. Any suggestions? Thanks!

ace_ventura
  • 468
  • 1
  • 4
  • 14

1 Answers1

0

.properties do not support that, but you can do this with string resources, for example:

app/src/main/res/values/strings.xml and app/src/debug/res/values/strings.xml

one does not even have to differ in code then, the resource location is internally being changed.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • It looks like I only have one `strings.xml` file at the moment located in `app/src/main/res/values/` – ace_ventura Sep 18 '18 at 18:40
  • @carlodonz when you create a `debug` directory beside the `main` directory (alias "source set"), these files will be overloaded in debug mode. this also works for other resources and classes, which shall only be available in debug mode. for the `Manifest.xml` this works, too. – Martin Zeitler Sep 18 '18 at 18:46
  • the problem is that I'm using an external framework and in the installation guide they say to use the `.properties` file for it. But I would like to have different values for it based on release or anything else – ace_ventura Sep 18 '18 at 18:58
  • @carlodonz I've already explained this in my answer...and while you don't mind to tell which framework it is, I can only tell that this approach will lead nowhere - while your example can be done with debug resources, without having to tell the framework which version of the file to use. – Martin Zeitler Sep 18 '18 at 19:08
  • sure I can tell you, it's NewRelic for Android, specifically step 5. "ProGuard only: Create a `newrelic.properties` file. In your project’s root directory (projectname/app), add a `newrelic.properties` file containing this setting: `com.newrelic.application_token=your_token` – ace_ventura Sep 18 '18 at 19:19
  • @carlodonz since the pre-defined location, where the file is being expected (no matter what, unless one could change that), is `app/newrelic.properties` - you could only build with two package names, using `applicationIdSuffix '.debug'` for `buildType` `debug` - and possibly also add these two package-names on the New Relic console. this at least works for me with Crashlytics. – Martin Zeitler Sep 18 '18 at 19:26
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/180296/discussion-between-carlodonz-and-martin-zeitler). – ace_ventura Sep 18 '18 at 19:42