Reputation: 1861
What is the correct way to add debugging code to an Android app, such that the debugging code will only execute in test builds, and not in signed builds published on Google Play?
For example, in iOS apps I simply write:
#ifdef DEBUG
// put debug code here
#endif
Searching for solutions has led me to several different approaches, each one followed by a string of complaints about how it doesn't work as expected. But many of these solutions are quite old. Surely Google has fixed whatever problems existed here and there is a straightforward always-works solution for this now?
I'm building with Android Studio, but I'm hoping that the solution is not IDE-specific.
Thanks, Frank
Upvotes: 0
Views: 27
Reputation: 6142
You should add the code that you want to execute only in debug mode inside the following:
if (BuildConfig.DEBUG) {
// THIS WILL BE EXECUTED ONLY IN DEBUG MODE
}
Upvotes: 2