1

I have a script to filter src, res, libs etc. (based on the device type) from Android project folder to another specific folders. For example type 1 and type 2 device will have following structure after running the script.

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

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

I have to write a script to make build using the above folder names. I tried out ant release command but it's throwing Java compilation error.

I like to know is there any command/script where I can pass path of src, res, lib, asset and manifest file as parameters and can build project.

2
  • Geez. "throwing Java compilation error". quote that damn error. Nobody told you error messages ARE useful in debugging process? Commented Jan 23, 2013 at 11:52
  • I am not able to get error details. Commented Jan 23, 2013 at 12:15

1 Answer 1

1

Not sure if I understood you correctly, but here's my script I use to build different apks for tablets and phones:

<?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>

It just extends standard android build.xml and slightly modifies it. When build starts, I create a temp dir and copy all the resources I need for the target, then build from that temp dir.

Right now it just separates drawable folders, but you can tweak it easily to accomplish your goals

Sign up to request clarification or add additional context in comments.

1 Comment

I did the same to separate Src, res and rest of files. Facing issue in compiling during build.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.