1 <?xml version="1.0" encoding="UTF-8"?> 2 <project name="android_rules" default="debug"> 3 4 <!-- 5 This build file is imported by the project build file. It contains 6 all the targets and tasks necessary to build Android projects, be they 7 regular projects, library projects, or test projects. 8 9 At the beginning of the file is a list of properties that can be overridden 10 by adding them to your ant.properties (properties are immutable, so their 11 first definition sticks and is never changed). 12 13 Follows: 14 - custom task definitions, 15 - more properties (do not override those unless the whole build system is modified). 16 - macros used throughout the build, 17 - base build targets, 18 - debug-specific build targets, 19 - release-specific build targets, 20 - instrument-specific build targets, 21 - test project-specific build targets, 22 - install targets, 23 - help target 24 --> 25 26 <!-- ******************************************************* --> 27 <!-- **************** Overridable Properties *************** --> 28 <!-- ******************************************************* --> 29 30 <!-- You can override these values in your build.xml or ant.properties. 31 Overriding any other properties may result in broken build. --> 32 33 <!-- Tells adb which device to target. You can change this from the command line 34 by invoking "ant -Dadb.device.arg=-d" for device "ant -Dadb.device.arg=-e" for 35 the emulator. --> 36 <property name="adb.device.arg" value="" /> 37 38 <!-- fileset exclude patterns (space separated) to prevent 39 files inside src/ from being packaged. --> 40 <property name="android.package.excludes" value="" /> 41 42 <!-- set some properties used for filtering/override. If those weren't defined 43 before, then this will create them with empty values, which are then ignored 44 by the custom tasks receiving them. --> 45 <property name="version.code" value="" /> 46 <property name="version.name" value="" /> 47 <property name="aapt.resource.filter" value="" /> 48 49 <!-- compilation options --> 50 <property name="java.encoding" value="UTF-8" /> 51 <property name="java.target" value="1.5" /> 52 <property name="java.source" value="1.5" /> 53 <property name="java.compilerargs" value="" /> 54 55 <!-- Renderscript options --> 56 <property name="renderscript.debug.opt.level" value="O0" /> 57 <property name="renderscript.release.opt.level" value="O3" /> 58 59 <!-- manifest merger default value --> 60 <property name="manifestmerger.enabled" value="false" /> 61 62 <!-- instrumentation options --> 63 <property name="emma.filter" value="" /> 64 65 <!-- Verbosity --> 66 <property name="verbose" value="false" /> 67 68 <!-- ******************************************************* --> 69 <!-- ********************* Custom Tasks ******************** --> 70 <!-- ******************************************************* --> 71 72 <!-- jar file from where the tasks are loaded --> 73 <path id="android.antlibs"> 74 <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" /> 75 </path> 76 77 <!-- Custom tasks --> 78 <taskdef resource="anttasks.properties" classpathref="android.antlibs" /> 79 80 <!-- Emma configuration --> 81 <property name="emma.dir" value="${sdk.dir}/tools/lib" /> 82 <path id="emma.lib"> 83 <pathelement location="${emma.dir}/emma.jar" /> 84 <pathelement location="${emma.dir}/emma_ant.jar" /> 85 </path> 86 <taskdef resource="emma_ant.properties" classpathref="emma.lib" /> 87 <!-- End of emma configuration --> 88 89 90 <!-- ******************************************************* --> 91 <!-- ******************* Other Properties ****************** --> 92 <!-- ******************************************************* --> 93 <!-- overriding these properties may break the build 94 unless the whole file is updated --> 95 96 <!-- Input directories --> 97 <property name="source.dir" value="src" /> 98 <property name="source.absolute.dir" location="${source.dir}" /> 99 <property name="gen.absolute.dir" location="gen" /> 100 <property name="resource.absolute.dir" location="res" /> 101 <property name="asset.dir" value="assets" /> 102 <property name="asset.absolute.dir" location="${asset.dir}" /> 103 <property name="jar.libs.dir" value="libs" /> 104 <property name="jar.libs.absolute.dir" location="${jar.libs.dir}" /> 105 <property name="native.libs.absolute.dir" location="libs" /> 106 107 <property name="manifest.file" value="AndroidManifest.xml" /> 108 <property name="manifest.abs.file" location="${manifest.file}" /> 109 110 <!-- Output directories --> 111 <property name="out.dir" value="bin" /> 112 <property name="out.absolute.dir" location="${out.dir}" /> 113 <property name="out.classes.absolute.dir" location="${out.dir}/classes" /> 114 <property name="out.res.absolute.dir" location="${out.dir}/res" /> 115 <property name="out.manifest.abs.file" location="${out.dir}/AndroidManifest.xml" /> 116 117 <!-- tools location --> 118 <property name="android.tools.dir" location="${sdk.dir}/tools" /> 119 <property name="android.platform.tools.dir" location="${sdk.dir}/platform-tools" /> 120 <condition property="exe" value=".exe" else=""><os family="windows" /></condition> 121 <condition property="bat" value=".bat" else=""><os family="windows" /></condition> 122 <property name="adb" location="${android.platform.tools.dir}/adb${exe}" /> 123 <property name="zipalign" location="${android.tools.dir}/zipalign${exe}" /> 124 <property name="aidl" location="${android.platform.tools.dir}/aidl${exe}" /> 125 <property name="aapt" location="${android.platform.tools.dir}/aapt${exe}" /> 126 <property name="dx" location="${android.platform.tools.dir}/dx${bat}" /> 127 <property name="renderscript" location="${android.platform.tools.dir}/llvm-rs-cc${exe}"/> 128 129 <!-- Renderscript include Path --> 130 <path id="android.renderscript.include.path"> 131 <pathelement location="${android.platform.tools.dir}/renderscript/include" /> 132 <pathelement location="${android.platform.tools.dir}/renderscript/clang-include" /> 133 </path> 134 135 <!-- Intermediate files --> 136 <property name="dex.file.name" value="classes.dex" /> 137 <property name="intermediate.dex.file" location="${out.absolute.dir}/${dex.file.name}" /> 138 <property name="resource.package.file.name" value="${ant.project.name}.ap_" /> 139 140 <!-- Build property file --> 141 <property name="out.build.prop.file" location="${out.absolute.dir}/build.prop" /> 142 143 144 <!-- This is needed by emma as it uses multilevel verbosity instead of simple 'true' or 'false' 145 The property 'verbosity' is not user configurable and depends exclusively on 'verbose' 146 value.--> 147 <condition property="verbosity" value="verbose" else="quiet"> 148 <istrue value="${verbose}" /> 149 </condition> 150 151 <!-- properties for signing in release mode --> 152 <condition property="has.keystore"> 153 <and> 154 <isset property="key.store" /> 155 <length string="${key.store}" when="greater" length="0" /> 156 <isset property="key.alias" /> 157 </and> 158 </condition> 159 <condition property="has.password"> 160 <and> 161 <isset property="has.keystore" /> 162 <isset property="key.store.password" /> 163 <isset property="key.alias.password" /> 164 </and> 165 </condition> 166 167 <!-- properties for packaging --> 168 <property name="build.packaging.nocrunch" value="true" /> 169 170 <!-- whether we need to fork javac. 171 This is only needed on Windows when running Java < 7 --> 172 <condition else="false" property="need.javac.fork"> 173 <and> 174 <matches pattern="1\.[56]" string="${java.specification.version}"/> 175 <not> 176 <os family="unix"/> 177 </not> 178 </and> 179 </condition> 180 181 <!-- ******************************************************* --> 182 <!-- ************************ Macros *********************** --> 183 <!-- ******************************************************* --> 184 185 <!-- macro to do a task on if project.is.library is false. 186 elseText attribute is displayed otherwise --> 187 <macrodef name="do-only-if-not-library"> 188 <attribute name="elseText" /> 189 <element name="task-to-do" implicit="yes" /> 190 <sequential> 191 <if condition="${project.is.library}"> 192 <else> 193 <task-to-do /> 194 </else> 195 <then> 196 <echo level="info">@{elseText}</echo> 197 </then> 198 </if> 199 </sequential> 200 </macrodef> 201 202 <!-- macro to do a task on if manifest.hasCode is true. 203 elseText attribute is displayed otherwise --> 204 <macrodef name="do-only-if-manifest-hasCode"> 205 <attribute name="elseText" default=""/> 206 <element name="task-to-do" implicit="yes" /> 207 <sequential> 208 <if condition="${manifest.hasCode}"> 209 <then> 210 <task-to-do /> 211 </then> 212 <else> 213 <if> 214 <condition> 215 <length string="@{elseText}" trim="true" when="greater" length="0" /> 216 </condition> 217 <then> 218 <echo level="info">@{elseText}</echo> 219 </then> 220 </if> 221 </else> 222 </if> 223 </sequential> 224 </macrodef> 225 226 227 <!-- Configurable macro, which allows to pass as parameters output directory, 228 output dex filename and external libraries to dex (optional) --> 229 <macrodef name="dex-helper"> 230 <element name="external-libs" optional="yes" /> 231 <attribute name="nolocals" default="false" /> 232 <sequential> 233 <!-- sets the primary input for dex. If a pre-dex task sets it to 234 something else this has no effect --> 235 <property name="out.dex.input.absolute.dir" value="${out.classes.absolute.dir}" /> 236 237 <!-- set the secondary dx input: the project (and library) jar files 238 If a pre-dex task sets it to something else this has no effect --> 239 <if> 240 <condition> 241 <isreference refid="out.dex.jar.input.ref" /> 242 </condition> 243 <else> 244 <path id="out.dex.jar.input.ref"> 245 <path refid="project.all.jars.path" /> 246 </path> 247 </else> 248 </if> 249 250 <dex executable="${dx}" 251 output="${intermediate.dex.file}" 252 nolocals="@{nolocals}" 253 verbose="${verbose}"> 254 <path path="${out.dex.input.absolute.dir}"/> 255 <path refid="out.dex.jar.input.ref" /> 256 <external-libs /> 257 </dex> 258 </sequential> 259 </macrodef> 260 261 <!-- This is macro that enable passing variable list of external jar files to ApkBuilder 262 Example of use: 263 <package-helper> 264 <extra-jars> 265 <jarfolder path="my_jars" /> 266 <jarfile path="foo/bar.jar" /> 267 <jarfolder path="your_jars" /> 268 </extra-jars> 269 </package-helper> --> 270 <macrodef name="package-helper"> 271 <element name="extra-jars" optional="yes" /> 272 <sequential> 273 <apkbuilder 274 outfolder="${out.absolute.dir}" 275 resourcefile="${resource.package.file.name}" 276 apkfilepath="${out.packaged.file}" 277 debugpackaging="${build.is.packaging.debug}" 278 debugsigning="${build.is.signing.debug}" 279 verbose="${verbose}" 280 hascode="${manifest.hasCode}" 281 previousBuildType="${build.last.is.packaging.debug}/${build.last.is.signing.debug}" 282 buildType="${build.is.packaging.debug}/${build.is.signing.debug}"> 283 <dex path="${intermediate.dex.file}"/> 284 <sourcefolder path="${source.absolute.dir}"/> 285 <jarfile refid="project.all.jars.path" /> 286 <nativefolder path="${native.libs.absolute.dir}" /> 287 <nativefolder refid="project.library.native.folder.path" /> 288 <extra-jars/> 289 </apkbuilder> 290 </sequential> 291 </macrodef> 292 293 <!-- This is macro which zipaligns in.package and outputs it to out.package. Used by targets 294 debug, -debug-with-emma and release.--> 295 <macrodef name="zipalign-helper"> 296 <attribute name="in.package" /> 297 <attribute name="out.package" /> 298 <sequential> 299 <zipalign 300 executable="${zipalign}" 301 input="@{in.package}" 302 output="@{out.package}" 303 verbose="${verbose}" /> 304 </sequential> 305 </macrodef> 306 307 <macrodef name="run-tests-helper"> 308 <attribute name="emma.enabled" default="false" /> 309 <element name="extra-instrument-args" optional="yes" /> 310 <sequential> 311 <echo level="info">Running tests ...</echo> 312 <exec executable="${adb}" failonerror="true"> 313 <arg line="${adb.device.arg}" /> 314 <arg value="shell" /> 315 <arg value="am" /> 316 <arg value="instrument" /> 317 <arg value="-w" /> 318 <arg value="-e" /> 319 <arg value="coverage" /> 320 <arg value="@{emma.enabled}" /> 321 <extra-instrument-args /> 322 <arg value="${project.app.package}/${test.runner}" /> 323 </exec> 324 </sequential> 325 </macrodef> 326 327 <macrodef name="record-build-key"> 328 <attribute name="key" default="false" /> 329 <attribute name="value" default="false" /> 330 <sequential> 331 <propertyfile file="${out.build.prop.file}" comment="Last build type"> 332 <entry key="@{key}" value="@{value}"/> 333 </propertyfile> 334 </sequential> 335 </macrodef> 336 337 <macrodef name="record-build-info"> 338 <sequential> 339 <record-build-key key="build.last.target" value="${build.target}" /> 340 <record-build-key key="build.last.is.instrumented" value="${build.is.instrumented}" /> 341 <record-build-key key="build.last.is.packaging.debug" value="${build.is.packaging.debug}" /> 342 <record-build-key key="build.last.is.signing.debug" value="${build.is.signing.debug}" /> 343 </sequential> 344 </macrodef> 345 346 <macrodef name="uninstall-helper"> 347 <attribute name="app.package" default="false" /> 348 <sequential> 349 <echo level="info">Uninstalling @{app.package} from the default emulator or device...</echo> 350 <exec executable="${adb}" failonerror="true"> 351 <arg line="${adb.device.arg}" /> 352 <arg value="uninstall" /> 353 <arg value="@{app.package}" /> 354 </exec> 355 </sequential> 356 </macrodef> 357 358 <!-- ******************************************************* --> 359 <!-- ******************** Build Targets ******************** --> 360 <!-- ******************************************************* --> 361 362 <!-- Basic Ant + SDK check --> 363 <target name="-check-env"> 364 <checkenv /> 365 </target> 366 367 <!-- target to disable building dependencies --> 368 <target name="nodeps"> 369 <property name="dont.do.deps" value="true" /> 370 </target> 371 372 <!-- generic setup --> 373 <target name="-setup" depends="-check-env"> 374 <echo level="info">Project Name: ${ant.project.name}</echo> 375 <gettype projectTypeOut="project.type" /> 376 377 <!-- sets a few boolean based on project.type 378 to make the if task easier --> 379 <condition property="project.is.library" value="true" else="false"> 380 <equals arg1="${project.type}" arg2="library" /> 381 </condition> 382 <condition property="project.is.test" value="true" else="false"> 383 <equals arg1="${project.type}" arg2="test" /> 384 </condition> 385 <condition property="project.is.testapp" value="true" else="false"> 386 <equals arg1="${project.type}" arg2="test-app" /> 387 </condition> 388 389 <!-- If a test project, resolve absolute path to tested project. --> 390 <if condition="${project.is.test}"> 391 <then> 392 <property name="tested.project.absolute.dir" location="${tested.project.dir}" /> 393 </then> 394 </if> 395 396 <!-- If the "debug" build type changed, clear out the compiled code. 397 This is to make sure the new BuildConfig.DEBUG value is picked up 398 as javac can't deal with this type of change in its dependency computation. --> 399 <if> 400 <condition> 401 <and> 402 <length string="${build.last.is.packaging.debug}" trim="true" when="greater" length="0" /> 403 <not><equals 404 arg1="${build.is.packaging.debug}" 405 arg2="${build.last.is.packaging.debug}" /></not> 406 </and> 407 </condition> 408 <then> 409 <echo level="info">Switching between debug and non debug build: Deleting previous compilation output...</echo> 410 <delete dir="${out.classes.absolute.dir}" verbose="${verbose}" /> 411 </then> 412 <else> 413 <!-- Else, we may still need to clean the code, for another reason. 414 special case for instrumented: if the previous build was 415 instrumented but not this one, clear out the compiled code --> 416 <if> 417 <condition> 418 <and> 419 <istrue value="${build.last.is.instrumented}" /> 420 <isfalse value="${build.is.instrumented}" /> 421 </and> 422 </condition> 423 <then> 424 <echo level="info">Switching from instrumented to non-instrumented build: Deleting previous compilation output...</echo> 425 <delete dir="${out.classes.absolute.dir}" verbose="${verbose}" /> 426 </then> 427 </if> 428 </else> 429 </if> 430 431 432 <!-- get the project manifest package --> 433 <xpath input="${manifest.abs.file}" 434 expression="/manifest/@package" output="project.app.package" /> 435 436 </target> 437 438 <!-- empty default pre-clean target. Create a similar target in 439 your build.xml and it'll be called instead of this one. --> 440 <target name="-pre-clean"/> 441 442 <!-- clean target --> 443 <target name="clean" depends="-setup, -pre-clean" 444 description="Removes output files created by other targets."> 445 <delete dir="${out.absolute.dir}" verbose="${verbose}" /> 446 <delete dir="${gen.absolute.dir}" verbose="${verbose}" /> 447 448 <!-- if we know about a tested project or libraries, we clean them too. --> 449 <if condition="${project.is.test}"> 450 <then> 451 <property name="tested.project.absolute.dir" location="${tested.project.dir}" /> 452 <subant failonerror="true"> 453 <fileset dir="${tested.project.absolute.dir}" includes="build.xml" /> 454 <target name="clean" /> 455 </subant> 456 </then> 457 </if> 458 459 <!-- get all the libraries --> 460 <if> 461 <condition><not><isset property="dont.do.deps" /></not></condition> 462 <then> 463 <getlibs libraryFolderPathOut="project.library.folder.path" /> 464 <if> 465 <condition> 466 <isreference refid="project.library.folder.path" /> 467 </condition> 468 <then> 469 <!-- clean the libraries with nodeps since we already 470 know about all the libraries even the indirect one --> 471 <subant 472 buildpathref="project.library.folder.path" 473 antfile="build.xml" 474 failonerror="true"> 475 <target name="nodeps" /> 476 <target name="clean" /> 477 </subant> 478 </then> 479 </if> 480 </then> 481 </if> 482 </target> 483 484 <!-- Pre build setup --> 485 <target name="-build-setup" depends="-setup"> 486 487 <!-- read the previous build mode --> 488 <property file="${out.build.prop.file}" /> 489 <!-- if empty the props won't be set, meaning it's a new build. 490 To force a build, set the prop to empty values. --> 491 <property name="build.last.target" value="" /> 492 <property name="build.last.is.instrumented" value="" /> 493 <property name="build.last.is.packaging.debug" value="" /> 494 <property name="build.last.is.signing.debug" value="" /> 495 496 <echo level="info">Resolving Build Target for ${ant.project.name}...</echo> 497 <!-- load project properties, resolve Android target, library dependencies 498 and set some properties with the results. 499 All property names are passed as parameters ending in -Out --> 500 <gettarget 501 androidJarFileOut="project.target.android.jar" 502 androidAidlFileOut="project.target.framework.aidl" 503 bootClassPathOut="project.target.class.path" 504 targetApiOut="project.target.apilevel" 505 minSdkVersionOut="project.minSdkVersion" /> 506 507 <!-- Value of the hasCode attribute (Application node) extracted from manifest file --> 508 <xpath input="${manifest.abs.file}" expression="/manifest/application/@android:hasCode" 509 output="manifest.hasCode" default="true"/> 510 511 <echo level="info">----------</echo> 512 <echo level="info">Creating output directories if needed...</echo> 513 <mkdir dir="${resource.absolute.dir}" /> 514 <mkdir dir="${jar.libs.absolute.dir}" /> 515 <mkdir dir="${out.absolute.dir}" /> 516 <mkdir dir="${out.res.absolute.dir}" /> 517 <do-only-if-manifest-hasCode> 518 <mkdir dir="${gen.absolute.dir}" /> 519 <mkdir dir="${out.classes.absolute.dir}" /> 520 </do-only-if-manifest-hasCode> 521 522 <echo level="info">----------</echo> 523 <echo level="info">Resolving Dependencies for ${ant.project.name}...</echo> 524 <dependency 525 libraryFolderPathOut="project.library.folder.path" 526 libraryPackagesOut="project.library.packages" 527 libraryManifestFilePathOut="project.library.manifest.file.path" 528 libraryResFolderPathOut="project.library.res.folder.path" 529 libraryNativeFolderPathOut="project.library.native.folder.path" 530 jarLibraryPathOut="project.all.jars.path" 531 targetApi="${project.target.apilevel}" 532 verbose="${verbose}" /> 533 534 <!-- compile the libraries if any --> 535 <if> 536 <condition> 537 <and> 538 <isreference refid="project.library.folder.path" /> 539 <not><isset property="dont.do.deps" /></not> 540 </and> 541 </condition> 542 <then> 543 <!-- figure out which target must be used to build the library projects. 544 If emma is enabled, then use 'instrument' otherwise, use 'debug' --> 545 <condition property="project.libraries.target" value="instrument" else="${build.target}"> 546 <istrue value="${build.is.instrumented}" /> 547 </condition> 548 549 <echo level="info">----------</echo> 550 <echo level="info">Building Libraries with '${project.libraries.target}'...</echo> 551 552 <!-- no need to build the deps as we have already 553 the full list of libraries --> 554 <subant failonerror="true" 555 buildpathref="project.library.folder.path" 556 antfile="build.xml"> 557 <target name="nodeps" /> 558 <target name="${project.libraries.target}" /> 559 </subant> 560 </then> 561 </if> 562 563 <!-- compile the main project if this is a test project --> 564 <if condition="${project.is.test}"> 565 <then> 566 <!-- figure out which target must be used to build the tested project. 567 If emma is enabled, then use 'instrument' otherwise, use 'debug' --> 568 <condition property="tested.project.target" value="instrument" else="debug"> 569 <isset property="emma.enabled" /> 570 </condition> 571 572 <echo level="info">----------</echo> 573 <echo level="info">Building tested project at ${tested.project.absolute.dir} with '${tested.project.target}'...</echo> 574 <subant target="${tested.project.target}" failonerror="true"> 575 <fileset dir="${tested.project.absolute.dir}" includes="build.xml" /> 576 </subant> 577 578 <!-- get the tested project full classpath to be able to build 579 the test project --> 580 <testedprojectclasspath 581 projectLocation="${tested.project.absolute.dir}" 582 projectClassPathOut="tested.project.classpath"/> 583 </then> 584 <else> 585 <!-- no tested project, make an empty Path object so that javac doesn't 586 complain --> 587 <path id="tested.project.classpath" /> 588 </else> 589 </if> 590 </target> 591 592 <!-- empty default pre-build target. Create a similar target in 593 your build.xml and it'll be called instead of this one. --> 594 <target name="-pre-build"/> 595 596 <!-- Code Generation: compile resources (aapt -> R.java), aidl, renderscript --> 597 <target name="-code-gen"> 598 <!-- always merge manifest --> 599 <mergemanifest 600 appManifest="${manifest.abs.file}" 601 outManifest="${out.manifest.abs.file}" 602 enabled="${manifestmerger.enabled}"> 603 <library refid="project.library.manifest.file.path" /> 604 </mergemanifest> 605 606 <do-only-if-manifest-hasCode 607 elseText="hasCode = false. Skipping aidl/renderscript/R.java"> 608 <echo level="info">Handling aidl files...</echo> 609 <aidl executable="${aidl}" framework="${project.target.framework.aidl}" 610 genFolder="${gen.absolute.dir}"> 611 <source path="${source.absolute.dir}"/> 612 </aidl> 613 614 <!-- renderscript generates resources so it must be called before aapt --> 615 <echo level="info">----------</echo> 616 <echo level="info">Handling RenderScript files...</echo> 617 <renderscript executable="${renderscript}" 618 includePath="${android.renderscript.include.path}" 619 genFolder="${gen.absolute.dir}" 620 resFolder="${out.res.absolute.dir}/raw" 621 targetApi="${project.minSdkVersion}" 622 optLevel="${renderscript.opt.level}" 623 buildType="${build.is.packaging.debug}" 624 previousBuildType="${build.last.is.packaging.debug}"> 625 <source path="${source.absolute.dir}"/> 626 </renderscript> 627 628 <echo level="info">----------</echo> 629 <echo level="info">Handling Resources...</echo> 630 <aapt executable="${aapt}" 631 command="package" 632 verbose="${verbose}" 633 manifest="${out.manifest.abs.file}" 634 androidjar="${project.target.android.jar}" 635 rfolder="${gen.absolute.dir}" 636 nonConstantId="${android.library}" 637 libraryResFolderPathRefid="project.library.res.folder.path" 638 libraryPackagesRefid="project.library.packages"> 639 <res path="${out.res.absolute.dir}" /> 640 <res path="${resource.absolute.dir}" /> 641 </aapt> 642 643 <echo level="info">----------</echo> 644 <echo level="info">Handling BuildConfig class...</echo> 645 <buildconfig 646 genFolder="${gen.absolute.dir}" 647 package="${project.app.package}" 648 buildType="${build.is.packaging.debug}" 649 previousBuildType="${build.last.is.packaging.debug}"/> 650 651 </do-only-if-manifest-hasCode> 652 </target> 653 654 <!-- empty default pre-compile target. Create a similar target in 655 your build.xml and it'll be called instead of this one. --> 656 <target name="-pre-compile"/> 657 658 <!-- Compiles this project's .java files into .class files. --> 659 <target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile"> 660 <do-only-if-manifest-hasCode elseText="hasCode = false. Skipping..."> 661 <!-- merge the project's own classpath and the tested project's classpath --> 662 <path id="project.javac.classpath"> 663 <path refid="project.all.jars.path" /> 664 <path refid="tested.project.classpath" /> 665 </path> 666 <javac encoding="${java.encoding}" 667 source="${java.source}" target="${java.target}" 668 debug="true" extdirs="" includeantruntime="false" 669 destdir="${out.classes.absolute.dir}" 670 bootclasspathref="project.target.class.path" 671 verbose="${verbose}" 672 classpathref="project.javac.classpath" 673 fork="${need.javac.fork}"> 674 <src path="${source.absolute.dir}" /> 675 <src path="${gen.absolute.dir}" /> 676 <compilerarg line="${java.compilerargs}" /> 677 </javac> 678 679 <!-- if the project is instrumented, intrument the classes --> 680 <if condition="${build.is.instrumented}"> 681 <then> 682 <echo level="info">Instrumenting classes from ${out.absolute.dir}/classes...</echo> 683 684 <!-- build the filter to remove R, Manifest, BuildConfig --> 685 <getemmafilter 686 appPackage="${project.app.package}" 687 libraryPackagesRefId="project.library.packages" 688 filterOut="emma.default.filter"/> 689 690 <!-- It only instruments class files, not any external libs --> 691 <emma enabled="true"> 692 <instr verbosity="${verbosity}" 693 mode="overwrite" 694 instrpath="${out.absolute.dir}/classes" 695 outdir="${out.absolute.dir}/classes"> 696 <filter excludes="${emma.default.filter}" /> 697 <filter value="${emma.filter}" /> 698 </instr> 699 </emma> 700 </then> 701 </if> 702 703 <!-- if the project is a library then we generate a jar file --> 704 <if condition="${project.is.library}"> 705 <then> 706 <echo level="info">Creating library output jar file...</echo> 707 <property name="out.library.jar.file" location="${out.absolute.dir}/classes.jar" /> 708 <if> 709 <condition> 710 <length string="${android.package.excludes}" trim="true" when="greater" length="0" /> 711 </condition> 712 <then> 713 <echo level="info">Custom jar packaging exclusion: ${android.package.excludes}</echo> 714 </then> 715 </if> 716 717 <propertybyreplace name="project.app.package.path" input="${project.app.package}" replace="." with="/" /> 718 719 <jar destfile="${out.library.jar.file}"> 720 <fileset dir="${out.classes.absolute.dir}" 721 includes="**/*.class" 722 excludes="${project.app.package.path}/R.class ${project.app.package.path}/R$*.class ${project.app.package.path}/Manifest.class ${project.app.package.path}/Manifest$*.class ${project.app.package.path}/BuildConfig.class"/> 723 <fileset dir="${source.absolute.dir}" excludes="**/*.java ${android.package.excludes}" /> 724 </jar> 725 </then> 726 </if> 727 728 </do-only-if-manifest-hasCode> 729 </target> 730 731 <!-- empty default post-compile target. Create a similar target in 732 your build.xml and it'll be called instead of this one. --> 733 <target name="-post-compile"/> 734 735 <!-- Obfuscate target 736 This is only active in release builds when proguard.config is defined 737 in default.properties. 738 739 To replace Proguard with a different obfuscation engine: 740 Override the following targets in your build.xml, before the call to <setup> 741 -release-obfuscation-check 742 Check whether obfuscation should happen, and put the result in a property. 743 -debug-obfuscation-check 744 Obfuscation should not happen. Set the same property to false. 745 -obfuscate 746 check if the property set in -debug/release-obfuscation-check is set to true. 747 If true: 748 Perform obfuscation 749 Set property out.dex.input.absolute.dir to be the output of the obfuscation 750 --> 751 <target name="-obfuscate"> 752 <if condition="${proguard.enabled}"> 753 <then> 754 <property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard" /> 755 <property name="preobfuscate.jar.file" value="${obfuscate.absolute.dir}/original.jar" /> 756 <property name="obfuscated.jar.file" value="${obfuscate.absolute.dir}/obfuscated.jar" /> 757 <!-- input for dex will be proguard's output --> 758 <property name="out.dex.input.absolute.dir" value="${obfuscated.jar.file}" /> 759 760 <!-- Add Proguard Tasks --> 761 <property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar" /> 762 <taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" /> 763 764 <!-- Set the android classpath Path object into a single property. It'll be 765 all the jar files separated by a platform path-separator. 766 Each path must be quoted if it contains spaces. 767 --> 768 <pathconvert property="project.target.classpath.value" refid="project.target.class.path"> 769 <firstmatchmapper> 770 <regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/> 771 <identitymapper/> 772 </firstmatchmapper> 773 </pathconvert> 774 775 <!-- Build a path object with all the jar files that must be obfuscated. 776 This include the project compiled source code and any 3rd party jar 777 files. --> 778 <path id="project.all.classes.path"> 779 <pathelement location="${preobfuscate.jar.file}" /> 780 <path refid="project.all.jars.path" /> 781 </path> 782 <!-- Set the project jar files Path object into a single property. It'll be 783 all the jar files separated by a platform path-separator. 784 Each path must be quoted if it contains spaces. 785 --> 786 <pathconvert property="project.all.classes.value" refid="project.all.classes.path"> 787 <firstmatchmapper> 788 <regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/> 789 <identitymapper/> 790 </firstmatchmapper> 791 </pathconvert> 792 793 <!-- Turn the path property ${proguard.config} from an A:B:C property 794 into a series of includes: -include A -include B -include C 795 suitable for processing by the ProGuard task. Note - this does 796 not include the leading '-include "' or the closing '"'; those 797 are added under the <proguard> call below. 798 --> 799 <path id="proguard.configpath"> 800 <pathelement path="${proguard.config}"/> 801 </path> 802 <pathconvert pathsep='" -include "' property="proguard.configcmd" refid="proguard.configpath"/> 803 804 <mkdir dir="${obfuscate.absolute.dir}" /> 805 <delete file="${preobfuscate.jar.file}"/> 806 <delete file="${obfuscated.jar.file}"/> 807 <jar basedir="${out.classes.absolute.dir}" 808 destfile="${preobfuscate.jar.file}" /> 809 <proguard> 810 -include "${proguard.configcmd}" 811 -injars ${project.all.classes.value} 812 -outjars "${obfuscated.jar.file}" 813 -libraryjars ${project.target.classpath.value} 814 -dump "${obfuscate.absolute.dir}/dump.txt" 815 -printseeds "${obfuscate.absolute.dir}/seeds.txt" 816 -printusage "${obfuscate.absolute.dir}/usage.txt" 817 -printmapping "${obfuscate.absolute.dir}/mapping.txt" 818 </proguard> 819 </then> 820 </if> 821 </target> 822 823 <!-- Converts this project's .class files into .dex files --> 824 <target name="-dex" depends="-compile, -post-compile, -obfuscate"> 825 <do-only-if-manifest-hasCode elseText="hasCode = false. Skipping..."> 826 <!-- only convert to dalvik bytecode is *not* a library --> 827 <do-only-if-not-library elseText="Library project: do not convert bytecode..." > 828 <!-- special case for instrumented builds: need to use no-locals and need 829 to pass in the emma jar. --> 830 <if condition="${build.is.instrumented}"> 831 <then> 832 <dex-helper nolocals="true"> 833 <external-libs> 834 <fileset file="${emma.dir}/emma_device.jar" /> 835 </external-libs> 836 </dex-helper> 837 </then> 838 <else> 839 <dex-helper /> 840 </else> 841 </if> 842 </do-only-if-not-library> 843 </do-only-if-manifest-hasCode> 844 </target> 845 846 <!-- Updates the pre-processed PNG cache --> 847 <target name="-crunch"> 848 <exec executable="${aapt}" taskName="crunch"> 849 <arg value="crunch" /> 850 <arg value="-v" /> 851 <arg value="-S" /> 852 <arg path="${resource.absolute.dir}" /> 853 <arg value="-C" /> 854 <arg path="${out.res.absolute.dir}" /> 855 </exec> 856 </target> 857 858 <!-- Puts the project's resources into the output package file 859 This actually can create multiple resource package in case 860 Some custom apk with specific configuration have been 861 declared in default.properties. 862 --> 863 <target name="-package-resources" depends="-crunch"> 864 <!-- only package resources if *not* a library project --> 865 <do-only-if-not-library elseText="Library project: do not package resources..." > 866 <aapt executable="${aapt}" 867 command="package" 868 versioncode="${version.code}" 869 versionname="${version.name}" 870 debug="${build.is.packaging.debug}" 871 manifest="${out.manifest.abs.file}" 872 assets="${asset.absolute.dir}" 873 androidjar="${project.target.android.jar}" 874 apkfolder="${out.absolute.dir}" 875 nocrunch="${build.packaging.nocrunch}" 876 resourcefilename="${resource.package.file.name}" 877 resourcefilter="${aapt.resource.filter}" 878 libraryResFolderPathRefid="project.library.res.folder.path" 879 libraryPackagesRefid="project.library.packages" 880 previousBuildType="${build.last.target}" 881 buildType="${build.target}"> 882 <res path="${out.res.absolute.dir}" /> 883 <res path="${resource.absolute.dir}" /> 884 <!-- <nocompress /> forces no compression on any files in assets or res/raw --> 885 <!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw --> 886 </aapt> 887 </do-only-if-not-library> 888 </target> 889 890 <!-- Packages the application. --> 891 <target name="-package" depends="-dex, -package-resources"> 892 <!-- only package apk if *not* a library project --> 893 <do-only-if-not-library elseText="Library project: do not package apk..." > 894 <if condition="${build.is.instrumented}"> 895 <then> 896 <package-helper> 897 <extra-jars> 898 <!-- Injected from external file --> 899 <jarfile path="${emma.dir}/emma_device.jar" /> 900 </extra-jars> 901 </package-helper> 902 </then> 903 <else> 904 <package-helper /> 905 </else> 906 </if> 907 </do-only-if-not-library> 908 </target> 909 910 <target name="-post-package" /> 911 <target name="-post-build" /> 912 913 <target name="-set-mode-check"> 914 <fail if="build.is.mode.set" 915 message="Cannot run two different modes at the same time. If you are running more than one debug/release/instrument type targets, call them from different Ant calls." /> 916 </target> 917 918 <!-- ******************************************************* --> 919 <!-- **************** Debug specific targets *************** --> 920 <!-- ******************************************************* --> 921 922 <target name="-set-debug-files" depends="-set-mode-check"> 923 924 <property name="out.packaged.file" location="${out.absolute.dir}/${ant.project.name}-debug-unaligned.apk" /> 925 <property name="out.final.file" location="${out.absolute.dir}/${ant.project.name}-debug.apk" /> 926 <property name="build.is.mode.set" value="true" /> 927 </target> 928 929 930 <target name="-set-debug-mode" depends="-setup"> 931 <!-- record the current build target --> 932 <property name="build.target" value="debug" /> 933 934 <if> 935 <condition> 936 <and> 937 <istrue value="${project.is.testapp}" /> 938 <istrue value="${emma.enabled}" /> 939 </and> 940 </condition> 941 <then> 942 <property name="build.is.instrumented" value="true" /> 943 </then> 944 <else> 945 <property name="build.is.instrumented" value="false" /> 946 </else> 947 </if> 948 949 <!-- whether the build is a debug build. always set. --> 950 <property name="build.is.packaging.debug" value="true" /> 951 952 <!-- signing mode: debug --> 953 <property name="build.is.signing.debug" value="true" /> 954 955 <!-- Renderscript optimization level: none --> 956 <property name="renderscript.opt.level" value="${renderscript.debug.opt.level}" /> 957 958 </target> 959 960 <target name="-debug-obfuscation-check"> 961 <!-- proguard is never enabled in debug mode --> 962 <property name="proguard.enabled" value="false"/> 963 </target> 964 965 <!-- Builds debug output package --> 966 <target name="-do-debug" depends="-set-debug-mode, -debug-obfuscation-check, -package, -post-package"> 967 <!-- only create apk if *not* a library project --> 968 <do-only-if-not-library elseText="Library project: do not create apk..." > 969 <sequential> 970 <zipalign-helper in.package="${out.packaged.file}" out.package="${out.final.file}" /> 971 <echo level="info">Debug Package: ${out.final.file}</echo> 972 </sequential> 973 </do-only-if-not-library> 974 <record-build-info /> 975 </target> 976 977 <!-- Builds debug output package --> 978 <target name="debug" depends="-set-debug-files, -do-debug, -post-build" 979 description="Builds the application and signs it with a debug key."> 980 </target> 981 982 983 <!-- ******************************************************* --> 984 <!-- *************** Release specific targets ************** --> 985 <!-- ******************************************************* --> 986 987 <!-- called through target 'release'. Only executed if the keystore and 988 key alias are known but not their password. --> 989 <target name="-release-prompt-for-password" if="has.keystore" unless="has.password"> 990 <!-- Gets passwords --> 991 <input 992 message="Please enter keystore password (store:${key.store}):" 993 addproperty="key.store.password" /> 994 <input 995 message="Please enter password for alias '${key.alias}':" 996 addproperty="key.alias.password" /> 997 </target> 998 999 <!-- called through target 'release'. Only executed if there's no 1000 keystore/key alias set --> 1001 <target name="-release-nosign" unless="has.keystore"> 1002 <!-- no release builds for library project --> 1003 <do-only-if-not-library elseText="" > 1004 <sequential> 1005 <echo level="info">No key.store and key.alias properties found in build.properties.</echo> 1006 <echo level="info">Please sign ${out.packaged.file} manually</echo> 1007 <echo level="info">and run zipalign from the Android SDK tools.</echo> 1008 </sequential> 1009 </do-only-if-not-library> 1010 <record-build-info /> 1011 </target> 1012 1013 <target name="-release-obfuscation-check"> 1014 <echo level="info">proguard.config is ${proguard.config}</echo> 1015 <condition property="proguard.enabled" value="true" else="false"> 1016 <and> 1017 <isset property="build.is.mode.release" /> 1018 <isset property="proguard.config" /> 1019 </and> 1020 </condition> 1021 <if condition="${proguard.enabled}"> 1022 <then> 1023 <echo level="info">Proguard.config is enabled</echo> 1024 <!-- Secondary dx input (jar files) is empty since all the 1025 jar files will be in the obfuscated jar --> 1026 <path id="out.dex.jar.input.ref" /> 1027 </then> 1028 </if> 1029 </target> 1030 1031 <target name="-set-release-mode" depends="-set-mode-check"> 1032 <property name="out.packaged.file" location="${out.absolute.dir}/${ant.project.name}-release-unsigned.apk" /> 1033 <property name="out.final.file" location="${out.absolute.dir}/${ant.project.name}-release.apk" /> 1034 <property name="build.is.mode.set" value="true" /> 1035 1036 <!-- record the current build target --> 1037 <property name="build.target" value="release" /> 1038 1039 <property name="build.is.instrumented" value="false" /> 1040 1041 <!-- release mode is only valid if the manifest does not explicitly 1042 set debuggable to true. default is false. --> 1043 <xpath input="${manifest.abs.file}" expression="/manifest/application/@android:debuggable" 1044 output="build.is.packaging.debug" default="false"/> 1045 1046 <!-- signing mode: release --> 1047 <property name="build.is.signing.debug" value="false" /> 1048 1049 <!-- Renderscript optimization level: aggressive --> 1050 <property name="renderscript.opt.level" value="${renderscript.release.opt.level}" /> 1051 1052 <if condition="${build.is.packaging.debug}"> 1053 <then> 1054 <echo>*************************************************</echo> 1055 <echo>**** Android Manifest has debuggable=true ****</echo> 1056 <echo>**** Doing DEBUG packaging with RELEASE keys ****</echo> 1057 <echo>*************************************************</echo> 1058 </then> 1059 <else> 1060 <!-- property only set in release mode. 1061 Useful for if/unless attributes in target node 1062 when using Ant before 1.8 --> 1063 <property name="build.is.mode.release" value="true"/> 1064 </else> 1065 </if> 1066 </target> 1067 1068 <target name="-release-sign" if="has.keystore" > 1069 <!-- only create apk if *not* a library project --> 1070 <do-only-if-not-library elseText="Library project: do not create apk..." > 1071 <sequential> 1072 <property name="out.unaligned.file" location="${out.absolute.dir}/${ant.project.name}-release-unaligned.apk" /> 1073 1074 <!-- Signs the APK --> 1075 <echo level="info">Signing final apk...</echo> 1076 <signapk 1077 input="${out.packaged.file}" 1078 output="${out.unaligned.file}" 1079 keystore="${key.store}" 1080 storepass="${key.store.password}" 1081 alias="${key.alias}" 1082 keypass="${key.alias.password}"/> 1083 1084 <!-- Zip aligns the APK --> 1085 <zipalign-helper 1086 in.package="${out.unaligned.file}" 1087 out.package="${out.final.file}" /> 1088 <echo level="info">Release Package: ${out.final.file}</echo> 1089 </sequential> 1090 </do-only-if-not-library> 1091 <record-build-info /> 1092 </target> 1093 1094 <!-- This runs -package-release and -release-nosign first and then runs 1095 only if release-sign is true (set in -release-check, 1096 called by -release-no-sign)--> 1097 <target name="release" 1098 depends="-set-release-mode, -release-obfuscation-check, -package, -post-package, -release-prompt-for-password, -release-nosign, -release-sign, -post-build" 1099 description="Builds the application in release mode."> 1100 </target> 1101 1102 <!-- ******************************************************* --> 1103 <!-- ************ Instrumented specific targets ************ --> 1104 <!-- ******************************************************* --> 1105 1106 <!-- These targets are specific for the project under test when it 1107 gets compiled by the test projects in a way that will make it 1108 support emma code coverage --> 1109 1110 <target name="-set-instrumented-mode" depends="-set-mode-check"> 1111 <property name="out.packaged.file" location="${out.absolute.dir}/${ant.project.name}-instrumented-unaligned.apk" /> 1112 <property name="out.final.file" location="${out.absolute.dir}/${ant.project.name}-instrumented.apk" /> 1113 <property name="build.is.mode.set" value="true" /> 1114 1115 <!-- whether the build is an instrumented build. --> 1116 <property name="build.is.instrumented" value="true" /> 1117 </target> 1118 1119 <!-- Builds instrumented output package --> 1120 <target name="instrument" depends="-set-instrumented-mode, -do-debug" 1121 description="Builds an instrumented packaged."> 1122 <!-- only create apk if *not* a library project --> 1123 <do-only-if-not-library elseText="Library project: do not create apk..." > 1124 <sequential> 1125 <zipalign-helper in.package="${out.packaged.file}" out.package="${out.final.file}" /> 1126 <echo level="info">Instrumented Package: ${out.final.file}</echo> 1127 </sequential> 1128 </do-only-if-not-library> 1129 <record-build-info /> 1130 </target> 1131 1132 <!-- ******************************************************* --> 1133 <!-- ************ Test project specific targets ************ --> 1134 <!-- ******************************************************* --> 1135 1136 <!-- enable code coverage --> 1137 <target name="emma"> 1138 <property name="emma.enabled" value="true" /> 1139 </target> 1140 1141 <!-- fails if the project is not a test project --> 1142 <target name="-test-project-check" depends="-setup"> 1143 <if> 1144 <condition> 1145 <and> 1146 <isfalse value="${project.is.test}" /> 1147 <isfalse value="${project.is.testapp}" /> 1148 </and> 1149 </condition> 1150 <then> 1151 <fail message="Project is not a test project." /> 1152 </then> 1153 </if> 1154 </target> 1155 1156 <target name="test" depends="-test-project-check" 1157 description="Runs tests from the package defined in test.package property"> 1158 <property name="test.runner" value="android.test.InstrumentationTestRunner" /> 1159 1160 <if condition="${project.is.test}"> 1161 <then> 1162 <property name="tested.project.absolute.dir" location="${tested.project.dir}" /> 1163 1164 <!-- Application package of the tested project extracted from its manifest file --> 1165 <xpath input="${tested.project.absolute.dir}/AndroidManifest.xml" 1166 expression="/manifest/@package" output="tested.project.app.package" /> 1167 </then> 1168 <else> 1169 <!-- this is a test app, the tested package is the app's own package --> 1170 <property name="tested.project.app.package" value="${project.app.package}" /> 1171 </else> 1172 </if> 1173 1174 <property name="emma.dump.file" 1175 value="/data/data/${tested.project.app.package}/coverage.ec" /> 1176 1177 <if condition="${emma.enabled}"> 1178 <then> 1179 <echo>WARNING: Code Coverage is currently only supported on the emulator and rooted devices.</echo> 1180 <run-tests-helper emma.enabled="true"> 1181 <extra-instrument-args> 1182 <arg value="-e" /> 1183 <arg value="coverageFile" /> 1184 <arg value="${emma.dump.file}" /> 1185 </extra-instrument-args> 1186 </run-tests-helper> 1187 <echo level="info">Downloading coverage file into project directory...</echo> 1188 <exec executable="${adb}" failonerror="true"> 1189 <arg line="${adb.device.arg}" /> 1190 <arg value="pull" /> 1191 <arg value="${emma.dump.file}" /> 1192 <arg value="coverage.ec" /> 1193 </exec> 1194 <echo level="info">Extracting coverage report...</echo> 1195 <emma> 1196 <report sourcepath="${tested.project.absolute.dir}/${source.dir}" 1197 verbosity="${verbosity}"> 1198 <!-- TODO: report.dir or something like should be introduced if necessary --> 1199 <infileset dir="${out.absolute.dir}"> 1200 <include name="coverage.ec" /> 1201 <include name="coverage.em" /> 1202 </infileset> 1203 <!-- TODO: reports in other, indicated by user formats --> 1204 <html outfile="coverage.html" /> 1205 </report> 1206 </emma> 1207 <echo level="info">Cleaning up temporary files...</echo> 1208 <delete file="${out.absolute.dir}/coverage.ec" /> 1209 <delete file="${out.absolute.dir}/coverage.em" /> 1210 <echo level="info">Saving the report file in ${basedir}/coverage/coverage.html</echo> 1211 </then> 1212 <else> 1213 <run-tests-helper /> 1214 </else> 1215 </if> 1216 </target> 1217 1218 1219 <!-- ******************************************************* --> 1220 <!-- ********** Install/uninstall specific targets ********* --> 1221 <!-- ******************************************************* --> 1222 1223 <target name="install" 1224 description="Installs the newly build package. Must be used in conjunction with a build target 1225 (debug/release/instrument). If the application was previously installed, the application 1226 is reinstalled if the signature matches." > 1227 <!-- only do install if *not* a library project --> 1228 <do-only-if-not-library elseText="Library project: nothing to install!" > 1229 <if> 1230 <condition> 1231 <isset property="out.final.file" /> 1232 </condition> 1233 <then> 1234 <if> 1235 <condition> 1236 <resourceexists> 1237 <file file="${out.final.file}"/> 1238 </resourceexists> 1239 </condition> 1240 <then> 1241 <echo level="info">Installing ${out.final.file} onto default emulator or device...</echo> 1242 <exec executable="${adb}" failonerror="true"> 1243 <arg line="${adb.device.arg}" /> 1244 <arg value="install" /> 1245 <arg value="-r" /> 1246 <arg path="${out.final.file}" /> 1247 </exec> 1248 1249 <!-- now install the tested project if applicable --> 1250 <!-- can't use project.is.test since the setup target might not have run --> 1251 <if> 1252 <condition> 1253 <and> 1254 <isset property="tested.project.dir" /> 1255 <not> 1256 <isset property="dont.do.deps" /> 1257 </not> 1258 </and> 1259 </condition> 1260 <then> 1261 <property name="tested.project.absolute.dir" location="${tested.project.dir}" /> 1262 1263 <!-- figure out which tested package to install based on emma.enabled --> 1264 <condition property="tested.project.install.target" value="installi" else="installd"> 1265 <isset property="emma.enabled" /> 1266 </condition> 1267 <subant target="${tested.project.install.target}" failonerror="true"> 1268 <fileset dir="${tested.project.absolute.dir}" includes="build.xml" /> 1269 </subant> 1270 </then> 1271 </if> 1272 </then> 1273 <else> 1274 <fail message="File ${out.final.file} does not exist." /> 1275 </else> 1276 </if> 1277 </then> 1278 <else> 1279 <echo>Install file not specified.</echo> 1280 <echo></echo> 1281 <echo>'ant install' now requires the build target to be specified as well.</echo> 1282 <echo></echo> 1283 <echo></echo> 1284 <echo> ant debug install</echo> 1285 <echo> ant release install</echo> 1286 <echo> ant instrument install</echo> 1287 <echo>This will build the given package and install it.</echo> 1288 <echo></echo> 1289 <echo>Alternatively, you can use</echo> 1290 <echo> ant installd</echo> 1291 <echo> ant installr</echo> 1292 <echo> ant installi</echo> 1293 <echo> ant installt</echo> 1294 <echo>to only install an existing package (this will not rebuild the package.)</echo> 1295 <fail /> 1296 </else> 1297 </if> 1298 </do-only-if-not-library> 1299 </target> 1300 1301 <target name="installd" depends="-set-debug-files, install" 1302 description="Installs (only) the debug package." /> 1303 <target name="installr" depends="-set-release-mode, install" 1304 description="Installs (only) the release package." /> 1305 <target name="installi" depends="-set-instrumented-mode, install" 1306 description="Installs (only) the instrumented package." /> 1307 <target name="installt" depends="-test-project-check, installd" 1308 description="Installs (only) the test and tested packages." /> 1309 1310 1311 <!-- Uninstalls the package from the default emulator/device --> 1312 <target name="uninstall" depends="-setup" 1313 description="Uninstalls the application from a running emulator or device."> 1314 <if> 1315 <condition> 1316 <isset property="project.app.package" /> 1317 </condition> 1318 <then> 1319 <uninstall-helper app.package="${project.app.package}" /> 1320 </then> 1321 <else> 1322 <fail message="Could not find application package in manifest. Cannot run 'adb uninstall'." /> 1323 </else> 1324 </if> 1325 1326 <!-- Now uninstall the tested project, if applicable --> 1327 <if> 1328 <condition> 1329 <and> 1330 <istrue value="${project.is.test}" /> 1331 <not> 1332 <isset property="dont.do.deps" /> 1333 </not> 1334 </and> 1335 </condition> 1336 <then> 1337 <property name="tested.project.absolute.dir" location="${tested.project.dir}" /> 1338 1339 <!-- Application package of the tested project extracted from its manifest file --> 1340 <xpath input="${tested.project.absolute.dir}/AndroidManifest.xml" 1341 expression="/manifest/@package" output="tested.project.app.package" /> 1342 <if> 1343 <condition> 1344 <isset property="tested.project.app.package" /> 1345 </condition> 1346 <then> 1347 <uninstall-helper app.package="${tested.project.app.package}" /> 1348 </then> 1349 <else> 1350 <fail message="Could not find tested application package in manifest. Cannot run 'adb uninstall'." /> 1351 </else> 1352 </if> 1353 </then> 1354 </if> 1355 1356 </target> 1357 1358 1359 <!-- ******************************************************* --> 1360 <!-- ************************* Help ************************ --> 1361 <!-- ******************************************************* --> 1362 1363 <target name="help"> 1364 <!-- displays starts at col 13 1365 |13 80| --> 1366 <echo>Android Ant Build. Available targets:</echo> 1367 <echo> help: Displays this help.</echo> 1368 <echo> clean: Removes output files created by other targets.</echo> 1369 <echo> The 'all' target can be used to clean dependencies</echo> 1370 <echo> (tested projects and libraries)at the same time</echo> 1371 <echo> using: 'ant all clean'</echo> 1372 <echo> debug: Builds the application and signs it with a debug key.</echo> 1373 <echo> The 'nodeps' target can be used to only build the</echo> 1374 <echo> current project and ignore the libraries using:</echo> 1375 <echo> 'ant nodeps debug'</echo> 1376 <echo> release: Builds the application. The generated apk file must be</echo> 1377 <echo> signed before it is published.</echo> 1378 <echo> The 'nodeps' target can be used to only build the</echo> 1379 <echo> current project and ignore the libraries using:</echo> 1380 <echo> 'ant nodeps release'</echo> 1381 <echo> instrument:Builds an instrumented package and signs it with a</echo> 1382 <echo> debug key.</echo> 1383 <echo> test: Runs the tests. Project must be a test project and</echo> 1384 <echo> must have been built. Typical usage would be:</echo> 1385 <echo> ant [emma] debug install test</echo> 1386 <echo> emma: Transiently enables code coverage for subsequent</echo> 1387 <echo> targets.</echo> 1388 <echo> install: Installs the newly build package. Must either be used</echo> 1389 <echo> in conjunction with a build target (debug/release/</echo> 1390 <echo> instrument) or with the proper suffix indicating</echo> 1391 <echo> which package to install (see below).</echo> 1392 <echo> If the application was previously installed, the</echo> 1393 <echo> application is reinstalled if the signature matches.</echo> 1394 <echo> installd: Installs (only) the debug package.</echo> 1395 <echo> installr: Installs (only) the release package.</echo> 1396 <echo> installi: Installs (only) the instrumented package.</echo> 1397 <echo> installt: Installs (only) the test and tested packages (unless</echo> 1398 <echo> nodeps is used as well.</echo> 1399 <echo> uninstall: Uninstalls the application from a running emulator or</echo> 1400 <echo> device. Also uninstall tested package if applicable</echo> 1401 <echo> unless 'nodeps' is used as well.</echo> 1402 </target> 1403 </project> 1404