Advertisement
Guest User

Untitled

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