Ant编译编译APK、打包打包JS
Base on Apache Ant 1.8.4

一、Apache Ant

维基百科:http://zh.wikipedia.org/wiki/Apache_Ant
下载地址:http://ant.apache.org/bindownload.cgi

二、编译编译APK

[附件]/AntApk/README.md

 
  
  1. # Ant编译Android工程样例手顺 
  2.  
  3. --- 
  4.  
  5. ## 基本步骤 
  6.  
  7. ### 新建工程(ant支持) 
  8.  
  9.   `android create project -n AntApk -t android-8 -p . -k org.join.ant.test -a AntActivity` 
  10.  
  11.   `android create project`,可查看更多参数信息 
  12.  
  13. ### 旧工程添加ant支持 
  14.  
  15.   `android update project -p . -s` 
  16.  
  17.   `android update project`,可查看更多参数信息 
  18.  
  19. ### 编译安装(debug版) 
  20.  
  21.   ``` 
  22.     ant debug 
  23.     ant installd 
  24.   ``` 
  25.  
  26.   `ant`或`ant help`,可查看更多目标信息 
  27.  
  28. --- 
  29.  
  30. ## 更多配置 
  31.  
  32. ### ProGuard混淆 
  33.   * project.properties -> proguard.config,取消#注释以启用 
  34.   * proguard-project.txt,增加混淆规则 
  35.  
  36. ### 私钥签名 
  37.   * ant.properties,增加key.store、key.alias 
  38.   * 免去密码输入,增加key.store.password、key.alias.password 
  39.  
  40. ### NDK编译 
  41.   * ${sdk.dir}/tools/ant/build.xml,如下修改: 
  42.  
  43.   ``` 
  44.     <!-- modify --> 
  45.     <target name="-pre-clean" depends="-ndk-clean"/> 
  46.      
  47.     <!-- modify --> 
  48.     <target name="-pre-build" depends="-ndk-build"/> 
  49.  
  50.     <!-- add start --> 
  51.     <condition property="has.ndkbuild"> 
  52.         <and> 
  53.             <isset property="ndk.build" /> 
  54.             <available file="${ndk.build}"/> 
  55.         </and> 
  56.     </condition> 
  57.  
  58.     <target name="-ndk-clean" if="has.ndkbuild"> 
  59.         <echo level="info">ndk clean...</echo> 
  60.         <exec executable="${ndk.build}" failonerror="true"> 
  61.             <arg value="clean" /> 
  62.         </exec> 
  63.         <delete dir="obj"/> 
  64.     </target> 
  65.  
  66.     <target name="-ndk-build" if="has.ndkbuild" depends="-ndk-clean"> 
  67.         <echo level="info">ndk build...</echo> 
  68.         <exec executable="${ndk.build}" failonerror="true" /> 
  69.     </target> 
  70.     <!-- add end --> 
  71.   ``` 
  72.  
  73.   * local.properties,增加ndk.build 
  74.  
  75.     `ndk.build=...\\android-ndk-r8b\\ndk-build.cmd` 
  76.  
  77. --- 
  78.  
  79. ## 其他内容 
  80.  
  81. ### android 
  82.  
  83.   该命令在`<sdk>\\tools`目录内,一般已添加至环境变量。 
  84.  
  85. ### [ant](http://ant.apache.org/bindownload.cgi "下载地址") 
  86.  
  87.   也一般将其安装目录添加至环境变量。 

三、打包打包JS

3.1)打包工具

Google Closure Compiler
下载地址:https://code.google.com/p/closure-compiler/downloads/list

输出到 -> [附件]/Cutout/tools/compiler.jar

3.2)编译脚本

[附件]/Cutout/src/build.xml

 
  
  1. <?xml version="1.0"?> 
  2. <project name="Javascript compress" basedir="." default="compile"> 
  3.  
  4.     <taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask" 
  5.              classpath="../tools/compiler.jar"/> 
  6.  
  7.     <target name="compile"> 
  8.         <jscomp compilationLevel="simple" warning="verbose" 
  9.                 debug="false" output="../js/Cutout.min.js"> 
  10.             <!-- 
  11.             <externs dir="${basedir}"> 
  12.                 <file name="externs.js"/> 
  13.             </externs> 
  14.             --> 
  15.             <sources dir="${basedir}"> 
  16.                 <file name="Cutout.js"/> 
  17.             </sources> 
  18.         </jscomp> 
  19.     </target> 
  20. </project> 

四、后记

如果使用Sublime Text 2,则可以如下配置(不过不能选择目标)。

 
  
  1. >>Ant build 
  2. "cmd": ["ant""-f""build.xml""all"], 
  3. "file_regex""^(...*?):([0-9]*):?([0-9]*)"
  4. "working_dir""$project_path" 
  5.  
  6. >> Ant.sublime-build 
  7. "cmd": ["ant"], 
  8. "file_regex""^ *\\[javac\\] (.+):([0-9]+):() (.*)$"
  9. "working_dir""${project_path:${folder}}"
  10. "selector""source.java"
  11.  
  12. "windows"
  13. "cmd": ["ant.bat"], 
  14. "encoding""cp936" 
  15. "working_dir""$project_path" <- Buildfile: build.xml does not exist! 
  16. "encoding""cp936" <- [Decode error - output not utf-8] 

 ps:附件AntApk为android sdk&ndk编译例子,Cutout为js压缩例子。