Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(768)

Side by Side Diff: build/android/ant/apk-build.xml

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

Powered by Google App Engine
This is Rietveld 408576698