2

我正在寻找一种更新 xml 文件属性值的方法。例如下面的 xml 我想用另一个值替换属性值android:versionCode30003我很难理解 ant 如何使用替换或正则表达式来做到这一点。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.see"
    android:installLocation="auto"
    android:versionCode="30003"
    android:versionName="@string/app_version" >
</manifest>
4

1 回答 1

4

如果真的那么简单,您可以使用replaceregexp

<property name="newVersionCode" value="30004"/>
<replaceregexp file="${src}/AndroidManifest.xml"
               match='(android:versionCode=").*(")'
               replace="\1${newVersionCode}\2"
               byline="true"
/>

否则,您应该考虑使用XSLT 任务。您可能希望将原始文件复制到临时目录中,然后应用样式表,其中将新值指定为参数,并在原始清单上生成输出。

于 2012-12-12T01:59:37.453 回答