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

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