Android项目使用Ant打包,自动生成build.xml

转自:http://blog.csdn.net/ms03001620/article/details/8490238


haima:以下为本人在使用过程中遇到的问题和解决方法:

1、$ android update project --path .

Error: The project either has no target set or the target is invalid.
Please provide a --target to the 'android update' command.


2. android update project --path . --target 17

Error: Target id '17' is not valid. Use 'android list targets' to get the target ids.

3.android list targets

id: 1 or "android-17"
     Name: Android 4.2.2
     Type: Platform
     API level: 17
     Revision: 2
     Skins: WQVGA432, WXGA800, WSVGA, WXGA800-7in, WVGA854, QVGA, HVGA, WQVGA400, WXGA720, WVGA800 (default)
     ABIs : no ABIs.


4.android update project --path . --target 1 

Updated project.properties
Updated local.properties
No project name specified, using Activity name '*******myproject'.
If you wish to change it, edit the first line of build.xml.
Added file ./build.xml
Added file ./proguard-project.txt


到了最后一步就成功了!!!!!


5. 有一个工程出现以下的警告信息,暂不处理。。。

e$ android update project --path . --target 1
Updated and renamed default.properties to project.properties
Updated local.properties
No project name specified, using Activity name 'BrowserActivity'.
If you wish to change it, edit the first line of build.xml.
Added file ./build.xml
Added file ./proguard-project.txt
It seems that there are sub-projects. If you want to update them
please use the --subprojects parameter.



一、生成build.xml

Eclipse中使用AntAndroid打包并且签名

SDK自带文件 在<sdk>tools/ant目录下这3个文件

 

其中build.xmluibuild.xml中定义了大量基础构建方法和打包策略。我们只需要建立我们自己的build.xml并且存放在项目的根目录下,然后引用一下<sdk>tools/ant/build.xml即可。当然也可以拷贝它然后直接操作。

那么如何。以项目AntForAndroid为例。生成一个针对该项目的build.xml呢?

这里需要一个工具。就是SDK自带的android.bat .所在目录<sdk>tools/android.bat

然后通过命令行执行“android update project --path .”即可。完毕后即可通过android命令在当前项目目录下生成一个build.xml文件

 

新生成的3个文件 build.xml,local.properties,proguard-project.exe

二、配置ant.properties 

在项目根目录新建一个ant.properties文件(不要去改变他的名字,因为<sdk>\tools\ant\build.xml会引用到这个名字)

并且在里面写入一下数据:

#keystore文件的目录,因为在根目录下所以直接写名字了

key.store=android.keystore

#这个名字就是在生成keystore时那个alias字段的值

key.alias=android.keystore

#两个密码分别写建立keystore时的两个密码

key.store.password=(your pwd)

key.alias.password=(your pwd)


生成 android.keystore 文件:

keytool -genkey -alias android.keystore -keyalg RSA -validity 20000 -keystore android.keystore


三、实现自动打签名apk

右键点击项目中的build.xml->run as... 先查看下有多少种任务,当然这些任务都是来自<sdk>\tools\ant\build.xml,项目里的只是引用了它

 

 

窗口打开

 

默认的选择在help上。打签名包的时候执行release这个任务即可。

按照以上的步骤配置好之后就能生成签名apk。并且大家可以通过学习<sdk>\tools\ant\build.xml来理解ant的基本奥妙。

最后在项目跟目录\bin下生成apk

Ant是非常强大的。可以实现一下功能

例如

1.在生成apk的文件名里加上日期。

2.把apk文件自动通过邮件发给其他人。

3.apk文件上传服务器

等等

 

 


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值