不确定我是否理解正确,但这是我用来为平板电脑和手机构建不同 apk 的脚本:
<?xml version="1.0" encoding="UTF-8"?>
<property file="local.properties" />
<property environment="env" />
<property name="temp.dir" location="bin/temp" />
<property name="resource.absolute.dir" location="${temp.dir}/res" />
<property name="resource.source.dir" location="res" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<loadproperties srcFile="project.properties" />
<fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable." unless="sdk.dir" />
<import file="${sdk.dir}/tools/ant/build.xml" />
<macrodef name="prepare-temp-dir">
<attribute name="target" default="phone" />
<sequential>
<delete dir="${temp.dir}" />
<mkdir dir="${temp.dir}" />
<mkdir dir="${resource.absolute.dir}" />
<!-- Probably should rewrite this with ant-contrib -->
<if>
<condition>
<and>
<equals arg1="@{target}" arg2="phone" />
</and>
</condition>
<then>
<copy todir="${resource.absolute.dir}">
<fileset dir="${resource.source.dir}" casesensitive="no">
<exclude name="/*sw600dp*/**" />
<exclude name="/*large*/*" />
<exclude name="/*xlarge*/*" />
</fileset>
</copy>
</then>
<else>
<if>
<condition>
<and>
<equals arg1="@{target}" arg2="tablet" />
</and>
</condition>
<then>
<copy todir="${resource.absolute.dir}">
<fileset dir="${resource.source.dir}" casesensitive="no">
<exclude name="/*small*/**" />
<exclude name="/*normal*/*" />
</fileset>
</copy>
</then>
</if>
</else>
</if>
</sequential>
</macrodef>
<macrodef name="clean-temp-dir">
<sequential>
<delete dir="${temp.dir}" />
</sequential>
</macrodef>
<target name="release-phone">
<echo message="Starting build procedure for target 'phone'" />
<prepare-temp-dir target="phone" />
<clean-temp-dir />
</target>
<target name="release-tablet">
<echo message="Starting build procedure for target 'tablet'" />
<prepare-temp-dir target="tablet" />
<clean-temp-dir />
</target>
它只是扩展了标准的 android build.xml 并稍微修改了它。构建开始时,我创建一个临时目录并复制目标所需的所有资源,然后从该临时目录构建。
现在它只是分隔可绘制文件夹,但您可以轻松调整它以实现您的目标