包引用
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath>
<pathelement location="./lib/xmltask.jar" />
</classpath>
</taskdef>
<!-- 使用-->
<xmltask source="/src/main/AndroidManifest.xml" dest="src/main/AndroidManifest.xml">
<attr path="//manifest" attr="android:versionCode" value="175" />
</xmltask>
属性定义
<!-- basedir 自动识别为当前文件的路径 -->
<property name="loadDir" value="${basedir}/../" />
<property name="env" value="test" />
修改变量
<!-- basedir 自动识别为当前文件的路径 -->
<target name="init_env">
<!-- 注意:env必须是前面已经用property声明过的 -->
<var name="env" value="pro" />
</target>
任务声明, 可直接通过name调用
<target name="test1" >
<echo> test1</echo>
</target>
设置任务依赖
<target name="test1" depends="test2">
<echo> test1</echo>
</target>
<target name="test2" >
<echo> test2</echo>
</target>
<!-- 执行test1之前先执行test2 -->
修改文件内容
<target name="replace_key">
<!-- 替换环境变量 -->
<replace encoding="utf-8" dir="src/MainConfig">
<include name="SwitchSettion.h"/>
<replacefilter token="test" value="pro" />
</replace>
</target>
设置pod库bitcode为NO
<!-- 因为修改pod库的设置实际改动到的是Pods/Pods.xcodeproj/project.pbxproj文件, 可以通过内容匹配去修改相关设置 -->
<target name="bitcode">
<replaceregexp flags="gm">
<regexp pattern='(\s*)(ENABLE_BITCODE = (YES|NO);(\s*))*GCC_PREFIX_HEADER = "Target Support Files/FMDB/FMDB-prefix.pch";' />
<substitution expression='\1ENABLE_BITCODE = NO;\1GCC_PREFIX_HEADER = "Target Support Files/FMDB/FMDB-prefix.pch";'/>
<fileset dir="${project.path}/iphone/native/Pods/Pods.xcodeproj">
<include name="project.pbxproj" />
</fileset>
</replaceregexp>
</target>
条件判断
<condition property="env_test">
<equals arg1="test" arg2="test"/>
</condition>
<target name="build_test" if="env_test">
<echo> build_test </echo>
</target>
<!-- 输出: build_test -->
删除 拷贝
<target name="clean_ios">
<echo>Delete all generated file.</echo>
<delete includeEmptyDirs="true">
<fileset dir="path/env" includes="demo.ipa, demo.app.dSYM"/>
</delete>
<copy file="path/libhello-jni.so" todir="path/armeabi-v7a" overwrite="true"
/>
<copy tofile="path/a.apk" file="release.apk"></copy>
</target>
任务里调用其它任务
<target name="test">
<echo> test1 </echo>
<antcallback target="test2" />
</target>
<target name="test2">
<echo> test2 </echo>
</target>
<!-- 输出: test1 -->
<!-- 输出: test2 -->
上传文件到服务器
<ftp action="mkdir"
server="20.26.11.10"
userid="admin"
password="admin"
remotedir="/usr/apps"/>
<ftp server="20.26.11.10"
action="put"
passive="no"
remotedir="/usr/apps"
userid="admin"
password="admin">
<fileset dir="path/env"
includes = "*.apk"/>
</ftp>
获取当前时间
<tstamp prefix="time">
<format property="date" pattern="yyyyMMdd"/>
<format property="hourDate" pattern="yyyy-MM-dd HH:mm"/>
</tstamp>
<target name="test2">
<echo message="Change Date is ${time.hourDate}"/>
</target>
网友评论