sdk-targets.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Copyright (c) 2012 The Chromium Authors. All rights reserved.
  4. Use of this source code is governed by a BSD-style license that can be
  5. found in the LICENSE file.
  6. -->
  7. <project name="chrome_sdk_overrides" >
  8. <!--
  9. Redefinition of targets used by SDK tools.
  10. Supported version: SDK tools revision 20.
  11. SDK tools do not allow easy way of extending classpaths
  12. for aidl and javac. This file defines targets which can be used to
  13. override targets used by tools.
  14. -->
  15. <target name="-pre-compile">
  16. <!--
  17. Remove all .class files from the output directory. This prevents inclusion of incorrect .class
  18. files in the final apk. For example, if a .java file was deleted, the apk should not contain
  19. the .class files for that .java from previous builds.
  20. -->
  21. <delete>
  22. <fileset dir="${out.classes.absolute.dir}" includes="**/*.class"/>
  23. </delete>
  24. </target>
  25. <!--
  26. Override the -compile target.
  27. This target requires 'javac.custom.classpath' to be set to reference
  28. of classpath to be used for javac. Also accepts custom path for
  29. sources: 'javac.custom.sourcepath'.
  30. -->
  31. <target
  32. name="-compile"
  33. depends="-build-setup, -pre-build, -code-gen, -pre-compile">
  34. <do-only-if-manifest-hasCode elseText="hasCode = false. Skipping..." >
  35. <!-- If javac.srcdirs.additional isn't set, set it to an empty path. -->
  36. <if>
  37. <condition>
  38. <not>
  39. <isreference refid="javac.srcdirs.additional"/>
  40. </not>
  41. </condition>
  42. <then>
  43. <path id="javac.srcdirs.additional"/>
  44. </then>
  45. </if>
  46. <javac
  47. bootclasspathref="project.target.class.path"
  48. classpathref="javac.custom.classpath"
  49. debug="true"
  50. destdir="${out.classes.absolute.dir}"
  51. encoding="${java.encoding}"
  52. extdirs=""
  53. fork="${need.javac.fork}"
  54. includeantruntime="false"
  55. source="${java.source}"
  56. target="${java.target}"
  57. verbose="${verbose}">
  58. <src path="${source.absolute.dir}"/>
  59. <src path="${gen.absolute.dir}"/>
  60. <src>
  61. <path refid="javac.srcdirs.additional"/>
  62. </src>
  63. <compilerarg line="${java.compilerargs}"/>
  64. </javac>
  65. <!--
  66. If the project is instrumented, then instrument the classes
  67. TODO(shashishekhar): Add option to override emma filter.
  68. -->
  69. <if condition="${build.is.instrumented}">
  70. <then>
  71. <echo level="info">
  72. Instrumenting classes from ${out.absolute.dir}/classes...
  73. </echo>
  74. <!-- build the default filter to remove R, Manifest, BuildConfig -->
  75. <getemmafilter
  76. appPackage="${project.app.package}"
  77. filterOut="emma.default.filter"
  78. libraryPackagesRefId="project.library.packages"/>
  79. <!--
  80. Define where the .em file is output.
  81. This may have been setup already if this is a library.
  82. -->
  83. <property name="emma.coverage.absolute.file"
  84. location="${out.absolute.dir}/coverage.em"/>
  85. <!-- It only instruments class files, not any external libs -->
  86. <emma enabled="true">
  87. <instr
  88. instrpath="${out.absolute.dir}/classes"
  89. metadatafile="${emma.coverage.absolute.file}"
  90. mode="overwrite"
  91. outdir="${out.absolute.dir}/classes"
  92. verbosity="${verbosity}">
  93. <filter excludes="${emma.default.filter}"/>
  94. <filter value="${emma.filter}"/>
  95. </instr>
  96. </emma>
  97. </then>
  98. </if>
  99. <!--
  100. If the project needs a test jar then generate a jar containing
  101. all compiled classes and referenced jars.
  102. project.is.testapp is set by Android's ant build system based on the
  103. target's manifest. It is true only for instrumentation apks.
  104. -->
  105. <if condition="${project.is.testapp}">
  106. <then>
  107. <echo level="info">Creating test jar file:
  108. ${ant.project.name}-debug.jar</echo>
  109. <property-location name="create.test.jar.file"
  110. location="${CHROMIUM_SRC}/build/android/ant/create-test-jar.js"/>
  111. <script language="javascript" src="${create.test.jar.file}"/>
  112. </then>
  113. </if>
  114. </do-only-if-manifest-hasCode>
  115. </target>
  116. <!--
  117. For debug builds, the Android SDK tools create a key in ~/.android and sign the build with it.
  118. This has caused all kinds of issues. Instead, the debug build should be signed with a key in
  119. build/android/ant. The SDK tools do not provide any support for overriding that behavior and so
  120. instead one must use the hack below.
  121. -->
  122. <!-- Disables automatic signing. -->
  123. <property name="build.is.signing.debug" value="false"/>
  124. <!-- TODO(cjhopman): Remove this property when all gyp files define the CHROMIUM_SRC property. -->
  125. <property name="CHROMIUM_SRC" value="${PRODUCT_DIR}/../.." />
  126. <property name="key.store" value="${CHROMIUM_SRC}/build/android/ant/chromium-debug.keystore"/>
  127. <property name="key.store.password" value="chromium"/>
  128. <property name="key.alias" value="chromiumdebugkey"/>
  129. <property name="key.alias.password" value="chromium"/>
  130. <!-- SDK tools assume that out.packaged.file is signed and name it "...-unaligned" -->
  131. <property name="out.packaged.file"
  132. value="${apks.dir}/${ant.project.name}-debug-unsigned.apk" />
  133. <property name="out.unaligned.file"
  134. value="${apks.dir}/${ant.project.name}-debug-unaligned.apk" />
  135. <!-- By default, the SDK tools build only aligns the APK in the -do-debug target. -->
  136. <target name="-do-debug"
  137. depends="-set-debug-mode, -debug-obfuscation-check, -package, -post-package">
  138. <!-- only create apk if *not* a library project -->
  139. <do-only-if-not-library elseText="Library project: do not create apk..." >
  140. <sequential>
  141. <!-- Signs the APK -->
  142. <echo level="info">Signing final apk...</echo>
  143. <signapk
  144. input="${out.packaged.file}"
  145. output="${out.unaligned.file}"
  146. keystore="${key.store}"
  147. storepass="${key.store.password}"
  148. alias="${key.alias}"
  149. keypass="${key.alias.password}"/>
  150. <!-- Zip aligns the APK -->
  151. <zipalign-helper
  152. in.package="${out.unaligned.file}"
  153. out.package="${out.final.file}" />
  154. <echo level="info">Release Package: ${out.final.file}</echo>
  155. </sequential>
  156. </do-only-if-not-library>
  157. <record-build-info />
  158. </target>
  159. <path id="native.libs.gdbserver">
  160. <fileset file="${android.gdbserver}"/>
  161. </path>
  162. <target name="-post-compile">
  163. <!--
  164. Copy gdbserver to main libs directory if building a non-instrumentation debug apk.
  165. TODO(jrg): For now, Chrome on Android always builds native code
  166. as Release and java/ant as Debug, which means we always install
  167. gdbserver. Resolve this discrepancy, possibly by making this
  168. Release Official build java/ant as Release.
  169. -->
  170. <if>
  171. <condition>
  172. <and>
  173. <equals arg1="${build.target}" arg2="debug"/>
  174. <isfalse value="${project.is.testapp}"/>
  175. </and>
  176. </condition>
  177. <then>
  178. <echo message="Copying gdbserver to the apk to enable native debugging"/>
  179. <copy todir="${out.dir}/libs/${target.abi}">
  180. <path refid="native.libs.gdbserver"/>
  181. </copy>
  182. </then>
  183. </if>
  184. <!-- Package all the compiled .class files into a .jar. -->
  185. <jar
  186. jarfile="${lib.java.dir}/chromium_apk_${PACKAGE_NAME}.jar"
  187. basedir="${out.classes.absolute.dir}"
  188. />
  189. </target>
  190. <!--
  191. Override obfuscate target to pass javac.custom.classpath to Proguard. SDK tools do not provide
  192. any way to pass custom class paths to Proguard.
  193. -->
  194. <target name="-obfuscate">
  195. <if condition="${proguard.enabled}">
  196. <then>
  197. <property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard"/>
  198. <property name="preobfuscate.jar.file" value="${obfuscate.absolute.dir}/original.jar"/>
  199. <property name="obfuscated.jar.file" value="${obfuscate.absolute.dir}/obfuscated.jar"/>
  200. <!-- input for dex will be proguard's output -->
  201. <property name="out.dex.input.absolute.dir" value="${obfuscated.jar.file}"/>
  202. <!-- Add Proguard Tasks -->
  203. <property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar"/>
  204. <taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}"/>
  205. <!-- Set the android classpath Path object into a single property. It'll be
  206. all the jar files separated by a platform path-separator.
  207. Each path must be quoted if it contains spaces.
  208. -->
  209. <pathconvert property="project.target.classpath.value" refid="project.target.class.path">
  210. <firstmatchmapper>
  211. <regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/>
  212. <identitymapper/>
  213. </firstmatchmapper>
  214. </pathconvert>
  215. <!-- Build a path object with all the jar files that must be obfuscated.
  216. This include the project compiled source code and any 3rd party jar
  217. files. -->
  218. <path id="project.all.classes.path">
  219. <pathelement location="${preobfuscate.jar.file}"/>
  220. <path refid="project.all.jars.path"/>
  221. <!-- Pass javac.custom.classpath for apks. -->
  222. <path refid="javac.custom.classpath"/>
  223. </path>
  224. <!-- Set the project jar files Path object into a single property. It'll be
  225. all the jar files separated by a platform path-separator.
  226. Each path must be quoted if it contains spaces.
  227. -->
  228. <pathconvert property="project.all.classes.value" refid="project.all.classes.path">
  229. <firstmatchmapper>
  230. <regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/>
  231. <identitymapper/>
  232. </firstmatchmapper>
  233. </pathconvert>
  234. <!-- Turn the path property ${proguard.config} from an A:B:C property
  235. into a series of includes: -include A -include B -include C
  236. suitable for processing by the ProGuard task. Note - this does
  237. not include the leading '-include "' or the closing '"'; those
  238. are added under the <proguard> call below.
  239. -->
  240. <path id="proguard.configpath">
  241. <pathelement path="${proguard.config}"/>
  242. </path>
  243. <pathconvert pathsep='" -include "' property="proguard.configcmd"
  244. refid="proguard.configpath"/>
  245. <mkdir dir="${obfuscate.absolute.dir}"/>
  246. <delete file="${preobfuscate.jar.file}"/>
  247. <delete file="${obfuscated.jar.file}"/>
  248. <jar basedir="${out.classes.absolute.dir}"
  249. destfile="${preobfuscate.jar.file}"/>
  250. <proguard>
  251. -include "${proguard.configcmd}"
  252. -include "${out.absolute.dir}/proguard.txt"
  253. -injars ${project.all.classes.value}
  254. -outjars "${obfuscated.jar.file}"
  255. -libraryjars ${project.target.classpath.value}
  256. -dump "${obfuscate.absolute.dir}/dump.txt"
  257. -printseeds "${obfuscate.absolute.dir}/seeds.txt"
  258. -printusage "${obfuscate.absolute.dir}/usage.txt"
  259. -printmapping "${obfuscate.absolute.dir}/mapping.txt"
  260. </proguard>
  261. </then>
  262. </if>
  263. </target>
  264. </project>