More aggressive inlining, to inline some key methods like BitArray.get(), resulting...
[zxing.git] / android / build.xml
index 4226f61..57b6d53 100644 (file)
         </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"/>
   </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 value="--locals=${locals}"/>
+      <arg value="--positions=${positions}"/>
       <arg path="${outdir-classes}"/>
     </exec>
   </target>
@@ -199,4 +257,9 @@ only when the assets dir exists. -->
 
   <!-- Create the package file for this project from the sources. -->
   <target name="package" depends="package-dex"/>
+
+  <target name="clean">
+    <delete dir="${outdir}"/>
+  </target>
+
 </project>