这是如何完成的:
不要在 project.properties 文件中设置 proguard.config=proguard.cfg。
在您的 build.properties 文件集中
proguarded=on # or whatever variable you chose
如果您正在构建 Android,请定义这些宏,以便始终关闭调试:
<macrodef name="set-app-debuggable">
<sequential>
<echo>Updating AndroidManifest.xml with debuggable set to true</echo>
<replaceregexp file="./AndroidManifest.xml"
match='android:debuggable="(.*)"'
replace='android:debuggable="true"'
byline="false">
</replaceregexp>
</sequential>
</macrodef>
<macrodef name="set-app-not-debuggable">
<sequential>
<echo>Updating AndroidManifest.xml with debuggable set to false</echo>
<replaceregexp file="./AndroidManifest.xml"
match='android:debuggable="(.*)"'
replace='android:debuggable="false"'
byline="false">
</replaceregexp>
</sequential>
</macrodef>
然后设置这些条件或类似于这些条件,具体取决于您是否要在 proguard 构建之外保留调试:
<target name="-set-mode-check">
<echo> set mode checking properties ... </echo>
<echo> Proguard Property value is '${proguard.config}' </echo>
<echo> Proguard Property value is '${proguarded}' </echo>
<condition property="proguard.config" value="proguard.cfg">
<isset property="proguarded"/>
</condition>
<echo> Proguard Property value after condition set is '${proguard.config}' </echo>
<if condition="${proguarded}">
<then>
<echo>**** This build is proguarded so setting debuggable off ****</echo>
<set-app-not-debuggable />
</then>
<else>
<echo>**** This build is not proguarded so setting debuggable on ****</echo>
<set-app-debuggable />
</else>
</if>
</target>
根本不需要在 project.properties 文件中设置 proguard.config。