Changed ProGuard settings so it will inline methods which use private members. This...
[zxing.git] / android-m3 / build.xml
1 <?xml version="1.0" ?>
2
3 <!--
4  Copyright (C) 2008 Google Inc.
5
6  Licensed under the Apache License, Version 2.0 (the "License");
7  you may not use this file except in compliance with the License.
8  You may obtain a copy of the License at
9
10       http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17  -->
18
19 <!-- This is a mildly hacked version of the auto-generated project
20      build.xml file. -->
21 <project name="BarcodeReaderM3" default="package">
22   <property file="../build.properties"/>
23   <property name="sdk-folder" value="${android-m3-home}"/>
24   <property name="android-tools" value="${sdk-folder}/tools"/>
25
26   <!-- The intermediates directory -->
27   <!-- Eclipse uses "bin" for its own output, so we do the same. -->
28   <property name="outdir" value="bin"/>
29
30   <!-- No user servicable parts below. -->
31
32   <!-- Input directories -->
33   <property name="resource-dir" value="res"/>
34   <property name="asset-dir" value="assets"/>
35   <property name="srcdir" value="src"/>
36
37   <!-- Output directories -->
38   <property name="outdir-classes" value="${outdir}/classes"/>
39
40   <!-- Create R.java in the source directory -->
41   <property name="outdir-r" value="src"/>
42
43   <!-- Intermediate files -->
44   <property name="dex-file" value="classes.dex"/>
45   <property name="intermediate-dex" value="${outdir}/${dex-file}"/>
46
47   <!-- The final package file to generate -->
48   <property name="out-package" value="${outdir}/BarcodeReader.apk"/>
49
50   <!-- Tools -->
51   <property name="aapt" value="${android-tools}/aapt"/>
52   <property name="aidl" value="${android-tools}/aidl"/>
53   <property name="dx" value="${android-tools}/dx"/>
54   <property name="zip" value="zip"/>
55   <property name="android-jar" value="${sdk-folder}/android.jar"/>
56
57   <!-- Rules -->
58
59   <target name="init">
60     <tstamp/>
61     <fail message="Please set 'android-m3-home' in build.properties">
62       <condition>
63         <not>
64           <available file="${android-m3-home}" type="dir"/>
65         </not>
66       </condition>
67     </fail>
68     <fail message="Please build 'core' first">
69       <condition>
70         <not>
71           <available file="../core/core.jar" type="file"/>
72         </not>
73       </condition>
74     </fail>
75     <fail message="Please put proguard.jar in 'bin' under the WTK install directory">
76       <condition>
77         <and>
78           <not>
79             <isset property="debug"/>
80           </not>
81           <not>
82             <available file="${WTK-home}/bin/proguard.jar" type="file"/>
83           </not>
84         </and>
85       </condition>
86     </fail>
87   </target>
88
89   <!-- Create the output directories if they don't exist yet. -->
90   <target name="dirs">
91     <mkdir dir="${outdir}"/>
92     <mkdir dir="${outdir-classes}"/>
93   </target>
94
95   <!-- Generate the R.java file for this project's resources. -->
96   <target name="resource-src" depends="dirs">
97
98     <copy file="strings.xml.template" tofile="res/values/strings.xml" overwrite="true">
99       <filterset>
100         <filter token="VERSION" value="${version}"/>
101       </filterset>
102     </copy>
103
104     <echo>Generating R.java...</echo>
105     <exec executable="${aapt}" failonerror="true">
106       <arg value="compile"/>
107       <arg value="-m"/>
108       <arg value="-J"/>
109       <arg value="${outdir-r}"/>
110       <arg value="-M"/>
111       <arg value="AndroidManifest.xml"/>
112       <arg value="-S"/>
113       <arg value="${resource-dir}"/>
114       <arg value="-I"/>
115       <arg value="${android-jar}"/>
116     </exec>
117   </target>
118
119   <!-- Generate java classes from .aidl files. -->
120   <target name="aidl" depends="dirs">
121     <apply executable="${aidl}" failonerror="true">
122       <fileset dir="${srcdir}">
123         <include name="**/*.aidl"/>
124       </fileset>
125     </apply>
126   </target>
127
128   <!-- Compile this project's .java files into .class files. -->
129   <target name="compile" depends="init, clean, dirs, resource-src, aidl">
130     <javac encoding="ascii" target="1.5" debug="true" optimize="true" extdirs=""
131            srcdir="."
132            destdir="${outdir-classes}"
133            bootclasspath="${android-jar}">
134       <classpath>
135         <pathelement location="../core/core.jar"/>
136       </classpath>
137     </javac>
138     <unzip src="../core/core.jar" dest="${outdir-classes}"/>
139   </target>
140
141   <target name="optimize" depends="compile" unless="debug">
142     <jar basedir="${outdir-classes}" destfile="temp.jar"/>
143     <java jar="${WTK-home}/bin/proguard.jar" fork="true" failonerror="true">
144       <jvmarg value="-Dmaximum.inlined.code.length=32"/>
145       <arg value="-injars temp.jar"/>
146       <arg value="-outjars optimized.jar"/>
147       <arg value="-libraryjars ${android-jar}"/>
148       <arg value="-dontpreverify"/>
149       <arg value="-dontobfuscate"/>
150       <!-- Temporary workaround to keep important stuff in the client, while inlining core. -->
151       <arg value="-keep class com.google.zxing.client.android.BarcodeReaderCaptureActivity { *; }"/>
152       <arg value="-keep class com.google.zxing.client.android.CameraManager { *; }"/>
153       <arg value="-keep class com.google.zxing.client.android.CameraThread { *; }"/>
154       <arg value="-optimizationpasses 7"/>
155       <arg value="-overloadaggressively"/>
156       <arg value="-verbose"/>
157       <!-- Needed to allow getters which refer to private members to be inlined. -->
158       <arg value="-allowaccessmodification"/>
159     </java>
160     <delete file="temp.jar"/>
161     <delete dir="${outdir-classes}"/>
162     <mkdir dir="${outdir-classes}"/>
163     <unzip src="optimized.jar" dest="${outdir-classes}"/>
164     <delete file="optimized.jar"/>
165   </target>
166
167   <!-- Convert this project's .class files into .dex files. -->
168   <target name="dex" depends="compile, optimize">
169
170     <condition property="locals" value="full">
171       <isset property="debug"/>
172     </condition>
173     <condition property="locals" value="none">
174       <not>
175         <isset property="debug"/>
176       </not>
177     </condition>
178     <condition property="positions" value="lines">
179       <isset property="debug"/>
180     </condition>
181     <condition property="positions" value="none">
182       <not>
183         <isset property="debug"/>
184       </not>
185     </condition>
186
187     <exec executable="${dx}" failonerror="true">
188       <arg value="-JXmx384M"/>
189       <arg value="--dex"/>
190       <arg value="--optimize"/>
191       <arg value="--output=${intermediate-dex}"/>
192       <arg value="--locals=${locals}"/>
193       <arg value="--positions=${positions}"/>
194       <arg path="${outdir-classes}"/>
195     </exec>
196   </target>
197
198   <!-- Put the project's resources into the output package file. -->
199   <target name="package-res-and-assets">
200     <echo>Packaging resources and assets...</echo>
201     <exec executable="${aapt}" failonerror="true">
202       <arg value="package"/>
203       <arg value="-f"/>
204       <arg value="-c"/>
205       <arg value="-M"/>
206       <arg value="AndroidManifest.xml"/>
207       <arg value="-S"/>
208       <arg value="${resource-dir}"/>
209       <arg value="-A"/>
210       <arg value="${asset-dir}"/>
211       <arg value="-I"/>
212       <arg value="${android-jar}"/>
213       <arg value="${out-package}"/>
214     </exec>
215   </target>
216
217   <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
218   <target name="package-res-no-assets">
219     <echo>Packaging resources...</echo>
220     <exec executable="${aapt}" failonerror="true">
221       <arg value="package"/>
222       <arg value="-f"/>
223       <arg value="-c"/>
224       <arg value="-M"/>
225       <arg value="AndroidManifest.xml"/>
226       <arg value="-S"/>
227       <arg value="${resource-dir}"/>
228       <!-- No assets directory -->
229       <arg value="-I"/>
230       <arg value="${android-jar}"/>
231       <arg value="${out-package}"/>
232     </exec>
233   </target>
234
235   <!-- Invoke the proper target depending on whether or not
236 an assets directory is present. -->
237   <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
238 only when the assets dir exists. -->
239   <target name="package-res">
240     <available file="${asset-dir}" type="dir"
241                property="res-target" value="and-assets"/>
242     <property name="res-target" value="no-assets"/>
243     <antcall target="package-res-${res-target}"/>
244   </target>
245
246   <!-- Put the project's .class files into the output package file. -->
247   <target name="package-java" depends="compile, package-res">
248     <echo>Packaging java...</echo>
249     <jar destfile="${out-package}"
250          basedir="${outdir-classes}"
251          update="true"/>
252   </target>
253
254   <!-- Put the project's .dex files into the output package file. -->
255   <target name="package-dex" depends="dex, package-res">
256     <echo>Packaging dex...</echo>
257     <exec executable="${zip}" failonerror="true">
258       <arg value="-qj"/>
259       <arg value="${out-package}"/>
260       <arg value="${intermediate-dex}"/>
261     </exec>
262   </target>
263
264   <!-- Create the package file for this project from the sources. -->
265   <target name="package" depends="package-dex"/>
266
267   <target name="clean">
268     <delete dir="${outdir}"/>
269   </target>
270
271 </project>