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
- # Ant编译Android工程样例手顺
- ---
- ## 基本步骤
- ### 新建工程(ant支持)
- `android create project -n AntApk -t android-8 -p . -k org.join.ant.test -a AntActivity`
- `android create project`,可查看更多参数信息
- ### 旧工程添加ant支持
- `android update project -p . -s`
- `android update project`,可查看更多参数信息
- ### 编译安装(debug版)
- ```
- ant debug
- ant installd
- ```
- `ant`或`ant help`,可查看更多目标信息
- ---
- ## 更多配置
- ### ProGuard混淆
- * project.properties -> proguard.config,取消#注释以启用
- * proguard-project.txt,增加混淆规则
- ### 私钥签名
- * ant.properties,增加key.store、key.alias
- * 免去密码输入,增加key.store.password、key.alias.password
- ### NDK编译
- * ${sdk.dir}/tools/ant/build.xml,如下修改:
- ```
- <!-- modify -->
- <target name="-pre-clean" depends="-ndk-clean"/>
- <!-- modify -->
- <target name="-pre-build" depends="-ndk-build"/>
- <!-- add start -->
- <condition property="has.ndkbuild">
- <and>
- <isset property="ndk.build" />
- <available file="${ndk.build}"/>
- </and>
- </condition>
- <target name="-ndk-clean" if="has.ndkbuild">
- <echo level="info">ndk clean...</echo>
- <exec executable="${ndk.build}" failonerror="true">
- <arg value="clean" />
- </exec>
- <delete dir="obj"/>
- </target>
- <target name="-ndk-build" if="has.ndkbuild" depends="-ndk-clean">
- <echo level="info">ndk build...</echo>
- <exec executable="${ndk.build}" failonerror="true" />
- </target>
- <!-- add end -->
- ```
- * local.properties,增加ndk.build
- `ndk.build=...\\android-ndk-r8b\\ndk-build.cmd`
- ---
- ## 其他内容
- ### android
- 该命令在`<sdk>\\tools`目录内,一般已添加至环境变量。
- ### [ant](http://ant.apache.org/bindownload.cgi "下载地址")
- 也一般将其安装目录添加至环境变量。
三、打包打包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
- <?xml version="1.0"?>
- <project name="Javascript compress" basedir="." default="compile">
- <taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask"
- classpath="../tools/compiler.jar"/>
- <target name="compile">
- <jscomp compilationLevel="simple" warning="verbose"
- debug="false" output="../js/Cutout.min.js">
- <!--
- <externs dir="${basedir}">
- <file name="externs.js"/>
- </externs>
- -->
- <sources dir="${basedir}">
- <file name="Cutout.js"/>
- </sources>
- </jscomp>
- </target>
- </project>
四、后记
如果使用Sublime Text 2,则可以如下配置(不过不能选择目标)。
- >>Ant build
- {
- "cmd": ["ant", "-f", "build.xml", "all"],
- "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
- "working_dir": "$project_path"
- }
- >> Ant.sublime-build
- {
- "cmd": ["ant"],
- "file_regex": "^ *\\[javac\\] (.+):([0-9]+):() (.*)$",
- "working_dir": "${project_path:${folder}}",
- "selector": "source.java",
- "windows":
- {
- "cmd": ["ant.bat"],
- "encoding": "cp936"
- }
- }
- "working_dir": "$project_path" <- Buildfile: build.xml does not exist!
- "encoding": "cp936" <- [Decode error - output not utf-8]
ps:附件AntApk为android sdk&ndk编译例子,Cutout为js压缩例子。
附件:http://down.51cto.com/data/2362318
本文转自winorlose2000 51CTO博客,原文链接:http://blog.51cto.com/vaero/1138877,如需转载请自行联系原作者