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?
You can a file named
custom_rules.xmlto 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 toR.java. It is generated during the build and the constantDEBUGwill be set tofalseduring debug builds and totruein release.So if you type
ant release, you will getfalse. With eclipse orant debug, you will gettrue.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.