forked from androidquery/androidquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
1331 lines (1172 loc) · 58.2 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<project name="AndroidQueryTest" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<loadproperties srcFile="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
unless="sdk.dir"
/>
<!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets -->
<!--
<target name="-pre-build">
</target>
<target name="-pre-compile">
</target>
/* This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir} */
<target name="-post-compile">
</target>
-->
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<!--
<import file="${sdk.dir}/tools/ant/build.xml" />
-->
<!--
This build file is imported by the project build file. It contains
all the targets and tasks necessary to build Android projects, be they
regular projects, library projects, or test projects.
At the beginning of the file is a list of properties that can be overridden
by adding them to your build.properties (properties are immutable, so their
first definition sticks and is never changed).
Follows:
- custom task definitions,
- more properties (do not override those unless the whole build system is modified).
- macros used throughout the build,
- base build targets,
- debug-specific build targets,
- release-specific build targets,
- instrument-specific build targets,
- test project-specific build targets,
- install targets,
- help target
-->
<!-- ********** Overrideable Properties ********** -->
<!-- You can override these values in your build.xml or build.properties.
Overriding any other properties may result in broken build. -->
<!-- Tells adb which device to target. You can change this from the command line
by invoking "ant -Dadb.device.arg=-d" for device "ant -Dadb.device.arg=-e" for
the emulator. -->
<property name="adb.device.arg" value="" />
<!-- fileset exclude patterns (space separated) to prevent
files inside src/ from being packaged. -->
<property name="android.package.excludes" value="" />
<!-- set some properties used for filtering/override. If those weren't defined
before, then this will create them with empty values, which are then ignored
by the custom tasks receiving them. -->
<property name="version.code" value="" />
<property name="version.name" value="" />
<property name="aapt.resource.filter" value="" />
<!-- compilation options -->
<property name="java.encoding" value="UTF-8" />
<property name="java.target" value="1.5" />
<property name="java.source" value="1.5" />
<!-- Verbosity -->
<property name="verbose" value="false" />
<!-- ********** Custom Tasks ********** -->
<!-- jar file from where the tasks are loaded -->
<path id="android.antlibs">
<pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
</path>
<!-- Custom tasks -->
<taskdef name="setup"
classname="com.android.ant.NewSetupTask"
classpathref="android.antlibs" />
<taskdef name="aapt"
classname="com.android.ant.AaptExecTask"
classpathref="android.antlibs" />
<taskdef name="aidl"
classname="com.android.ant.AidlExecTask"
classpathref="android.antlibs" />
<taskdef name="renderscript"
classname="com.android.ant.RenderScriptTask"
classpathref="android.antlibs" />
<taskdef name="dex"
classname="com.android.ant.DexExecTask"
classpathref="android.antlibs" />
<taskdef name="apkbuilder"
classname="com.android.ant.ApkBuilderTask"
classpathref="android.antlibs" />
<taskdef name="zipalign"
classname="com.android.ant.ZipAlignTask"
classpathref="android.antlibs" />
<taskdef name="xpath"
classname="com.android.ant.XPathTask"
classpathref="android.antlibs" />
<taskdef name="if"
classname="com.android.ant.IfElseTask"
classpathref="android.antlibs" />
<!-- Emma configuration -->
<property name="emma.dir" value="${sdk.dir}/tools/lib" />
<path id="emma.lib">
<pathelement location="${emma.dir}/emma.jar" />
<pathelement location="${emma.dir}/emma_ant.jar" />
</path>
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
<!-- End of emma configuration -->
<!-- ********** Other Properties ********** -->
<!-- overriding these properties may break the build
unless the whole file is updated -->
<!-- Input directories -->
<property name="source.dir" value="src" />
<property name="source.absolute.dir" location="${source.dir}" />
<property name="gen.absolute.dir" location="gen" />
<property name="resource.absolute.dir" location="res" />
<property name="asset.absolute.dir" location="assets" />
<property name="jar.libs.dir" value="libs" />
<property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
<property name="native.libs.absolute.dir" location="libs" />
<!-- Output directories -->
<property name="out.dir" value="bin" />
<property name="out.absolute.dir" location="${out.dir}" />
<property name="out.classes.absolute.dir" location="${out.dir}/classes" />
<property name="out.res.absolute.dir" location="${out.dir}/res" />
<!-- tools location -->
<property name="android.tools.dir" location="${sdk.dir}/tools" />
<property name="android.platform.tools.dir" location="${sdk.dir}/platform-tools" />
<condition property="exe" value=".exe" else=""><os family="windows" /></condition>
<condition property="bat" value=".bat" else=""><os family="windows" /></condition>
<property name="adb" location="${android.platform.tools.dir}/adb${exe}" />
<property name="zipalign" location="${android.tools.dir}/zipalign${exe}" />
<property name="aidl" location="${android.platform.tools.dir}/aidl${exe}" />
<property name="aapt" location="${android.platform.tools.dir}/aapt${exe}" />
<property name="dx" location="${android.platform.tools.dir}/dx${bat}" />
<!-- renderscript location is set by NewSetupTask since we have a choice of
several executables based on minSdkVersion -->
<!-- Intermediate files -->
<property name="dex.file.name" value="classes.dex" />
<property name="intermediate.dex.file" location="${out.absolute.dir}/${dex.file.name}" />
<property name="resource.package.file.name" value="${ant.project.name}.ap_" />
<!-- Build property file -->
<property name="out.build.prop.file" location="${out.absolute.dir}/build.prop" />
<!-- This is needed by emma as it uses multilevel verbosity instead of simple 'true' or 'false'
The property 'verbosity' is not user configurable and depends exclusively on 'verbose'
value.-->
<condition property="verbosity" value="verbose" else="quiet">
<istrue value="${verbose}" />
</condition>
<!-- properties for signing in release mode -->
<condition property="has.keystore">
<and>
<isset property="key.store" />
<length string="${key.store}" when="greater" length="0" />
<isset property="key.alias" />
</and>
</condition>
<condition property="has.password">
<and>
<isset property="has.keystore" />
<isset property="key.store.password" />
<isset property="key.alias.password" />
</and>
</condition>
<!-- properties for packaging -->
<property name="build.packaging.nocrunch" value="true" />
<!-- ********** Macros ********** -->
<!-- macro to do a task on if project.is.library is false.
elseText attribute is displayed otherwise -->
<macrodef name="do-only-if-not-library">
<attribute name="elseText" />
<element name="task-to-do" implicit="yes" />
<sequential>
<if condition="${project.is.library}">
<else>
<task-to-do />
</else>
<then>
<echo>@{elseText}</echo>
</then>
</if>
</sequential>
</macrodef>
<!-- macro to do a task on if manifest.hasCode is true.
elseText attribute is displayed otherwise -->
<macrodef name="do-only-if-manifest-hasCode">
<attribute name="elseText" default=""/>
<element name="task-to-do" implicit="yes" />
<sequential>
<if condition="${manifest.hasCode}">
<then>
<task-to-do />
</then>
<else>
<if>
<condition>
<length string="@{elseText}" trim="true" when="greater" length="0" />
</condition>
<then>
<echo>@{elseText}</echo>
</then>
</if>
</else>
</if>
</sequential>
</macrodef>
<!-- Configurable macro, which allows to pass as parameters output directory,
output dex filename and external libraries to dex (optional) -->
<macrodef name="dex-helper">
<element name="external-libs" optional="yes" />
<attribute name="nolocals" default="false" />
<sequential>
<!-- sets the primary input for dex. If a pre-dex task sets it to
something else this has no effect -->
<property name="out.dex.input.absolute.dir" value="${out.classes.absolute.dir}" />
<!-- set the secondary dx input: the project (and library) jar files
If a pre-dex task sets it to something else this has no effect -->
<if>
<condition>
<isreference refid="out.dex.jar.input.ref" />
</condition>
<else>
<path id="out.dex.jar.input.ref">
<path refid="jar.libs.ref" />
</path>
</else>
</if>
<dex executable="${dx}"
output="${intermediate.dex.file}"
nolocals="@{nolocals}"
verbose="${verbose}"
previousBuildType="${build.last.target}"
buildType="${build.target}">
<path path="${out.dex.input.absolute.dir}"/>
<path refid="out.dex.jar.input.ref" />
<external-libs />
</dex>
</sequential>
</macrodef>
<!-- This is macro that enable passing variable list of external jar files to ApkBuilder
Example of use:
<package-helper>
<extra-jars>
<jarfolder path="my_jars" />
<jarfile path="foo/bar.jar" />
<jarfolder path="your_jars" />
</extra-jars>
</package-helper> -->
<macrodef name="package-helper">
<element name="extra-jars" optional="yes" />
<sequential>
<apkbuilder
outfolder="${out.absolute.dir}"
resourcefile="${resource.package.file.name}"
apkfilepath="${out.packaged.file}"
debugpackaging="${build.is.packaging.debug}"
debugsigning="${build.is.signing.debug}"
verbose="${verbose}"
hascode="${manifest.hasCode}"
previousBuildType="${build.last.is.packaging.debug}/${build.last.is.signing.debug}"
buildType="${build.is.packaging.debug}/${build.is.signing.debug}">
<dex path="${intermediate.dex.file}"/>
<sourcefolder path="${source.absolute.dir}"/>
<jarfile refid="jar.libs.ref" />
<nativefolder path="${native.libs.absolute.dir}" />
<nativefolder refid="project.libraries.libs" />
<extra-jars/>
</apkbuilder>
</sequential>
</macrodef>
<!-- This is macro which zipaligns in.package and outputs it to out.package. Used by targets
debug, -debug-with-emma and release.-->
<macrodef name="zipalign-helper">
<attribute name="in.package" />
<attribute name="out.package" />
<sequential>
<zipalign
executable="${zipalign}"
input="@{in.package}"
output="@{out.package}"
verbose="${verbose}" />
</sequential>
</macrodef>
<macrodef name="run-tests-helper">
<attribute name="emma.enabled" default="false" />
<element name="extra-instrument-args" optional="yes" />
<sequential>
<echo>Running tests ...</echo>
<echo>@{emma.enabled}</echo>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="shell" />
<arg value="am" />
<arg value="instrument" />
<arg value="-w" />
<arg value="-e" />
<arg value="coverage" />
<arg value="@{emma.enabled}" />
<extra-instrument-args />
<arg value="${manifest.package}/${test.runner}" />
</exec>
</sequential>
</macrodef>
<macrodef name="record-build-key">
<attribute name="key" default="false" />
<attribute name="value" default="false" />
<sequential>
<propertyfile file="${out.build.prop.file}" comment="Last build type">
<entry key="@{key}" value="@{value}"/>
</propertyfile>
</sequential>
</macrodef>
<macrodef name="record-build-info">
<sequential>
<record-build-key key="build.last.target" value="${build.target}" />
<record-build-key key="build.last.is.instrumented" value="${build.is.instrumented}" />
<record-build-key key="build.last.is.packaging.debug" value="${build.is.packaging.debug}" />
<record-build-key key="build.last.is.signing.debug" value="${build.is.signing.debug}" />
</sequential>
</macrodef>
<macrodef name="uninstall-helper">
<attribute name="app.package" default="false" />
<sequential>
<echo>Uninstalling @{app.package} from the default emulator or device...</echo>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="uninstall" />
<arg value="@{app.package}" />
</exec>
</sequential>
</macrodef>
<!-- ********** Build Targets ********** -->
<!-- this target simply force running -setup making
the project info be read. To be used as
ant all clean
to clean the main project as well as the libraries and tested project -->
<target name="all" depends="-setup"/>
<!-- clean target -->
<target name="clean" description="Removes output files created by other targets.">
<delete dir="${out.absolute.dir}" verbose="${verbose}" />
<delete dir="${gen.absolute.dir}" verbose="${verbose}" />
<!-- if we know about a tested project or libraries, we clean them too. This
will only work if the target 'all' was called first -->
<if condition="${project.is.test}">
<then>
<property name="tested.project.absolute.dir" location="${tested.project.dir}" />
<subant failonerror="true">
<fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
<target name="all" />
<target name="clean" />
</subant>
</then>
</if>
<if>
<condition>
<isreference refid="project.libraries" />
</condition>
<then>
<subant
buildpathref="project.libraries"
antfile="build.xml"
failonerror="true">
<target name="all" />
<target name="clean" />
</subant>
</then>
</if>
</target>
<!-- generic setup -->
<target name="-setup">
<if>
<condition>
<not><isset property="setup.done" /></not>
</condition>
<then>
<property name="setup.done" value="true" />
<echo>Gathering info for ${ant.project.name}...</echo>
<!-- load project properties, resolve Android target, library dependencies
and set some properties with the results.
All property names are passed as parameters ending in -Out -->
<setup
projectTypeOut="android.project.type"
androidJarFileOut="android.jar"
androidAidlFileOut="android.aidl"
renderScriptExeOut="renderscript"
renderScriptIncludeDirOut="android.rs"
bootclasspathrefOut="android.target.classpath"
projectLibrariesRootOut="project.libraries"
projectLibrariesJarsOut="project.libraries.jars"
projectLibrariesResOut="project.libraries.res"
projectLibrariesPackageOut="project.libraries.package"
projectLibrariesLibsOut="project.libraries.libs"
targetApiOut="target.api"
/>
<!-- sets a few boolean based on android.project.type
to make the if task easier -->
<condition property="project.is.library" else="false">
<equals arg1="${android.project.type}" arg2="library" />
</condition>
<condition property="project.is.test" else="false">
<equals arg1="${android.project.type}" arg2="test" />
</condition>
<!-- If a test project, resolve absolute path to tested project. -->
<if condition="${project.is.test}">
<then>
<property name="tested.project.absolute.dir" location="${tested.project.dir}" />
</then>
</if>
</then>
</if>
</target>
<!-- Pre build setup -->
<target name="-build-setup" depends="-setup">
<!-- read the previous build mode -->
<property file="${out.build.prop.file}" />
<!-- if empty the prop won't be set, so set it to the current target
to provide a default value equal to the current build -->
<property name="build.last.target" value="${build.target}" />
<!-- also set the default value for whether the build is instrumented -->
<property name="build.last.is.instrumented" value="${build.is.instrumented}" />
<property name="build.last.is.packaging.debug" value="${build.is.packaging.debug}" />
<property name="build.last.is.signing.debug" value="${build.is.signing.debug}" />
<!-- compile the libraries if any -->
<!--
<if>
<condition>
<isreference refid="project.libraries" />
</condition>
<then>
<echo>Building Libraries</echo>
<subant
buildpathref="project.libraries"
antfile="build.xml"
target="${build.target}"
failonerror="true"/>
<echo></echo>
<echo>############################################</echo>
<echo>**** Back to project ${ant.project.name} ****</echo>
<echo>############################################</echo>
</then>
</if>
-->
<!-- compile the main project if this is a test project -->
<!--
<if condition="${project.is.test}">
<then>
<condition property="tested.project.target" value="instrument" else="debug">
<isset property="emma.enabled" />
</condition>
<echo>Building tested project at ${tested.project.absolute.dir}</echo>
<subant target="${tested.project.target}" failonerror="true">
<fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
</subant>
<echo></echo>
<echo>############################################</echo>
<echo>**** Back to project ${ant.project.name} ****</echo>
<echo>############################################</echo>
</then>
</if>
-->
<!-- Value of the hasCode attribute (Application node) extracted from manifest file -->
<xpath input="AndroidManifest.xml" expression="/manifest/application/@android:hasCode"
output="manifest.hasCode" default="true"/>
<!-- create a path with all the jar files, from the main project and the
libraries -->
<path id="jar.libs.ref">
<fileset dir="${jar.libs.absolute.dir}" includes="*.jar" />
<path refid="project.libraries.jars" />
</path>
<!-- special case for instrumented: if the previous build was
instrumented but not this one, clear out the compiled code -->
<if>
<condition>
<and>
<istrue value="${build.last.is.instrumented}" />
<isfalse value="${build.is.instrumented}" />
</and>
</condition>
<then>
<echo>Switching from instrumented to non-instrumented build.</echo>
<echo>Deleting previous compilation output:</echo>
<delete dir="${out.classes.absolute.dir}" verbose="${verbose}" />
</then>
</if>
<echo>Creating output directories if needed...</echo>
<mkdir dir="${resource.absolute.dir}" />
<mkdir dir="${jar.libs.absolute.dir}" />
<mkdir dir="${out.absolute.dir}" />
<mkdir dir="${out.res.absolute.dir}" />
<do-only-if-manifest-hasCode>
<mkdir dir="${gen.absolute.dir}" />
<mkdir dir="${out.classes.absolute.dir}" />
</do-only-if-manifest-hasCode>
</target>
<!-- empty default pre-build target. Create a similar target in
your build.xml and it'll be called instead of this one. -->
<target name="-pre-build"/>
<!-- Code Generation: compile resources (aapt -> R.java), aidl, renderscript -->
<target name="-code-gen">
<do-only-if-manifest-hasCode
elseText="hasCode = false. Skipping aidl/renderscript/R.java">
<echo>----------</echo>
<echo>Handling aidl files...</echo>
<aidl executable="${aidl}" framework="${android.aidl}"
genFolder="${gen.absolute.dir}">
<source path="${source.absolute.dir}"/>
</aidl>
<!-- renderscript generates resources so it must be called before aapt -->
<echo>----------</echo>
<echo>Handling RenderScript files...</echo>
<renderscript executable="${renderscript}"
framework="${android.rs}"
genFolder="${gen.absolute.dir}"
resFolder="${resource.absolute.dir}/raw"
targetApi="${target.api}">
<source path="${source.absolute.dir}"/>
</renderscript>
<echo>----------</echo>
<echo>Handling Resources...</echo>
<aapt executable="${aapt}"
command="package"
verbose="${verbose}"
manifest="AndroidManifest.xml"
androidjar="${android.jar}"
rfolder="${gen.absolute.dir}"
nonConstantId="${android.library}"
projectLibrariesResName="project.libraries.res"
projectLibrariesPackageName="project.libraries.package">
<res path="${resource.absolute.dir}" />
</aapt>
</do-only-if-manifest-hasCode>
</target>
<!-- empty default pre-compile target. Create a similar target in
your build.xml and it'll be called instead of this one. -->
<target name="-pre-compile"/>
<!-- Compiles this project's .java files into .class files. -->
<target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile">
<do-only-if-manifest-hasCode elseText="hasCode = false. Skipping...">
<!-- If android rules are used for a test project, its classpath should include
tested project's location -->
<condition property="extensible.classpath"
value="${tested.project.absolute.dir}/bin/classes"
else=".">
<isset property="tested.project.absolute.dir" />
</condition>
<condition property="extensible.libs.classpath"
value="${tested.project.absolute.dir}/${jar.libs.dir}"
else="${jar.libs.dir}">
<isset property="tested.project.absolute.dir" />
</condition>
<javac encoding="${java.encoding}"
source="${java.source}" target="${java.target}"
debug="true" extdirs=""
destdir="${out.classes.absolute.dir}"
bootclasspathref="android.target.classpath"
verbose="${verbose}"
classpath="${extensible.classpath}"
classpathref="jar.libs.ref">
<src path="${source.absolute.dir}" />
<src path="${gen.absolute.dir}" />
<classpath>
<fileset dir="${extensible.libs.classpath}" includes="*.jar" />
</classpath>
</javac>
<!-- if the project is a library then we generate a jar file -->
<if condition="${project.is.library}">
<then>
<echo>Creating library output jar file...</echo>
<property name="out.library.jar.file" location="${out.absolute.dir}/classes.jar" />
<if>
<condition>
<length string="${android.package.excludes}" trim="true" when="greater" length="0" />
</condition>
<then>
<echo>Custom jar packaging exclusion: ${android.package.excludes}</echo>
</then>
</if>
<jar destfile="${out.library.jar.file}">
<fileset dir="${out.classes.absolute.dir}" excludes="**/R.class **/R$*.class"/>
<fileset dir="${source.absolute.dir}" excludes="**/*.java ${android.package.excludes}" />
</jar>
</then>
</if>
<!-- if the project is instrumented, intrument the classes -->
<if condition="${build.is.instrumented}">
<then>
<echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo>
<echo>EMMA will create meta data file in ${emma.report.dir}/coverage.em</echo>
<!-- It only instruments class files, not any external libs -->
<emma enabled="true">
<instr verbosity="${verbosity}"
mode="overwrite"
instrpath="${out.absolute.dir}/classes"
outdir="${out.absolute.dir}/classes"
metadatafile="${emma.report.dir}/coverage.em"
>
</instr>
<!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
user defined file -->
</emma>
</then>
</if>
</do-only-if-manifest-hasCode>
</target>
<!-- empty default post-compile target. Create a similar target in
your build.xml and it'll be called instead of this one. -->
<target name="-post-compile"/>
<!-- Obfuscate target
This is only active in release builds when proguard.config is defined
in default.properties.
To replace Proguard with a different obfuscation engine:
Override the following targets in your build.xml, before the call to <setup>
-release-obfuscation-check
Check whether obfuscation should happen, and put the result in a property.
-debug-obfuscation-check
Obfuscation should not happen. Set the same property to false.
-obfuscate
check if the property set in -debug/release-obfuscation-check is set to true.
If true:
Perform obfuscation
Set property out.dex.input.absolute.dir to be the output of the obfuscation
-->
<target name="-obfuscate">
<if condition="${proguard.enabled}">
<then>
<property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard" />
<property name="preobfuscate.jar.file" value="${obfuscate.absolute.dir}/original.jar" />
<property name="obfuscated.jar.file" value="${obfuscate.absolute.dir}/obfuscated.jar" />
<!-- input for dex will be proguard's output -->
<property name="out.dex.input.absolute.dir" value="${obfuscated.jar.file}" />
<!-- Add Proguard Tasks -->
<property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar" />
<taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" />
<!-- Set the android classpath Path object into a single property. It'll be
all the jar files separated by a platform path-separator.
Each path must be quoted if it contains spaces.
-->
<pathconvert property="android.libraryjars" refid="android.target.classpath">
<firstmatchmapper>
<regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/>
<identitymapper/>
</firstmatchmapper>
</pathconvert>
<!-- Build a path object with all the jar files that must be obfuscated.
This include the project compiled source code and any 3rd party jar
files. -->
<path id="project.jars.ref">
<pathelement location="${preobfuscate.jar.file}" />
<path refid="jar.libs.ref" />
</path>
<!-- Set the project jar files Path object into a single property. It'll be
all the jar files separated by a platform path-separator.
Each path must be quoted if it contains spaces.
-->
<pathconvert property="project.jars" refid="project.jars.ref">
<firstmatchmapper>
<regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/>
<identitymapper/>
</firstmatchmapper>
</pathconvert>
<mkdir dir="${obfuscate.absolute.dir}" />
<delete file="${preobfuscate.jar.file}"/>
<delete file="${obfuscated.jar.file}"/>
<jar basedir="${out.classes.absolute.dir}"
destfile="${preobfuscate.jar.file}" />
<proguard>
@${proguard.config}
-injars ${project.jars}
-outjars "${obfuscated.jar.file}"
-libraryjars ${android.libraryjars}
-dump "${obfuscate.absolute.dir}/dump.txt"
-printseeds "${obfuscate.absolute.dir}/seeds.txt"
-printusage "${obfuscate.absolute.dir}/usage.txt"
-printmapping "${obfuscate.absolute.dir}/mapping.txt"
</proguard>
</then>
</if>
</target>
<!-- Converts this project's .class files into .dex files -->
<target name="-dex" depends="-compile, -post-compile, -obfuscate">
<do-only-if-manifest-hasCode elseText="hasCode = false. Skipping...">
<!-- only convert to dalvik bytecode is *not* a library -->
<do-only-if-not-library elseText="Library project: do not convert bytecode..." >
<!-- special case for instrumented builds: need to use no-locals and need
to pass in the emma jar. -->
<if condition="${build.is.instrumented}">
<then>
<dex-helper nolocals="true">
<external-libs>
<fileset file="${emma.dir}/emma_device.jar" />
</external-libs>
</dex-helper>
</then>
<else>
<dex-helper />
</else>
</if>
</do-only-if-not-library>
</do-only-if-manifest-hasCode>
</target>
<!-- Updates the pre-processed PNG cache -->
<target name="-crunch">
<exec executable="${aapt}" taskName="crunch">
<arg value="crunch" />
<arg value="-v" />
<arg value="-S" />
<arg path="${resource.absolute.dir}" />
<arg value="-C" />
<arg path="${out.res.absolute.dir}" />
</exec>
</target>
<!-- Puts the project's resources into the output package file
This actually can create multiple resource package in case
Some custom apk with specific configuration have been
declared in default.properties.
-->
<target name="-package-resources" depends="-crunch">
<!-- only package resources if *not* a library project -->
<do-only-if-not-library elseText="Library project: do not package resources..." >
<aapt executable="${aapt}"
command="package"
versioncode="${version.code}"
versionname="${version.name}"
debug="${build.is.packaging.debug}"
manifest="AndroidManifest.xml"
assets="${asset.absolute.dir}"
androidjar="${android.jar}"
apkfolder="${out.absolute.dir}"
nocrunch="${build.packaging.nocrunch}"
resourcefilename="${resource.package.file.name}"
resourcefilter="${aapt.resource.filter}"
projectLibrariesResName="project.libraries.res"
projectLibrariesPackageName="project.libraries.package"
previousBuildType="${build.last.target}"
buildType="${build.target}">
<res path="${out.res.absolute.dir}" />
<res path="${resource.absolute.dir}" />
<!-- <nocompress /> forces no compression on any files in assets or res/raw -->
<!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw -->
</aapt>
</do-only-if-not-library>
</target>
<!-- Packages the application. -->
<target name="-package" depends="-dex, -package-resources">
<!-- only package apk if *not* a library project -->
<do-only-if-not-library elseText="Library project: do not package apk..." >
<if condition="${build.is.instrumented}">
<then>
<package-helper>
<extra-jars>
<!-- Injected from external file -->
<jarfile path="${emma.dir}/emma_device.jar" />
</extra-jars>
</package-helper>
</then>
<else>
<package-helper />
</else>
</if>
</do-only-if-not-library>
</target>
<target name="-set-mode-check">
<fail if="out.final.file"
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." />
</target>
<!-- ********** Debug specific targets ********** -->
<target name="-set-debug-files" depends="-set-mode-check">
<property name="out.packaged.file" location="${out.absolute.dir}/${ant.project.name}-debug-unaligned.apk" />
<property name="out.final.file" location="${out.absolute.dir}/${ant.project.name}-debug.apk" />
</target>
<target name="-set-debug-mode">
<!-- record the current build target -->
<property name="build.target" value="debug" />
<property name="build.is.instrumented" value="false" />
<!-- whether the build is a debug build. always set. -->
<property name="build.is.packaging.debug" value="true" />
<!-- signing mode: debug -->
<property name="build.is.signing.debug" value="true" />
</target>
<target name="-debug-obfuscation-check">
<!-- proguard is never enabled in debug mode -->
<property name="proguard.enabled" value="false"/>
</target>
<!-- Builds debug output package -->
<target name="-do-debug" depends="-set-debug-mode, -debug-obfuscation-check, -package">
<!-- only create apk if *not* a library project -->
<do-only-if-not-library elseText="Library project: do not create apk..." >
<sequential>
<zipalign-helper in.package="${out.packaged.file}" out.package="${out.final.file}" />
<echo>Debug Package: ${out.final.file}</echo>
</sequential>
</do-only-if-not-library>
</target>
<!-- Builds debug output package -->
<target name="debug" depends="-set-debug-files, -do-debug"
description="Builds the application and signs it with a debug key.">
<record-build-info />
</target>
<!-- ********** Release specific targets ********** -->
<!-- called through target 'release'. Only executed if the keystore and
key alias are known but not their password. -->
<target name="-release-prompt-for-password" if="has.keystore" unless="has.password">
<!-- Gets passwords -->
<input
message="Please enter keystore password (store:${key.store}):"
addproperty="key.store.password" />
<input
message="Please enter password for alias '${key.alias}':"
addproperty="key.alias.password" />
</target>
<!-- called through target 'release'. Only executed if there's no
keystore/key alias set -->
<target name="-release-nosign" unless="has.keystore">
<!-- no release builds for library project -->
<do-only-if-not-library elseText="" >
<sequential>
<echo>No key.store and key.alias properties found in build.properties.</echo>
<echo>Please sign ${out.packaged.file} manually</echo>
<echo>and run zipalign from the Android SDK tools.</echo>
</sequential>
</do-only-if-not-library>
<record-build-info />
</target>
<target name="-release-obfuscation-check">
<condition property="proguard.enabled" value="true" else="false">
<and>
<isset property="build.is.mode.release" />
<isset property="proguard.config" />
</and>
</condition>
<if condition="${proguard.enabled}">
<then>
<!-- Secondary dx input (jar files) is empty since all the
jar files will be in the obfuscated jar -->
<path id="out.dex.jar.input.ref" />
</then>
</if>
</target>
<target name="-set-release-mode" depends="-set-mode-check">