Changed the project names for the two Android clients to disambiguate them.
[zxing.git] / android / build.xml
index 5a92331..49d21aa 100644 (file)
@@ -1,5 +1,4 @@
-<?xml version="1.0" ?>
-
+<?xml version="1.0" encoding="UTF-8"?>
 <!--
  Copyright (C) 2008 Google Inc.
 
 
 <!-- This is a mildly hacked version of the auto-generated project
      build.xml file. -->
-<project name="BarcodeReader" default="package">
+<project name="BarcodeReaderM5" default="package">
   <property file="../build.properties"/>
   <property name="sdk-folder" value="${android-home}"/>
   <property name="android-tools" value="${sdk-folder}/tools"/>
+  <property name="android-framework" value="${android-tools}/lib/framework.aidl"/>
 
   <!-- The intermediates directory -->
   <!-- Eclipse uses "bin" for its own output, so we do the same. -->
   <property name="intermediate-dex" value="${outdir}/${dex-file}"/>
 
   <!-- The final package file to generate -->
-  <property name="out-package" value="${outdir}/${ant.project.name}.apk"/>
+  <property name="out-package" value="${outdir}/BarcodeReader.apk"/>
 
   <!-- Tools -->
   <property name="aapt" value="${android-tools}/aapt"/>
   <property name="aidl" value="${android-tools}/aidl"/>
   <property name="dx" value="${android-tools}/dx"/>
+  <property name="adb" value="${android-tools}/adb" />
+  <property name="android-jar" value="${sdk-folder}/android.jar" />
   <property name="zip" value="zip"/>
-  <property name="android-jar" value="${sdk-folder}/android.jar"/>
 
   <!-- Rules -->
 
         </not>
       </condition>
     </fail>
+    <fail message="Please put proguard.jar in 'bin' under the WTK install directory">
+      <condition>
+        <and>
+          <not>
+            <isset property="debug"/>
+          </not>
+          <not>
+            <available file="${WTK-home}/bin/proguard.jar" type="file"/>
+          </not>
+        </and>
+      </condition>
+    </fail>
   </target>
 
   <!-- Create the output directories if they don't exist yet. -->
 
   <!-- Generate the R.java file for this project's resources. -->
   <target name="resource-src" depends="dirs">
+
+    <copy file="strings.xml.template" tofile="res/values/strings.xml" overwrite="true">
+      <filterset>
+        <filter token="VERSION" value="${version}"/>
+      </filterset>
+    </copy>
+
     <echo>Generating R.java...</echo>
     <exec executable="${aapt}" failonerror="true">
       <arg value="compile"/>
   <!-- Generate java classes from .aidl files. -->
   <target name="aidl" depends="dirs">
     <apply executable="${aidl}" failonerror="true">
+      <arg value="-p${android-framework}"/>
+      <arg value="-I${srcdir}"/>
       <fileset dir="${srcdir}">
         <include name="**/*.aidl"/>
       </fileset>
   </target>
 
   <!-- Compile this project's .java files into .class files. -->
-  <target name="compile" depends="init, dirs, resource-src, aidl">
-    <javac encoding="ascii" target="1.5" debug="true" extdirs=""
+  <target name="compile" depends="init, clean, dirs, resource-src, aidl">
+    <javac encoding="ascii" target="1.5" debug="true" optimize="true" extdirs=""
            srcdir="."
            destdir="${outdir-classes}"
            bootclasspath="${android-jar}">
     <unzip src="../core/core.jar" dest="${outdir-classes}"/>
   </target>
 
+  <target name="optimize" depends="compile" unless="debug">
+    <jar basedir="${outdir-classes}" destfile="temp.jar"/>
+    <java jar="${WTK-home}/bin/proguard.jar" fork="true" failonerror="true">
+     <jvmarg value="-Dmaximum.inlined.code.length=32"/>
+     <arg value="-injars temp.jar"/>
+     <arg value="-outjars optimized.jar"/>
+     <arg value="-libraryjars ${android-jar}"/>
+     <arg value="-dontpreverify"/>
+     <arg value="-dontobfuscate"/>
+     <arg value="-keep public class com.google.zxing.client.android.BarcodeReaderCaptureActivity"/>
+     <arg value="-optimizationpasses 7"/>
+     <arg value="-overloadaggressively"/>
+     <arg value="-verbose"/>
+   </java>
+   <delete file="temp.jar"/>
+   <delete dir="${outdir-classes}"/>
+   <mkdir dir="${outdir-classes}"/>
+   <unzip src="optimized.jar" dest="${outdir-classes}"/>
+   <delete file="optimized.jar"/>
+  </target>
+
   <!-- Convert this project's .class files into .dex files. -->
-  <target name="dex" depends="compile">
+  <target name="dex" depends="compile, optimize">
+
+    <condition property="locals" value="full">
+      <isset property="debug"/>
+    </condition>
+    <condition property="locals" value="none">
+      <not>
+        <isset property="debug"/>
+      </not>
+    </condition>
+    <condition property="positions" value="lines">
+      <isset property="debug"/>
+    </condition>
+    <condition property="positions" value="none">
+      <not>
+        <isset property="debug"/>
+      </not>
+    </condition>
+
     <exec executable="${dx}" failonerror="true">
       <arg value="-JXmx384M"/>
       <arg value="--dex"/>
       <arg value="--output=${intermediate-dex}"/>
-      <arg value="--locals=full"/>
-      <arg value="--positions=lines"/>
-      <arg path="${outdir-classes}"/>
+      <arg value="--locals=${locals}"/>
+      <arg value="--positions=${positions}"/>
+      <arg path="${basedir}/${outdir-classes}"/>
     </exec>
   </target>
 
@@ -187,7 +248,11 @@ only when the assets dir exists. -->
          update="true"/>
   </target>
 
-  <!-- Put the project's .dex files into the output package file. -->
+  <!-- Put the project's .dex files into the output package file.
+       Use the "zip" command, available on most un*x/Linux/MacOS systems,
+       to create the new package (Ant 1.7 has an internal 'zip' command,
+       however Ant 1.6.5 lacks it and is still widely installed.)
+  -->
   <target name="package-dex" depends="dex, package-res">
     <echo>Packaging dex...</echo>
     <exec executable="${zip}" failonerror="true">
@@ -200,6 +265,15 @@ only when the assets dir exists. -->
   <!-- Create the package file for this project from the sources. -->
   <target name="package" depends="package-dex"/>
 
+  <!-- Install package on the default emulator -->
+  <target name="install">
+    <echo>Sending package to default emulator...</echo>
+    <exec executable="${adb}" failonerror="true">
+      <arg value="install" />
+      <arg value="${out-package}" />
+    </exec>
+  </target>
+
   <target name="clean">
     <delete dir="${outdir}"/>
   </target>