ant 加快eclipse下android项目编译速度

10 篇文章 0 订阅

http://trinea.iteye.com/blog/1457473

本文主要介绍通过ant和一些eclipse配置加快eclipse下android项目编译速度。

主要包括两部分ant提高效率eclipse配置项提高效率。关于eclipse中android项目的编译过程分析见上一篇博客

Ps:本文中编译过程输出都是以真机(htc g7)作为avd,api level为8。

 

用eclipse进行android开发的朋友都会发现,无论是java文件还是一个资源文件的修改,在build的时候都会有一个重新编译的过程,而这个过程及其缓慢,导致项目开发效率极其低下。

 

1、ant配置提高效率

这个部分主要介绍ant可以为android开发做什么,如何生成ant项目,为已存在的项目生成ant的build xml,如何利用ant生成配置。

相应java开发对ant都有一定熟悉,关于下载安装、配置及使用不多介绍,具体可见apache ant

1.1 ant可以为android开发做什么

a. 添加自定义生成步骤

b. 使用自动生成系统

c. 使用生成配置

d. 一个命令build项目

 

1.2 生成ant项目

使用如下命令

Xml代码   收藏代码
  1. android create project --name YourProjectName --path C:\dev\YourProject --target android-3 --package com.company.testproject --activity MainActivity  

相当于eclipse -> new -> other -> android project,参数相当于dialog中需要填写的信息

 

1.3 为已存在的项目生成ant的build xml

运行命令行到当前项目根目录下,运行如下命令:

Xml代码   收藏代码
  1. android update project --path .  

结果如下:

Xml代码   收藏代码
  1. Updated local.properties  
  2. Added file C:\dev\blog\antbuild\build.xml  

表示增加成功,可以使用ant命令查看相关信息和帮助,如下:

Java代码   收藏代码
  1. >ant  
  2. Buildfile: C:\dev\blog\antbuild\build.xml  
  3.     [setup] Android SDK Tools Revision 6  
  4.     [setup] Project Target: Android 1.5  
  5.     [setup] API level: 3  
  6.     [setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.  
  7.     [setup] Importing rules file: platforms\android-3\ant\ant_rules_r2.xml  
  8.   
  9. help:  
  10.      [echo] Android Ant Build. Available targets:  
  11.      [echo]    help:      Displays this help.  
  12.      [echo]    clean:     Removes output files created by other targets.  
  13.      [echo]    compile:   Compiles project's .java files into .class files.  
  14.      [echo]    debug:     Builds the application and signs it with a debug key.  
  15.      [echo]    release:   Builds the application. The generated apk file must be  
  16.      [echo]               signed before it is published.  
  17.      [echo]    install:   Installs/reinstalls the debug package onto a running  
  18.      [echo]               emulator or device.  
  19.      [echo]               If the application was previously installed, the  
  20.      [echo]               signatures must match.  
  21.      [echo]    uninstall: Uninstalls the application from a running emulator or  
  22.      [echo]               device.  
  23.   
  24. BUILD SUCCESSFUL  
 

1.4 如何利用ant生成配置

项目中经常需要对一些字符串或是日志级别进行设置,这里我们可以通过ant的配置项完成

新建build.properties文件,内容为

Xml代码   收藏代码
  1. # Turn on or off logging.  
  2. config.logging=true  

调用地方如下使用

Xml代码   收藏代码
  1. public class Config {  
  2.     /** Whether or not to include logging statements in the application. */  
  3.     public final static boolean LOGGING = @CONFIG.LOGGING@;  
  4. }    

需要在build.xml中添加如下部分

Xml代码   收藏代码
  1. <!-- Copy Config.java to our source tree, replacing custom tokens with values in build.properties. The configuration depends on "clean" because otherwise the build system will not detect changes in the configuration. -->  
  2. lt;target name="config">  
  3.   
  4. <property name="config-target-path" value="${source.dir}/com/androidengineer/antbuild"/>  
  5.   
  6. <!-- Copy the configuration file, replacing tokens in the file. -->  
  7. <copy file="config/Config.java" todir="${config-target-path}"  
  8. overwrite="true" encoding="utf-8">  
  9.  <filterset>  
  10. lt;filter token="CONFIG.LOGGING" value="${config.logging}"/>  
  11.  </filterset>  
  12. </copy>  
  13.   
  14. <!-- Now set it to read-only, as we don't want people accidentally  
  15.   editing the wrong one. NOTE: This step is unnecessary, but I do  
  16.   it so the developers remember that this is not the original file. -->  
  17. <chmod file="${config-target-path}/Config.java" perm="-w"/>  
  18. <attrib file="${config-target-path}/Config.java" readonly="true"/>  
  19.   
  20. t;/target>  
具体可以参考  http://www.androidengineer.com/2010/06/using-ant-to-automate-building-android.html

 

2、eclipse配置项提高效率

右击项目选择Properties -> Builders,取消勾选所有的Builders

原因尚不明,但很有效果,修改文件后保存,编译极快。

 

3、修改sdk依赖版本,据悉在api level 8之前编译速度良好。

未降级api进行测试

 

参考:

http://oae9.wordpress.com/2011/03/22/android-workaround-for-slow-building-workspace-problem-in-eclipse/

 

http://liuqzan.iteye.com/blog/951995


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值