android使用ant打包应用

参考文章1:http://blog.csdn.net/hao1056531028/article/details/7717758


1. 安装及配置ant

地址:Apache官网下载最新版本的ant:http://ant.apache.org/bindownload.cgi

我下载的为:apache-ant-1.9.0-bin.zip

解压缩为:/home/hwh/Android_Project/Environment/apache-ant-1.9.0

2.修改配置变量

在/home/hwh打开隐藏文件.profile添加如下语句

####################################################################
#Apache ant
export ANT_HOME=/home/hwh/Android_Project/Environment/apache-ant-1.9.0
export PATH=$ANT_HOME/bin:$PATH

3.检查配置情况

注销后,在终端输入:ant -version

输出:

hwh@Mountain:~/Android_Project/Code/Rotate3D_2/bin$ ant -version
Apache Ant(TM) version 1.9.0 compiled on March 5 2013

表明配置好了。。


OK,然后我们进入使用ant打包android应用阶段。

///

我们主要查看更新现有代码Build清单的方法:

hwh@Mountain:~/Android_Project/Code/HHDemos$ android update project
Error: The parameter --path must be defined for action 'update project'

       Usage:
       android [global options] update project [action options]
       Global options:
  -h --help       : Help on a specific command.
  -v --verbose    : Verbose mode, shows errors, warnings and all messages.
     --clear-cache: Clear the SDK Manager repository manifest cache.
  -s --silent     : Silent mode, shows errors only.

                         Action "update project":
  Updates an Android project (must already have an AndroidManifest.xml).
Options:
  -l --library    : Directory of an Android library to add, relative to this
                    project's directory.
  -p --path       : The project's directory. [required]
  -n --name       : Project name.
  -t --target     : Target ID to set for the project.
  -s --subprojects: Also updates any projects in sub-folders, such as test
                    projects.

步骤一:android update project -n HHDemos -t android-17 -p .

步骤二:ant debug

步骤三:cd bin

步骤四:adb install HHDemos-debug.apk

OK,打完收工。。。



参考文章2:http://www.2cto.com/kf/201110/108316.html

看这篇文章之前,假设您已经具备下列条件,否则阅读这篇文章对您帮助不会太大。
<1> ubuntu下,成功安装JDK1.6并配置环境变量
<2> ubuntu下,成功下载、配置好ant环境
<3> ubuntu下,成功安装android-sdk,并且配置好tools、platform-tools环境变量
好吧,开始ant开发android之旅!/home/mark/android/android-sdk-linux_x86是android_sdk安装路径。

1.android 命令
打开终端,敲入命令

android -h 
可以列出关于该命令的帮助及其用法,其中下面命令是这篇文章的重点

create project: Creates a new Android project 
update project: Updates an Android project (must already have an AndroidManifest.xml) 
接下来,我们看看这两个命令的参数及其用法。打开终端,敲入命令

android -h create project 
可以看到,输出帮助信息:

Usage: 
  android [global options] create project [action options] 
 
 
Global options: 
  -v --verbose  Verbose mode: errors, warnings and informational messages are printed. 
  -h --help     Help on a specific command. 
  -s --silent   Silent mode: only errors are printed out. 
 
 
Action "create project": 
  Creates a new Android project. 
Options: 
  -n --name     Project name 
  -t --target   Target ID of the new project [required] 
  -p --path     The new project's directory [required] 
  -k --package  Android package name for the application [required] 
  -a --activity Name of the default Activity that is created [required] 
同理,可以看看另一个命令的用法。

Usage: 
  android [global options] update project [action options] 
 
 
Global options: 
  -v --verbose  Verbose mode: errors, warnings and informational messages are printed. 
  -h --help     Help on a specific command. 
  -s --silent   Silent mode: only errors are printed out. 
 
 
Action "update project": 
  Updates an Android project (must already have an AndroidManifest.xml). 
Options: 
  -p --path        The project's directory [required] 
  -l --library     Directory of an Android library to add, relative to this project's directory 
  -n --name        Project name 
  -t --target      Target ID to set for the project 
  -s --subprojects Also updates any projects in sub-folders, such as test projects. 
2. 创建项目
在/home/mark路径下,创建android项目,详情如下:
工程名称        :TestAntAndroidActivity
名称                :TestActivity
包名称            :mark.zhangandroid  版本    :4,即 android1.5
那么,在终端只需要:

android create project -k mark.zhang -n TestAntAndroid -a TestActivity -t 4 -p /home/mark/TestAntAndroid 
ok,在/home/mark/下面就会创建TestAntAndroid工程目录,其结构如下,与使用Eclipse/ADT创建项目是一样的效果。
修改res/layout/main.xml文件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<TextView   
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:text="this is my ant compile android app" 
    android:textSize="20sp" 
    android:textColor="#aa000a" 
    /> 
</LinearLayout> 
提示:执行 androidlist target 可以查看安装的sdk版本
3.编译项目
只需要两条简单命令,呵呵!

cd /home/mark/TestAntAndroid/ 
ant debug 
进入目录/home/mark/TestAntAndroid/bin,可以看到 ak 文件:
4. 安装 apk
将上面的 apk 文件安装到模拟器,验证是否可行。

cd /home/mark/TestAntAndroid/bin 
 
 
adb install TestAntAndroid-debug.apk 
5. 更新已有工程
如果 android 工程已经存在,可以 update project(修改平台的版本),这样会自动修改 build.xml 等 ant 的配置文件

android update project -n TestAntAndroid -t 11 -p /home/mark/TestAntAndroid/ 
控制台显示信息:

Updated default.properties 
Updated local.properties 
File build.xml is too old and needs to be updated. 
Updated file /home/mark/TestAntAndroid/build.xml 
Updated file /home/mark/TestAntAndroid/proguard.cfg 

作者:AndroidBluetooth



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值