1 <?xml version="1.0" encoding="UTF-8"?> 2 <!-- 3 Copyright (C) 2005-2008 The Android Open Source Project 4 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, software 12 distributed under the License is distributed on an "AS IS" BASIS, 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 See the License for the specific language governing permissions and 15 limitations under the License. 16 --> 17 18 <project default="-obfuscate"> 19 <property name="verbose" value="false" /> 20 <property name="out.dir" location="${OUT_DIR}" /> 21 <!-- Output directories --> 22 <property name="out.dir" value="bin" /> 23 <property name="out.absolute.dir" location="${out.dir}" /> 24 <property name="out.classes.absolute.dir" location="${out.dir}/classes" /> 25 <property name="out.manifest.abs.file" location="${out.dir}/AndroidManifest.xml" /> 26 27 <!-- tools location --> 28 <property name="sdk.dir" location="${ANDROID_SDK_ROOT}"/> 29 <property name="android.tools.dir" location="${sdk.dir}/tools" /> 30 31 <property name="project.target.android.jar" location="${ANDROID_SDK_JAR}" /> 32 <path id="project.target.class.path"> 33 <pathelement location="${project.target.android.jar}" /> 34 </path> 35 36 37 <!-- jar file from where the tasks are loaded --> 38 <path id="android.antlibs"> 39 <pathelement path="${sdk.dir}/tools/lib/ant-tasks.jar" /> 40 </path> 41 42 <!-- Custom tasks --> 43 <taskdef resource="anttasks.properties" classpathref="android.antlibs" /> 44 45 <!-- Classpath for javac --> 46 <path id="javac.custom.classpath"> 47 <filelist files="${INPUT_JARS_PATHS}"/> 48 </path> 49 50 <condition property="project.is.testapp" value="true" else="false"> 51 <equals arg1="${IS_TEST_APK}" arg2="1" /> 52 </condition> 53 54 <property name="proguard.enabled" value="${PROGUARD_ENABLED}" /> 55 <property name="proguard.config" value="${PROGUARD_FLAGS}" /> 56 57 <!-- Obfuscate target 58 This is only active in release builds when proguard.config is defined 59 in default.properties. 60 61 --> 62 <!-- 63 Override obfuscate target to pass javac.custom.classpath to Proguard. SDK tools do not provide 64 any way to pass custom class paths to Proguard. 65 --> 66 <target name="-obfuscate"> 67 <if condition="${project.is.testapp}"> 68 <then> 69 <!-- get the project manifest package --> 70 <xpath input="${out.manifest.abs.file}" 71 expression="/manifest/@package" output="project.app.package" /> 72 <loadresource property="project.app.packagepath"> 73 <propertyresource name="project.app.package"/> 74 <filterchain> 75 <replacestring from="." to="/"/> 76 </filterchain> 77 </loadresource> 78 <property name="create.test.jar.exclusions" value="${project.app.packagepath}/R.class ${project.app.packagepath}/R$*.class ${project.app.packagepath}/Manifest.class ${project.app.packagepath}/Manifest$*.class ${project.app.packagepath}/BuildConfig.class"/> 79 <jar destfile="${TEST_JAR_PATH}" 80 excludes="${create.test.jar.exclusions}" 81 duplicate="preserve" 82 > 83 <restrict> 84 <name name="**/*.class"/> 85 <archives> 86 <zips> 87 <path refid="javac.custom.classpath"/> 88 </zips> 89 </archives> 90 </restrict> 91 <fileset dir="${out.dir}/classes"/> 92 </jar> 93 </then> 94 </if> 95 <if> 96 <condition> 97 <and> 98 <istrue value="${proguard.enabled}"/> 99 <equals arg1="${CONFIGURATION_NAME}" arg2="Release"/> 100 </and> 101 </condition> 102 <then> 103 <property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard"/> 104 <property name="preobfuscate.jar.file" value="${obfuscate.absolute.dir}/original.jar"/> 105 <property name="obfuscated.jar.file" value="${OBFUSCATED_JAR_PATH}"/> 106 <property name="obfuscated.jar.abs.file" location="${obfuscated.jar.file}"/> 107 108 <!-- Add Proguard Tasks --> 109 <property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar"/> 110 <taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}"/> 111 112 <!-- Set the android classpath Path object into a single property. It'll be 113 all the jar files separated by a platform path-separator. 114 Each path must be quoted if it contains spaces. 115 --> 116 <pathconvert property="project.target.classpath.value" refid="project.target.class.path"> 117 <firstmatchmapper> 118 <regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/> 119 <identitymapper/> 120 </firstmatchmapper> 121 </pathconvert> 122 123 <!-- Build a path object with all the jar files that must be obfuscated. 124 This include the project compiled source code and any 3rd party jar 125 files. --> 126 <path id="project.all.classes.path"> 127 <pathelement location="${preobfuscate.jar.file}"/> 128 <!-- Pass javac.custom.classpath for apks. --> 129 <path refid="javac.custom.classpath"/> 130 </path> 131 <!-- Set the project jar files Path object into a single property. It'll be 132 all the jar files separated by a platform path-separator. 133 Each path must be quoted if it contains spaces. 134 --> 135 <pathconvert property="project.all.classes.value" refid="project.all.classes.path"> 136 <firstmatchmapper> 137 <regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/> 138 <identitymapper/> 139 </firstmatchmapper> 140 </pathconvert> 141 142 <!-- Turn the path property ${proguard.config} from an A:B:C property 143 into a series of includes: -include A -include B -include C 144 suitable for processing by the ProGuard task. Note - this does 145 not include the leading '-include "' or the closing '"'; those 146 are added under the <proguard> call below. 147 --> 148 <path id="proguard.configpath"> 149 <filelist files="${proguard.config}"/> 150 </path> 151 <pathconvert pathsep='" -include "' property="proguard.configcmd" 152 refid="proguard.configpath"/> 153 154 <mkdir dir="${obfuscate.absolute.dir}"/> 155 <delete file="${preobfuscate.jar.file}"/> 156 <delete file="${obfuscated.jar.abs.file}"/> 157 <jar basedir="${out.classes.absolute.dir}" 158 destfile="${preobfuscate.jar.file}"/> 159 <proguard> 160 -include "${proguard.configcmd}" 161 -include "${out.absolute.dir}/proguard.txt" 162 -injars ${project.all.classes.value} 163 -outjars "${obfuscated.jar.abs.file}" 164 -libraryjars ${project.target.classpath.value} 165 -dump "${obfuscate.absolute.dir}/dump.txt" 166 -printseeds "${obfuscate.absolute.dir}/seeds.txt" 167 -printusage "${obfuscate.absolute.dir}/usage.txt" 168 -printmapping "${obfuscate.absolute.dir}/mapping.txt" 169 </proguard> 170 </then> 171 </if> 172 <touch file="${STAMP}" /> 173 </target> 174 </project> 175