1

src、res、libsなど(デバイスタイプに基づく)をAndroidプロジェクトフォルダーから別の特定のフォルダーにフィルター処理するスクリプトがあります。たとえば、タイプ1とタイプ2のデバイスは、スクリプトの実行後に次の構造になります。

Device_Type_1
  \src
  \res
  \libs
  \assets
  \AndroidManifest.xml

Device_Type_2
  \src
  \res
  \libs
  \assets
  \AndroidManifest.xml

上記のフォルダ名を使用してビルドするスクリプトを作成する必要があります。ant releaseコマンドを試しましたが、Javaコンパイルエラーが発生します。

src、res、lib、asset、manifestファイルのパスをパラメーターとして渡し、プロジェクトをビルドできるコマンド/スクリプトがあることを知りたいです。

4

1 に答える 1

1

私があなたを正しく理解したかどうかはわかりませんが、タブレットと電話用にさまざまな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 &apos;android update project&apos; 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>

標準のandroidbuild.xmlを拡張し、わずかに変更します。ビルドが開始したら、一時ディレクトリを作成し、ターゲットに必要なすべてのリソースをコピーしてから、その一時ディレクトリからビルドします。

今のところ、描画可能なフォルダを分離するだけですが、目標を達成するために簡単に調整できます

于 2013-01-23T11:57:17.893 に答える