1

Less than a year ago I wanted to learn Android and I started to make an application. I know java/eclipse long, but not like other of you, as the language in which most have been deepened is C/C++. But I always been a thing I've been missing, and it is the lack in the (language || IDE || Framework) , of not having a preprocessor as the M4 that C/C++ has.

To include similar directives as these.

  • #DEFINE foo
  • #IFDEF foo
  • #IFNDEF foo
  • #ENDIF

So that we avoid some code on the package. Or resources.

  • Do you know any way/s to incorporate this feature in Android with Java or Eclipse or NetBeans or IntelliJ IDEA or Android Studio or plugin?.
  • If you know several, in your opinion, What would be the best?.

Please, that this post does not turn into a war of which is the best solution, there's no accounting for taste.

2 Answers2

0

With new gradle plugin you can use buildConfigField method of BuildType's or Flavor's DSL. It will generate a field in BuildConfig so you can use it later in code.

You can see example here: BuildConfig not getting created correctly (Gradle Android)

Community
  • 1
  • 1
Korniltsev Anatoly
  • 3,676
  • 2
  • 26
  • 37
-1

You have a classic case of the XY problem. Java already gives you plenty of tools to reduce code duplication, use them. C-style #defines are not the solution.

Community
  • 1
  • 1
Tassos Bassoukos
  • 16,017
  • 2
  • 36
  • 40
  • So, what do you suggest? I'm writing an app which I want to generate different versions, but only write 1 code. Please say me the name of this tools or a web that show me how to use them. – Joaquín Luis Monleón Irisarri Apr 05 '14 at 16:09
  • I guess that this is a start: https://developer.android.com/guide/topics/resources/index.html . However, exatly what do you want to change per version? – Tassos Bassoukos Apr 05 '14 at 18:43