(转)Android 自动 打包
这个主要就是用ant+proguard+签名来实现自动打包的,一些解释都在代码里,在这里就不多说了,现在开始把上代码吧。
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <project name="xiyou_base_" default="deployableAllDevice"> 4 <!-- proguard4的路径 --> 5 6 <property name="proguard.home" value="D:/software/j2me/proguard4.5.1/proguard4.5.1"/> 7 <!-- sdk的路径 --> 8 <property name="sdk.dir" value="E:\dev\android-sdk-windows"/> 9 <!-- 是否使用签名 --> 10 <property name="has.keystore" value="true" /> 11 <!-- 签名密码 --> 12 <property name="has.password" value="true" /> 13 <!--签名相关的key --> 14 <property name="key.alias" value="key.keystore" /> 15 <property name="key.store" value="key.keystore" /> 16 <!-- 签名相关的密码 --> 17 <property name="key.store.password" value="xxxx" /> 18 <property name="key.alias.password" value="xxxx" /> 19 20 21 <!-- 22 default.properties 内容 23 target=android-4 24 proguard.config=proguard.cfg 25 --> 26 27 <property file="default.properties" /> 28 29 <!-- Custom Android task to deal with the project target, and import the 30 proper rules. 31 This requires ant 1.6.0 or above. --> 32 33 <path id="android.antlibs"> 34 <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" /> 35 36 <pathelement path="${sdk.dir}/tools/lib/sdklib.jar" /> 37 <pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" /> 38 </path> 39 <taskdef name="setup" classname="com.android.ant.SetupTask" classpathref="android.antlibs" /> 40 <setup import="false" /> 41 42 <!-- Custom tasks --> 43 <taskdef name="aapt" classname="com.android.ant.AaptExecLoopTask" classpathref="android.antlibs" /> 44 <taskdef name="aidl" classname="com.android.ant.AidlExecTask" classpathref="android.antlibs" /> 45 <taskdef name="apkbuilder" classname="com.android.ant.ApkBuilderTask" classpathref="android.antlibs" /> 46 <taskdef name="xpath" classname="com.android.ant.XPathTask" classpathref="android.antlibs" /> 47 <taskdef name="if" classname="com.android.ant.IfElseTask" classpathref="android.antlibs" /> 48 <!-- Properties --> 49 <!-- Tells adb which device to target. You can change this from the command line 50 by invoking "ant -Dadb.device.arg=-d" for device "ant -Dadb.device.arg=-e" for 51 the emulator. --> 52 <property name="adb.device.arg" value="" /> 53 <property name="android.tools.dir" location="${sdk.dir}/tools" /> 54 <property name="android.platform.tools.dir" location="${sdk.dir}/platform-tools" /> 55 <!-- Name of the application package extracted from manifest file --> 56 <xpath input="AndroidManifest.xml" expression="/manifest/@package" output="manifest.package" /> 57 58 <!-- Value of the hasCode attribute (Application node) extracted from manifest file --> 59 <xpath input="AndroidManifest.xml" expression="/manifest/application/@android:hasCode" output="manifest.hasCode" default="true" /> 60 <!-- 源文件及资源路径 --> 61 <property name="source.dir" value="src" /> 62 <property name="source.absolute.dir" location="${source.dir}" /> 63 <property name="gen.dir" value="gen" /> 64 <property name="gen.absolute.dir" location="${gen.dir}" /> 65 <property name="resource.dir" value="res" /> 66 <property name="resource.absolute.dir" location="${resource.dir}" /> 67 <property name="asset.dir" value="assets" /> 68 <property name="asset.absolute.dir" location="${asset.dir}" /> 69 <!-- Directory for the third party java libraries --> 70 <property name="jar.libs.dir" value="libs" /> 71 <property name="jar.libs.absolute.dir" location="${jar.libs.dir}" /> 72 <!-- create a path with all the jar files, from the main project and the 73 libraries --> 74 <path id="jar.libs.ref"> 75 <fileset dir="${jar.libs.absolute.dir}" includes="*.jar" /> 76 <path refid="project.libraries.jars" /> 77 </path> 78 <!-- Directory for the native libraries --> 79 <property name="native.libs.dir" value="libs" /> 80 <property name="native.libs.absolute.dir" location="${native.libs.dir}" /> 81 <!-- 输出路径 --> 82 <property name="out.dir" value="out" /> 83 <property name="out.absolute.dir" location="${out.dir}" /> 84 <property name="out.classes.dir" value="${out.absolute.dir}/classes" /> 85 <property name="out.classes.absolute.dir" location="${out.classes.dir}" /> 86 <!-- Intermediate files --> 87 <property name="dex.file.name" value="classes.dex" /> 88 <property name="intermediate.dex.file" location="${out.absolute.dir}/${dex.file.name}" /> 89 <property name="resource.package.file.name" value="${ant.project.name}.ap_" /> 90 91 <!-- The final package file to generate 92 93 These can be overridden by setting them earlier to 94 95 different values --> 96 97 <property name="out.debug.unaligned.file" location="${out.absolute.dir}/${ant.project.name}-debug-unaligned.apk" /> 98 99 <property name="out.debug.file" location="${out.absolute.dir}/${ant.project.name}-debug.apk" /> 100 101 <property name="out.unsigned.file.name" value="${ant.project.name}-unsigned.apk" /> 102 103 <property name="out.unsigned.file" location="${out.absolute.dir}/${out.unsigned.file.name}" /> 104 105 <property name="out.unaligned.file.name" value="${ant.project.name}-unaligned.apk" /> 106 107 <property name="out.unaligned.file" location="${out.absolute.dir}/${out.unaligned.file.name}" /> 108 109 <property name="out.release.file.name" value="${ant.project.name}-release.apk" /> 110 111 <property name="out.release.file" location="${out.absolute.dir}/${out.release.file.name}" /> 112 113 <property name="proguard.enabled" value="true" /> 114 115 <property name="android-jar" value="${sdk.dir}/platforms/${target}/android.jar" /> 116 117 <!-- set some properties used for filtering/override. If those weren't defined 118 119 before, then this will create them with empty values, which are then ignored 120 121 by the custom tasks receiving them. --> 122 123 <property name="version.code" value="" /> 124 125 <property name="aapt.resource.filter" value="" /> 126 127 <property name="filter.abi" value="" /> 128 129 <!-- java源文件编码,编译的目标平台,为1.5 or 1.6都可以 --> 130 131 <property name="java.encoding" value="UTF-8" /> 132 133 <property name="java.target" value="1.5" /> 134 135 <property name="java.source" value="1.5" /> 136 <!-- Verbosity --> 137 <property name="verbose" value="false" /> 138 <!-- Verbosity --> 139 <property name="verbose" value="false" /> 140 <!-- This is needed by emma as it uses multilevel verbosity instead of simple 'true' or 'false' 141 The property 'verbosity' is not user configurable and depends exclusively on 'verbose' 142 value.--> 143 <condition property="verbosity" value="verbose" else="quiet"> 144 <istrue value="${verbose}" /> 145 </condition> 146 <!-- This is needed to switch verbosity of zipalign. Depends exclusively on 'verbose' 147 --> 148 <condition property="v.option" value="-v" else=""> 149 <istrue value="${verbose}" /> 150 </condition> 151 <!-- This is needed to switch verbosity of dx. Depends exclusively on 'verbose' --> 152 <condition property="verbose.option" value="--verbose" else=""> 153 <istrue value="${verbose}" /> 154 </condition> 155 <!-- properties for signing in release mode --> 156 <condition property="has.keystore" value="true"> 157 <and> 158 <isset property="key.store" /> 159 <length string="${key.store}" when="greater" length="0" /> 160 <isset property="key.alias" /> 161 </and> 162 </condition> 163 <condition property="has.password" value="passwordxxxxx"> 164 <and> 165 <isset property="has.keystore" /> 166 <isset property="key.store.password" /> 167 <isset property="key.alias.password" /> 168 </and> 169 </condition> 170 <!-- Tools --> 171 <condition property="exe" value=".exe" else=""> 172 <os family="windows" /> 173 </condition> 174 <property name="adb" location="${android.platform.tools.dir}/adb${exe}" /> 175 <property name="zipalign" location="${android.tools.dir}/zipalign${exe}" /> 176 <!-- Emma configuration --> 177 <property name="emma.dir" value="${sdk.dir}/tools/lib" /> 178 <path id="emma.lib"> 179 <pathelement location="${emma.dir}/emma.jar" /> 180 <pathelement location="${emma.dir}/emma_ant.jar" /> 181 </path> 182 <taskdef resource="emma_ant.properties" classpathref="emma.lib" /> 183 <!-- End of emma configuration --> 184 <!-- Macros --> 185 <!-- Configurable macro, which allows to pass as parameters output directory, 186 output dex filename and external libraries to dex (optional) --> 187 <macrodef name="dex-helper"> 188 <element name="external-libs" optional="yes" /> 189 <element name="extra-parameters" optional="yes" /> 190 <sequential> 191 <!-- sets the primary input for dex. If a pre-dex task sets it to 192 something else this has no effect --> 193 <property name="out.dex.input.absolute.dir" value="${out.classes.absolute.dir}" /> 194 <!-- set the secondary dx input: the project (and library) jar files 195 If a pre-dex task sets it to something else this has no effect --> 196 <if> 197 <condition> 198 <isreference refid="out.dex.jar.input.ref" /> 199 </condition> 200 <else> 201 <path id="out.dex.jar.input.ref"> 202 <path refid="jar.libs.ref" /> 203 </path> 204 </else> 205 </if> 206 <echo>Converting compiled files and external libraries into ${intermediate.dex.file}…</echo> 207 <apply executable="${dx}" failonerror="true" parallel="true"> 208 <arg value="--dex" /> 209 <arg value="--output=${intermediate.dex.file}" /> 210 <extra-parameters /> 211 <arg line="${verbose.option}" /> 212 <arg path="${out.dex.input.absolute.dir}" /> 213 <path refid="out.dex.jar.input.ref" /> 214 <external-libs /> 215 </apply> 216 </sequential> 217 </macrodef> 218 219 <!-- This is macro that enable passing variable list of external jar files to ApkBuilder 220 Example of use: 221 <package-helper output.filepath="/path/to/foo.apk"> 222 <extra-jars> 223 <jarfolder path="my_jars" /> 224 <jarfile path="foo/bar.jar" /> 225 <jarfolder path="your_jars" /> 226 </extra-jars> 227 </package-helper> --> 228 <macrodef name="package-helper"> 229 <attribute name="output.filepath" /> 230 <element name="extra-jars" optional="yes" /> 231 <sequential> 232 <apkbuilder outfolder="${out.absolute.dir}" resourcefile="${resource.package.file.name}" apkfilepath="@{output.filepath}" debugpackaging="${build.packaging.debug}" debugsigning="${build.signing.debug}" abifilter="${filter.abi}" verbose="${verbose}" hascode="${manifest.hasCode}"> 233 <dex path="${intermediate.dex.file}" /> 234 <sourcefolder path="${source.absolute.dir}" /> 235 <sourcefolder refid="project.libraries.src" /> 236 <jarfolder path="${jar.libs.absolute.dir}" /> 237 <jarfolder refid="project.libraries.libs" /> 238 <nativefolder path="${native.libs.absolute.dir}" /> 239 <nativefolder refid="project.libraries.libs" /> 240 <extra-jars /> 241 </apkbuilder> 242 </sequential> 243 </macrodef> 244 <!-- This is macro which zipaligns in.package and outputs it to out.package. Used by targets 245 debug, -debug-with-emma and release.--> 246 <macrodef name="zipalign-helper"> 247 <attribute name="in.package" /> 248 <attribute name="out.package" /> 249 <sequential> 250 <echo>Running zip align on final apk…</echo> 251 <exec executable="${zipalign}" failonerror="true"> 252 <arg line="${v.option}" /> 253 <arg value="-f" /> 254 <arg value="4" /> 255 <arg path="@{in.package}" /> 256 <arg path="@{out.package}" /> 257 </exec> 258 </sequential> 259 </macrodef> 260 <!-- This is macro used only for sharing code among two targets, -install and 261 -install-with-emma which do exactly the same but differ in dependencies --> 262 <macrodef name="install-helper"> 263 <sequential> 264 <echo>Installing ${out.debug.file} onto default emulator or device…</echo> 265 <exec executable="${adb}" failonerror="true"> 266 <arg line="${adb.device.arg}" /> 267 <arg value="install" /> 268 <arg value="-r" /> 269 <arg path="${out.debug.file}" /> 270 </exec> 271 </sequential> 272 </macrodef> 273 <!-- Rules --> 274 <!-- Creates the output directories if they don't exist yet. --> 275 <target name="-dirs"> 276 <echo>Creating output directories if needed…</echo> 277 <mkdir dir="${resource.absolute.dir}" /> 278 <mkdir dir="${jar.libs.absolute.dir}" /> 279 <mkdir dir="${out.absolute.dir}" /> 280 <if condition="${manifest.hasCode}"> 281 <then> 282 <mkdir dir="${gen.absolute.dir}" /> 283 <mkdir dir="${out.classes.absolute.dir}" /> 284 </then> 285 </if> 286 </target> 287 <!-- empty default pre-compile target. Create a similar target in 288 your build.xml and it'll be called instead of this one. --> 289 <target name="-pre-compile" /> 290 <!-- Compiles this project's .java files into .class files. --> 291 <target name="compile" depends="-resource-src, -aidl, -pre-compile" description="Compiles project's .java files into .class files"> 292 <if condition="${manifest.hasCode}"> 293 <then> 294 <!-- If android rules are used for a test project, its classpath should include 295 tested project's location --> 296 <condition property="extensible.classpath" value="${tested.project.absolute.dir}/${out.dir}/classes" else="."> 297 <isset property="tested.project.absolute.dir" /> 298 </condition> 299 <condition property="extensible.libs.classpath" value="${tested.project.absolute.dir}/libs" else="${jar.libs.dir}"> 300 <isset property="tested.project.absolute.dir" /> 301 </condition> 302 <javac encoding="${java.encoding}" source="${java.source}" target="${java.target}" debug="true" extdirs="" destdir="${out.classes.absolute.dir}" bootclasspathref="android.target.classpath" verbose="${verbose}" classpath="${extensible.classpath}" classpathref="jar.libs.ref"> 303 <src path="${source.absolute.dir}" /> 304 <src path="${gen.absolute.dir}" /> 305 <src refid="project.libraries.src" /> 306 <classpath> 307 <fileset dir="${extensible.libs.classpath}" includes="*.jar" /> 308 </classpath> 309 </javac> 310 </then> 311 <else> 312 <echo>hasCode = false. Skipping…</echo> 313 </else> 314 </if> 315 </target> 316 <!-- empty default post-compile target. Create a similar target in 317 your build.xml and it'll be called instead of this one. --> 318 <target name="-post-compile" /> 319 <!-- Obfuscate target 320 This is only active in release builds when proguard.config is defined 321 in default.properties. 322 To replace Proguard with a different obfuscation engine: 323 Override the following targets in your build.xml, before the call to <setup> 324 -release-obfuscation-check 325 Check whether obfuscation should happen, and put the result in a property. 326 -debug-obfuscation-check 327 Obfuscation should not happen. Set the same property to false. 328 -obfuscate 329 ** Make sure unless="do.not.compile" is used in the target definition ** 330 check if the property set in -debug/release-obfuscation-check is set to true. 331 If true: 332 Perform obfuscation 333 Set property out.dex.input.absolute.dir to be the output of the obfuscation 334 --> 335 <target name="-obfuscate" unless="do.not.compile"> 336 <if condition="${proguard.enabled}"> 337 <then> 338 <property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard" /> 339 <property name="preobfuscate.jar.file" value="${obfuscate.absolute.dir}/original.jar" /> 340 <property name="obfuscated.jar.file" value="${obfuscate.absolute.dir}/obfuscated.jar" /> 341 <!-- input for dex will be proguard's output --> 342 <property name="out.dex.input.absolute.dir" value="${obfuscated.jar.file}" /> 343 344 <!-- Add Proguard Tasks --> 345 <property name="proguard.jar" location="${proguard.home}/lib/proguard.jar" /> 346 <taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" /> 347 348 <!-- Set the android classpath Path object into a single property. It'll be 349 all the jar files separated by a platform path-separator. 350 --> 351 352 <property name="android.libraryjars" refid="android.target.classpath" /> 353 <!-- Build a path object with all the jar files that must be obfuscated. 354 This include the project compiled source code and any 3rd party jar files. --> 355 356 <path id="project.jars.ref"> 357 <pathelement location="${preobfuscate.jar.file}" /> 358 <path refid="jar.libs.ref" /> 359 </path> 360 361 <!-- Set the project jar files Path object into a single property. It'll be 362 all the jar files separated by a platform path-separator. 363 --> 364 365 <property name="project.jars" refid="project.jars.ref" /> 366 <mkdir dir="${obfuscate.absolute.dir}" /> 367 <delete file="${preobfuscate.jar.file}" /> 368 <delete file="${obfuscated.jar.file}" /> 369 <jar basedir="${out.classes.dir}" destfile="${preobfuscate.jar.file}" /> 370 <!-- 混淆相关参数 --> 371 <proguard> 372 -optimizationpasses 5 373 -dontusemixedcaseclassnames 374 -dontskipnonpubliclibraryclasses 375 -dontpreverify 376 -verbose 377 -repackageclasses 378 -allowaccessmodification 379 -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 380 -keep public class * extends android.app.Activity 381 -keep public class * extends android.app.Application 382 -keep public class * extends android.app.Service 383 -keep public class * extends android.content.BroadcastReceiver 384 -keep public class * extends android.content.ContentProvider 385 -keep public class com.android.vending.licensing.ILicensingService 386 -injars ${project.jars} 387 -outjars ${obfuscated.jar.file} 388 -libraryjars ${android.libraryjars} 389 </proguard> 390 </then> 391 </if> 392 </target> 393 <target name="pre" depends="-obfuscate"> 394 </target> 395 396 <!-- Converts this project's .class files into .dex files --> 397 <!--<target name="-dex" depends="compile, -post-compile, -obfuscate" unless="do.not.compile">--> 398 <target name="-dex" depends="compile, -post-compile, optimize" unless="do.not.compile"> 399 <if condition="${manifest.hasCode}"> 400 <then> 401 <dex-helper /> 402 </then> 403 <else> 404 <echo>hasCode = false. Skipping…</echo> 405 </else> 406 </if> 407 </target> 408 <target name="optimize" depends="compile,-obfuscate"> 409 <if condition="${proguard.enabled}"> 410 <then> 411 <mkdir dir="${out.dir}/out/class" /> 412 <!-- 创建文件夹--> 413 <!--别人的<jar basedir="${out-folder}" destfile="temp.jar"/>--> 414 <property name="proguard-jar" value="${proguard.home}/lib/proguard.jar" /> 415 <java jar="${proguard-jar}" fork="true" failonerror="true"> 416 <jvmarg value="-Dmaximum.inlined.code.length=32" /> 417 <arg value="-injars ${out.dir}/classes" /> 418 <!-- 原来的类文件,使用Bin/classes下的--> 419 <arg value="-outjars ${out.dir}/out/classes" /> 420 <!-- 生成的混淆Class位置--> 421 <arg value="-libraryjars ${android-jar}" /> 422 <!-- 423 <arg value=" -libraryjars ${library-jar}/some_lib_used.jar"/> 424 --> 425 <arg value="-keep public class * extends android.app.Activity" /> 426 <arg value="-keep public class * extends android.app.Service" /> 427 <arg value="-keep public class * extends android.content.BroadcastReceiver" /> 428 <arg value="-keep public class * extends android.content.ContentProvider" /> 429 <arg value="-keep public class * extends android.view.View" /> 430 <arg value="-dontwarn" /> 431 <arg value="-dontpreverify" /> 432 <arg value="-optimizationpasses 7" /> 433 <arg value="-dontusemixedcaseclassnames" /> 434 <arg value="-dontskipnonpubliclibraryclasses" /> 435 <arg value="-repackageclasses" /> 436 <arg value="-allowaccessmodification" /> 437 <!--<arg value="-dontskipnonpubliclibraryclassmembers"/>--> 438 </java> 439 440 <!--这些是原来的Jar<delete file="temp.jar"/>--> 441 <!--<delete dir="${out-folder}"/>--> 442 <!--<mkdir dir="${out-folder}"/> 443 <unzip src="optimized.jar" dest="${out-folder}"/> 444 <delete file="optimized.jar"/>--> 445 </then> 446 </if> 447 </target> 448 <!-- Puts the project's resources into the output package file 449 This actually can create multiple resource package in case 450 Some custom apk with specific configuration have been 451 declared in default.properties. 452 --> 453 <target name="-package-resources"> 454 <echo>Packaging resources</echo> 455 <aapt executable="${aapt}" command="package" versioncode="${version.code}" debug="${build.packaging.debug}" manifest="AndroidManifest.xml" assets="${asset.absolute.dir}" androidjar="${android.jar}" apkfolder="${out.absolute.dir}" resourcefilename="${resource.package.file.name}" resourcefilter="${aapt.resource.filter}"> 456 <res path="${resource.absolute.dir}" /> 457 <!-- <nocompress /> forces no compression on any files in assets or res/raw --> 458 <!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw --> 459 </aapt> 460 </target> 461 <!-- Packages the application and sign it with a debug key. --> 462 <target name="-package-debug-sign" depends="-dex, -package-resources"> 463 <package-helper output.filepath="${out.debug.unaligned.file}" /> 464 </target> 465 <!-- Packages the application without signing it. --> 466 <target name="-package-release" depends="-dex, -package-resources"> 467 <package-helper output.filepath="${out.unsigned.file}" /> 468 </target> 469 <target name="-compile-tested-if-test" if="tested.project.dir" unless="do.not.compile.again"> 470 <subant target="compile"> 471 <fileset dir="${tested.project.absolute.dir}" includes="build.xml" /> 472 </subant> 473 </target> 474 <target name="-debug-obfuscation-check"> 475 <!-- proguard is never enabled in debug mode --> 476 <property name="proguard.enabled" value="true" /> 477 </target> 478 <target name="-set-debug-mode" depends="-debug-obfuscation-check"> 479 <!-- property only set in debug mode. 480 Useful for if/unless attributes in target node 481 when using Ant before 1.8 --> 482 <property name="build.mode.debug" value="true" /> 483 <!-- whether the build is a debug build. always set. --> 484 <property name="build.packaging.debug" value="true" /> 485 <!-- signing mode: debug --> 486 <property name="build.signing.debug" value="true" /> 487 </target> 488 489 <!-- Builds debug output package, provided all the necessary files are already dexed --> 490 <target name="debug" depends="-set-debug-mode, -compile-tested-if-test, -package-debug-sign" description="Builds the application and signs it with a debug key."> 491 <zipalign-helper in.package="${out.debug.unaligned.file}" out.package="${out.debug.file}" /> 492 <echo>Debug Package: ${out.debug.file}</echo> 493 </target> 494 <!-- called through target 'release'. Only executed if the keystore and 495 key alias are known but not their password. --> 496 <target name="-release-prompt-for-password" if="has.keystore" unless="has.password"> 497 <!-- Gets passwords --> 498 <echo>Gets passwords ${has.keystore} ${has.password}</echo> 499 <input message="Please enter keystore password (store:${key.store}):" addproperty="key.store.password" defaultvalue="5201314" /> 500 <input message="Please enter password for alias '${key.alias}':" addproperty="key.alias.password" defaultvalue="5201314" /> 501 </target> 502 <!-- called through target 'release'. Only executed if there's no 503 keystore/key alias set --> 504 <target name="-release-nosign" unless="has.keystore"> 505 <echo>No key.store and key.alias properties found in build.properties.</echo> 506 <echo>Please sign ${out.unsigned.file} manually</echo> 507 <echo>and run zipalign from the Android SDK tools.</echo> 508 </target> 509 <target name="-release-obfuscation-check"> 510 <condition property="proguard.enabled" value="true" else="false"> 511 <and> 512 <isset property="build.mode.release" /> 513 <isset property="proguard.config" /> 514 </and> 515 </condition> 516 517 <if condition="${proguard.enabled}"> 518 <then> 519 <!-- Secondary dx input (jar files) is empty since all the 520 jar files will be in the obfuscated jar --> 521 <path id="out.dex.jar.input.ref" /> 522 </then> 523 </if> 524 </target> 525 <target name="-set-release-mode"> 526 <!-- release mode is only valid if the manifest does not explicitly 527 set debuggable to true. default is false. 528 We actually store build.packaging.debug, not build.release --> 529 <xpath input="AndroidManifest.xml" expression="/manifest/application/@android:debuggable" output="build.packaging.debug" default="false" /> 530 <!-- signing mode: release --> 531 <property name="build.signing.debug" value="false" /> 532 <if condition="${build.packaging.debug}"> 533 <then> 534 <echo>*************************************************</echo> 535 <echo>**** Android Manifest has debuggable=true ****</echo> 536 <echo>**** Doing DEBUG packaging with RELEASE keys ****</echo> 537 <echo>*************************************************</echo> 538 </then> 539 <else> 540 <!-- property only set in release mode. 541 Useful for if/unless attributes in target node 542 when using Ant before 1.8 --> 543 <property name="build.mode.release" value="true" /> 544 </else> 545 </if> 546 </target> 547 548 <!-- This runs -package-release and -release-nosign first and then runs 549 only if release-sign is true (set in -release-check, 550 called by -release-no-sign)--> 551 <target name="release" depends="-set-release-mode, -release-obfuscation-check, -package-release, -release-prompt-for-password, -release-nosign" if="has.keystore" description="Builds the application. The generated apk file must be signed before 552 it is published."> 553 <!-- Signs the APK --> 554 <echo>Signing final apk…</echo> 555 <signjar jar="${out.unsigned.file}" signedjar="${out.unaligned.file}" keystore="${key.store}" storepass="${key.store.password}" alias="${key.alias}" keypass="${key.alias.password}" verbose="${verbose}" /> 556 <!-- Zip aligns the APK --> 557 <zipalign-helper in.package="${out.unaligned.file}" out.package="${out.release.file}" /> 558 <echo>Release Package: ${out.release.file}</echo> 559 </target> 560 <target name="clean" description="Removes output files created by other targets."> 561 <delete dir="${out.absolute.dir}" verbose="${verbose}" /> 562 <delete dir="${gen.absolute.dir}" verbose="${verbose}" /> 563 </target> 564 <target name="deployableAllDevice" description="build all device packet"> 565 <!-- uid和sdk都是自定义参数,可有可无,有多小个包要打,就在这里copy多小行,修改相关参数,传入到程序里即可 --> 566 <antcall target="release" inheritAll="true"><param name="uid" value="100" /><param name="sdk" value="91" /></antcall> 567 <antcall target="release" inheritAll="true"><param name="uid" value="101" /><param name="sdk" value="90" /></antcall> 568 </target> 569 </project>