0

Our app is distributed from multiple markets and as the developer I need to make different code run for each of those targets, something like:

if (target == ROCK) do A;
else if (target == PAPER) do B; 

and so on, does ADT/Eclipse support these kinds of stuff?

How should I go about doing it?

Ofek Ron
  • 8,354
  • 13
  • 55
  • 103
  • Do you mean as in different version of the sdk or as in different locations/carriers? – Vitor M. Barbosa Jul 30 '13 at 14:02
  • neither, i want to have my own defined targets, is that possible? – Ofek Ron Jul 30 '13 at 14:02
  • [This answer](http://stackoverflow.com/a/4526126/622391) says you can't, but there are other ways. Have a look at [this solution](https://weblogs.java.net/blog/schaefa/archive/2005/01/how_to_do_condi_1.html) which _"[uses] Ant's copy and filter feature to create the source with the different code in it"_. – Simon MᶜKenzie Jun 11 '14 at 02:15

3 Answers3

1

you can set in the res/values folder a parameter (e. g. string in strings.xml) to check for. This string can be parametered with the target (e. g. screensize in res/values-480x800).

Christian
  • 4,596
  • 1
  • 26
  • 33
1

There are two approaches to this, depending on what you want:

  1. Multiple APKs, each with hardcoded options.
  2. A single APK that executes code conditionally.

For approach 1, you can use build flavors in gradle / Android Studio (I don't think ADT supports this). You can basically build multiple versions of a single APK choosing different source files in each. Then, in the Play Store, you can distribute these different files according to your criteria.

For approach 2, you have a few options:

  1. For resources, you can provide different files depending on Language and Region (or MCC).
  2. For code, getResources().getConfiguration().locale.getCountry() to get the country of the device or TelephonyManager.getNetworkOperator() for the MCC
matiash
  • 54,791
  • 16
  • 125
  • 154
0

once I had similar problem for J2ME development, I just developed preprocessor, you can try to use it for Android projects

Igor Maznitsa
  • 833
  • 7
  • 12