I’m a newbie to Android and Java–lots of experience with C/C++/C#.
I have in interface that looks like this:
class WellNamedClass {
void greatMethodToCallWhenever() { /*...*/ }
void debugOnlyMethod() { /*...*/ }
}
In the the languages mentioned above, I would either #ifdef the entire debugOnlyMethod method out or #ifdef the implementation out so it simply does nothing, but Java doesn’t have a preprocessor.
I’m totally comfortable with having the code there and checking at run-time whether we are in a debug build, but I can’t even find a way of doing that.
I’ve found suggestions like this one where you create a class with a constant indicating whether debug (or whatever else you want) is enabled. This could work, but then you have to manually change code to get a debug vs. a release build.
Has anyone else solved this problem? Thanks.
I think the method we’re going to use is have a JNI call into our native component that will tell us whether we are running in debug mode. We have to have the native component anyway, and will make a few JNI calls at startup so it’s a relatively simple solution, since C++ has a preprocessor.