-1

We are developing an Android app that will target different markets (countries).

The scope of this question is to answer 2 things:

  1. How to easily configure and switch a "global" parameter (e.g. the country which this "variant" of this app will target) within the app that will be used across the whole code base, e.g. a backend API endpoint. In other words, there are 20+ backend APIs depending on the variant being released.
  2. How to easily build these 20+ different apps, changing the package name for each and taking into account the unique global parameter above while building each.
Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118
  • If at all possible, for the sake of release management, just auto detect the country the user is in. Discussed [here](http://stackoverflow.com/questions/11872483/reliable-method-to-get-the-country-the-user-is-in) and [here](http://stackoverflow.com/questions/11872483/reliable-method-to-get-the-country-the-user-is-in) – selbie Jan 14 '17 at 11:12
  • No, we are not interested in detecting the user's location at runtime. We want to build customized applications for the different markets. Based on the build "variant" the app will be completely different and will behave differently. – Dzhuneyt Jan 14 '17 at 11:45

1 Answers1

1

How to easily configure and switch a "global" parameter (e.g. the country which this "variant" of this app will target) within the app that will be used across the whole code base, e.g. a backend API endpoint. In other words, there are 20+ backend APIs depending on the variant being released.

Set up a product flavor per country. Use buildConfigField to add a field (or fields) to BuildConfig with the details of your backend endpoint.

How to easily build these 20+ different apps, changing the package name for each and taking into account the unique global parameter above while building each.

Run gradle assembleRelease to assemble all 20+ APKs. Or, run gradle assembleFlavorRelease to assemble the one APK with the flavor named flavor.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491