Detecting build configuration (debug or release) in ant script

I have an ant script that does what it needs to do, but I need to set several property values ​​based on whether I am running a run or debugging. How to do it?

If that matters, my ant script runs some custom utility tasks before completing the Android build.


To answer my own question:

The properties to look for are "build.mode.release" and "build.mode.debug", however there is caveat ... if your manifest has debuggable = "true", the REVERTS system for debug mode with a little "short" ( IMO)

  • build.mode.release is NOT installed ,
  • build.mode.debug is ALSO not installed
  • Debug signing is disabled (you must specify a keystore, alias, and password).

Note. . This only applies to Android strings.

+8
java android build ant configuration
source share
4 answers

The reason for the “disclaimer” is actually documented in the Android project main_rules.xml ( $ANDROID_SDK_ROOT/tools/ant/main_rules.xml ):

 <target name="-set-release-mode"> <!-- release mode is only valid if the manifest does not explicitly set debuggable to true. default is false. We actually store build.packaging.debug, not build.release --> <xpath input="AndroidManifest.xml" expression="/manifest/application/@android:debuggable" output="build.packaging.debug" default="false"/> ... </target> 

So what you want to check out is build.mode.debug (executed via ant debug ), build.mode.release (when @debuggable=false and executed using ant release ) and finally to satisfy your caveat: build.packaging.debug (when @debuggable=true and executed using ant release )


Here is an example that would automatically compile:

 <target name="-my-debug-precompile" if="build.mode.debug"> <!-- This is executed for any "debug" build ("ant debug") --> </target> <target name="-my-release-precompile" unless="build.mode.debug"> <!-- This is executed for any non-"debug" build (eg, "ant release", regardless of the @debuggable attribute in AndroidManifest.xml) --> </target> <!-- This is called automatically by Android ant tasks, and delegates the task to one of the above two targets: --> <target name="-pre-compile" depends="-my-debug-precompile,-my-release-precompile" /> 
+8
source share

As an update for Joe's answer, it looks like at least version 22.3 of Android Tools, the build.mode.debug property no longer exists, but you can use build.is.packaging.debug to distinguish between debugging and release

+3
source share

ant -D<prop-name>=<value> set the property to ant

+1
source share

final version for ant debug and jni module:
1. in custom_rules.xml set the debug mode to "BUILDMODE"

 <?xml version="1.0" encoding="UTF-8"?> <project> <property name="out.library.jar.file" location="bin/classes.jar" /> <target name="-pre-compile"> <exec executable="ndk-build"> <arg value="BUILDMODE=${build.is.packaging.debug}" /> </exec> </target> </project> 
  1. jni / Android.mk, add the following:

ifeq ($ (BUILDMODE), true)
LOCAL_CFLAGS=-DDEBUG
endif

0
source share

All Articles