Build Script for a Unity Android Project

Having learned how to integrate my Android code and resources with Unity, I went looking for a way to simplify the migration of my files to my Unity project. (I found repeatedly exporting a JAR and copying over the manifest and resource directories painful.) The result was this Ant script, which drops the class files, manifest, and resources directly into my Unity project.

<project default="build">
  <!-- Set this to your top-level Unity project directory! -->
  <property
    name="project.dir"
    value="D:/rezcycle" />

  <!-- All Android files will be placed inside Assets/Plugins/Android. No 
    need to touch this. -->
  <property
    name="assets.dir"
    value="${project.dir}/Assets/Plugins/Android" />

  <target name="build">
    <!-- Make the assets directory in our project. -->
    <mkdir dir="${assets.dir}" />

    <!-- Copy over the manifest. -->
    <copy
      file="AndroidManifest.xml"
      todir="${assets.dir}" />

    <!-- Copy over the raw files in res/ and assets/. -->
    <copy todir="${assets.dir}">
      <fileset
        dir="."
        includes="res/**" />
      <fileset
        dir="."
        includes="assets/**" />
    </copy>

    <!-- Produce a JAR file of all your pre-compiled classes. Don't bring 
      R stuff. -->
    <jar destfile="${assets.dir}/custom_android.jar">
      <fileset
        dir="bin/classes"
        excludes="**/R.class,**/R$*.class" />
    </jar>
  </target>
</project>

I drop this in to my top-level Android project directory in Eclipse, naming it build.xml. Eclipse knows how to run Ant files, so I simply run as “Ant Build”.

Comments

  1. linfeng says:

    sorry my English not good ,i have a issue ask you,i use command line build an android project for untiy3D . next i want to build APK ,how can i do this.

Leave a Reply

Your email address will not be published. Required fields are marked *