Android Ant Build.xml Instance

Source: Internet
Author: User
Tags create directory

Use ant to compile apk. You only need to modify the SKD path Javahome path and project path when using it.
<?xml version= "1.0" encoding= "UTF-8"? ><project name= "Scolview" default= "Zipalign" basedir= "." ><property name= "EXE" value= ". exe"/><property name= "Bat" value= ". bat"/><!--the local path of each tool used, be sure to modify it! --><!--android_home The installation directory for ANDROIDSDK on this machine--><property name= "Android_home" value= "f:/ Adt-bundle-windows-x86_64-20140624/sdk "/><!--the root directory of the project--><property name=" root "value=" F:/andoridADT/ Workspace/scolview "/><!--javahome Directory--<property name=" Javahome "value=" C:/Program Files/Java/jdk1.6.0 _45 "></property> <!--Android SDK version number, 18 means Android 4.3--><property name=" Android_api_level "value=" "/><!--the location of the Android.jar package in the ANDROID_SDK directory--<property name=" Androidjar "value=" ${android_home}/ Platforms/android-${android_api_level}/android.jar "/> <!--native Javac directory--><property name=" Javac "value= "${javahome}/bin/javac.exe"/><!--aapt for production R.java and packaging resource resources--><property name= "AAPT" value= "${ Android_home}/build-tools/18.0.1/aapt${exe} "/><!--DX is used to package A. class file (plus a third-party library and A. class file) into a. dex file--><property name=" DX " Value= "${android_home}/build-tools/18.1.1/dx.bat"/><!-- Apkbuilder is used to package. dex files and packaged resource files (AAPT packaged) and other resource files into an apk file--><property name= "Apkbuilder" value= "${android_home }/tools/apkbuilder${bat} "/><!--zipalign is used to optimize the APK, not required step--><property name=" zipalign "value=" ${android _home}/tools/zipalign${exe} "/><!--the various folders involved in the packaging process--><!--bin file to store the files needed for the APK package (. Dex,resource.ap_,.class, Androidmanifest.xml, etc.) and the resulting apk--><property name= "out" value= "${root}/dest"/><!--Gen is mainly used for storing R.java, Under Eclipse for auto-generation, ant AAPT tool generates--><property name= "gen" value= "Gen"/><!--the directory where the Javac generated class files are stored-->< Property Name= "Classes" value= "${out}/classes"/><!--stored. Directory of Java source files--><property name= "src" value= "src"/ ><!--Store the referenced library directory--><property name= "Lib" value= "${out}/libs"/><!--the encoding format when packaging--><property name = "Encoding" value= "UTF-8"/><!--generate the name of the APKWord--><property name= "file_name" value= "Scollview"/> <!--signature Warehouse, generated Keytool--><property by Name= " KeyStore "value=" ${root}/edsheng.keystore "/><!--need to set the signature name--><property name=" Key_name "value=" Edsheng "/ ><!--need to set--><property name= "Key_pass" value= "a199210311"/><!--need to set--><property name= " Store_pass "value=" a199210311 "/><!--the location of the jar package used for signing--><property name=" Jarsigner "value=" ${javahome}/bin/ Jarsigner.exe "/><!--the steps to actually compile the APK! 1. Clear the output path of the file (overwriting the original packaging result) 2. Create a folder that requires output 3. Call the AAPT tool to generate R.java file 4. Call Javac to compile the Java file into a Java bytecode (. class file) 5. Call Dx.bat to the third-party library file that the. class file and other calls to Compiling into a. dex file (. dex files can be run directly on the Dalvik virtual machine file format, can be understood as the Java bytecode for embedded device optimization) 6. Call the Apkbuilder tool to generate the. dex file and the resource file under the Bin directory (AAPT, such as Resource.ap _) packaged into APK7. Call Jarsigner for the previous 8. Call Zipalign for performance improvement--><!--The following is the actual packaging process--><!--1. Clear the output path of the file (overwriting the original packaging results)- <target name= "mkdir" > <echo> Generate output Folder ... </echo> <mkdir dir= "${out}" ></mkdir> <echo> generation complete </echo></target>&Lt;target name= "clean" depends= "mkdir" ><echo> cleanup output directory ...</echo> <delete dir= "${out}"/><delet E dir= "${gen}"/> <echo> cleanup complete </echo></target><target name= "init" depends= "clean" ><echo > Create output directory ... </echo><mkdir dir= "${out}"/><mkdir dir= "${gen}"/><mkdir dir= "${classes}"/> <mkdir dir= "${lib}"/><echo> Create directory completion </echo></target><!--aapt specific parameters meaning see:/http blog.csdn.net/liuhe688/article/details/6679879--><!--generate R.java file for the project resource--><target name= "GEN" depends= " Init "><echo> generate R.java from resource file ... </echo><exec executable=" ${aapt} "failonerror=" true "><arg Value= "Package"/><arg value= "-M"/><arg value= "-j"/><arg value= "${gen}"/><arg value= "-M"/ ><arg value= "Androidmanifest.xml"/><arg value= "-S"/><arg value= "res"/><arg value= "-i"/> <arg value= "${androidjar}"/></exec><echo>r.java file generated successfully </echo></target><!--Javac The specific parameters of the meaning see: http://cyf0110.iteye.com/blog/1508991--><target name= "Compile" Depends= "Gen" ><echo> start compiling. class files ... </echo><javac fork= "true" executable= "${javac}" encoding= "${            encoding} "debug=" true "extdirs=" "source=" 1.5 "target=" 1.5 "destdir=" ${classes} "bootclasspath=" ${androidjar} "> <src path= "${src}"/> <src path= "${gen}"/> <classpath> <f Ileset dir= "${root}/libs" includes= "*.jar"/> </classpath> </javac><echo>.class file compilation Complete </echo></target><!--carry out Android's own tool Dx.bat used to package. class files and third-party libraries into Dex files--><!--The Apply tag can be found in: HTTPS ://ant.apache.org/manual/tasks/apply.html--><target name= "dex" depends= "compile" ><echo> compile. dex file    ... </echo><apply executable= "${DX}" failonerror= "true" parallel= "true" > <arg value= "-jxms1024m"/> <arg value= "-jxmx1536m"/> <arg value= "-jxss1024k"/&GT;&LT;arg value= "--dex"/><arg value= "--num-threads=4"/><arg value= "--output=${out}/classes.dex"/>< Arg path= "${classes}"/><fileset dir= "${lib}" > <include name= "*.jar"/> </f Ileset></apply><echo> compiling the. dex file complete </echo></target><!--The resource file for the packaged project--><target name = "Package_res_with_assets" ><echo> packaging resources and asset files ... </echo><exec executable= "${aapt}" failonerror= " True "><arg value=" package "/><arg value="-F "/><arg value="-M "/><arg value=" Androidmanifest.xml "/><arg value="-S "/><arg value=" res "/><arg value="-A "/><arg value=" Assets "/><arg value="-i "/><arg value=" ${androidjar} "/><arg value="-F "/><arg value=" ${out}/ ${FILE_NAME}.AP_ "/></exec><echo> packaging resources and asset files complete </echo></target><target name=" apk " Depends= "Dex, package_res_with_assets" ><echo> start packing apk...</echo><exec executable= "${apkbuilder} "failonerror=" true "><arg value=" ${out}/${file_name}_unsigned.apk "/><arg value="-U "/> <arg value= "-Z"/><arg value= "${OUT}/${FILE_NAME}.AP_"/><arg value= "-F"/><arg value= "${out}/ Classes.dex "/><arg value="-RF "/><arg value=" ${root}/src "/><arg value="-RJ "/><arg value=" ${ Root}/libs "/><arg value="-nf "/><arg value=" ${root}/libs "/></exec><echo> successfully packaged apk</ echo></target><!--call Jarsigner for signature--><target name= "sign" depends= "APK" ><echo> start signing ... </echo><exec executable= "${jarsigner}" failonerror= "true" ><arg value= "-verbose"/><arg value= " -sigalg "/><arg value=" Md5withrsa "/><arg value="-digestalg "/><arg value=" SHA1 "/><arg value= "-keystore"/><arg value= "${keystore}"/><arg value= "-storepass"/><arg value= "${store_pass}"/> <arg value= "-keypass"/><arg value= "${key_pass}"/><arg value= "-Signedjar "/><arg value=" ${out}/${file_name}_signed_unzipalign.apk "/><arg value=" ${out}/${file_name}_ unsigned.apk "/><arg value=" ${key_name} "/></exec><echo> Signature success </echo></target>< !--Call the Zipalign tool to optimize the package after the signature--><!--is to optimize the byte alignment of the resource, and reduce the ram--><!--during memory run http://developer.android.com/ Tools/help/zipalign.html--><target name= "zipalign" depends= "sign" ><echo> start optimization ...</echo>< EXEC executable= "${zipalign}" failonerror= "true" ><arg value= "-V"/><arg value= "4"/><arg value= "${ out}/${file_name}_signed_unzipalign.apk "/><arg value=" ${out}/${file_name}_signed_zipaligned.apk "/>< /exec><echo> End optimization </echo><echo> purge data generated during compilation ... </echo><delete dir= "${out}/classes" > </delete><echo> erase Data Complete ... </echo></target></project>

Android Ant Build.xml Instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.