0

I have an ant build setup for my Android project, and I've been reading guides and tutorials all over stackoverflow and online, but cannot seem to understand how to make this work. Basically in my code I have a variable, "isDebugVersion" (which will print out logs, and a few other things). When I build with ant, I want that variable in my code to be set to "false". I'm looking around and I cannot find the custom_rules.xml examples even though it's listed in the build.xml file.

So the variable is in com.example.application.Globals, and it's listed as isDebugVersion. Can someone please give me an example for how to manipulate this variable using an ant build script?

RyanInBinary
  • 1,533
  • 3
  • 19
  • 47
  • While this isn't a direct answer to your question have you looked into using the debuggable flag in the Android manifest? [Here](http://stackoverflow.com/questions/4276857/getting-debuggable-value-of-androidmanifest-from-code) is a link to access the value in code. – Jim Baca Nov 15 '12 at 19:27
  • I have, but part of the reason that I'm looking for this is because I'm also going to need to control variables like the "mapKey" used for the MapAPI – RyanInBinary Nov 15 '12 at 19:32

1 Answers1

2

You can a file named custom_rules.xml to the root folder of your project. Inside define any property you want.

Note that what you are trying to achieve could be simpler using BuildConfig.DEBUG. This file is in the gen folder of your project, close to R.java. It is generated during the build and the constant DEBUG will be set to false during debug builds and to true in release.

So if you type ant release, you will get false. With eclipse or ant debug, you will get true.

You could also learn how to use RoboGuice, it has an interesting logging solution.

You can use this constant for all purposes like changing the google map api key from debug to release key. For an example, follow this thread.

Community
  • 1
  • 1
Snicolas
  • 37,840
  • 15
  • 114
  • 173