<target name="-release-obfuscation-check">
<echo level="info">proguard.config is ${proguard.config}</echo>
<condition property="proguard.enabled"
value="true" else="false">
<and>
<isset property="build.is.mode.release"
/>
<isset property="proguard.config"
/>
</and>
</condition>
<if condition="${proguard.enabled}">
<then>
<echo level="info">Proguard.config
is enabled</echo>
<!-- Secondary dx input (jar files)
is empty since all the
jar files will be in the obfuscated
jar -->
<path id="out.dex.jar.input.ref" />
</then>
</if>
</target>
proguard.enabled的依據就是在release模式下,並且設置proguard.config這個屬性
簽名規則:簽名過程中需要檢查keystore和密碼
<target name="-release-sign" if="has.keystore"
>
<!-- only create apk if *not* a library project -->
<do-only-if-not-library elseText="Library project: do not create
apk..." >
<sequential>
<property name="out.unaligned.file" location="${out.absolute.dir}/${ant.project.name}-release-unaligned.apk"
/>
<!-- Signs the APK -->
<echo level="info">Signing final apk...</echo>
<signapk
input="${out.packaged.file}"
output="${out.unaligned.file}"
keystore="${key.store}"
storepass="${key.store.password}"
alias="${key.alias}"
keypass="${key.alias.password}"/>
<!-- Zip aligns the APK -->
<zipalign-helper
in.package="${out.unaligned.file}"
out.package="${out.final.file}" />
<echo level="info">Release Package: ${out.final.file}</echo>
</sequential>
</do-only-if-not-library>
<record-build-info />
</target>
自定義打包規則:
在 build.xml 中導入自定義的打包規則的文件,
<import file="custom_rules.xml" optional="true" />
然後
可根據 release中的規則和順序(depends="-set-release-mode, -release-obfuscation-check, -package, -post-package, -release-prompt-for-password, -release-nosign, -release-sign, -post-build"),自定義自己的規則。
在custom_rules.xml中
重新實現這些字段對應的規則方法。一般都在最後一項“-post-bulid”中完成。
如xxxxx項目中,在編譯之前先檢查libs庫中的.so文件是否一致
和 簽名採用自己的簽名服務器去做等。實現代碼如下:
classname="com.netease.apkchecker.AllSoChecker"
classpath="apkchecker.jar" />
<target name="-post-build" depends="custom_sign,protect" >
<SoChecker apkPath="${out.final.file}" />