看这篇文章之前,假设您已经具备下列条件,否则阅读这篇文章对您帮助不会太大。
<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
<wbr></wbr>
可以列出关于该命令的帮助及其用法,其中下面命令是这篇文章的重点
<wbr></wbr>
create project: Creates a new Android project
update project: Updates an Android project (must already have an AndroidManifest.xml)
<wbr></wbr>
接下来,我们看看这两个命令的参数及其用法。打开终端,敲入命令
<wbr></wbr>
android -h create project
<wbr></wbr>
可以看到,输出帮助信息:
Usage:
android [global options] create project [action options]
<wbr></wbr>
<wbr></wbr>
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.
<wbr></wbr>
<wbr></wbr>
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]
<wbr></wbr>
同理,可以看看另一个命令的用法。
Usage:
android [global options] update project [action options]
<wbr></wbr>
<wbr></wbr>
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.
<wbr></wbr>
<wbr></wbr>
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
那么,在终端只需要:
<wbr></wbr>
android create project -k mark.zhang -n TestAntAndroid -a TestActivity -t 4 -p /home/mark/TestAntAndroid
<wbr></wbr>
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.编译项目
只需要两条简单命令,呵呵!
<wbr></wbr>
cd /home/mark/TestAntAndroid/
ant debug
进入目录/home/mark/TestAntAndroid/bin,可以看到 ak 文件:
4. 安装 apk
将上面的 apk 文件安装到模拟器,验证是否可行。
<wbr></wbr>
cd /home/mark/TestAntAndroid/bin
adb install TestAntAndroid-debug.apk
5. 更新已有工程
如果 android 工程已经存在,可以 update project(修改平台的版本),这样会自动修改 build.xml 等 ant 的配置文件
<wbr></wbr>
android update project -n TestAntAndroid -t 11 -p /home/mark/TestAntAndroid/
<wbr></wbr>
注意: -t 11 表示使用 android-11,当然你可以使用其他版本来更新工程。但是,有时候更新一个工程不使用 android 高版本来更新的话,项目会报错。
控制台显示信息:
<wbr></wbr>
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
<wbr></wbr>
P.S:如果工程已经存在,就不要再执行android create...的android口令了,而是直接更新工程即可,如下:
android update project --name com.weibo.android -t 6 -p E:\Code\Android6_ndk\com.weibo.android
android update project --name com.renren.android -t 6 -p E:\Code\Android6_ndk\com.renren.android
android update project --name Lvyoukankan -t 6 -p E:\Code\Android6_ndk\lvyoukankan
cd /d E:\Code\Android6_ndk\Lvyoukankan
ant debug
注释:
1.com.weibo.android--project name <wbr>E:\Code\Android6_ndk\com.weibo.android--project path</wbr>
2.name com.renren.android--project name E:\Code\Android6_ndk\com.renren.android--project path
3.Lvyoukankan--project name E:\Code\Android6_ndk\lvyoukankan--project path
这样,你会看到在Lvyoukankan里面的bin文件夹下,刚刚利用ant构建文件生成的带签名的apk文件。
分享到:
相关推荐
通过ant脚本,编译打包android工程。 编译打包android工程的ant脚本,Android官方提供的打包脚本。 有注释
Ant编译打包android工程,签名,多渠道
Android工程,演示如何使用Ant编译工程。
Maven坐标:org.apache.ant:ant:1.9.1; 标签:apache、jar包、java、API文档、中文版; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持...
Android利用ant自动编译、修改配置文件、批量多渠道,打包生成apk文件 详见:http://www.cnblogs.com/ycxyyzw/p/4535459.html
通过ant脚本,编译打包android工程, 编译打包android工程的ant脚本。
ant脚本编译出jar
因为项目的需要必须写一个ANDROID_ANT自动编译打包签名的脚本,终于奋斗了几天写完了,和大家分享一下
mac下是用ant对android App的多渠道打包工具。
介绍了如何通过ant进行java web工程的编译操作的详细配置
当一个代码项目大了以后,每次重新编译,打包,测试等都会变得非常复杂而且重复,因此c语言中有make脚本来帮助这些工作的批量完成。在Java 中应用是平台无关性的,当然不会用平台...本文介绍了android编译和ant打包原理
在使用命令行+Ant学习Android的过程中,自己累积的一些常用在命令下的编译和运行Android的命令,希望能带给你一些帮忙。
传单蚂蚁路径创建带有“蚂蚁路径”动画通量的传单折线正在安装通过NPM: npm install --save leaflet-ant-path通过纱线: yarn add leaflet-ant-path通过凉亭: bower install leaflet-ant-path或仅此源代码要求单张...
使用ant打包android,使用ant打包android
在编译flex/java工程是采用Ant自动编译,将编译好的工程进行打包发布.
Ant编译后的zookeeper源码 版本:zookeeper-release-3.4.11、apache-ant-1.9.14 可直接导入eclipse或idea
Builder 给出了使用ant编译Android工程的通用shell脚本,相关博文:Android开发实践:用脚本编译Android工程 GroupList 封装并演示了如何使用Android的ExpandableListView控件,相关博文:Android开发实践:多级...
NULL 博文链接:https://liuna718-163-com.iteye.com/blog/1859773
准备工作: 1、安装 ant:把 ant 解压到本地硬盘 c:\ant 2、设置环境变量:ANT_HOME:c:\ant 。 PATH:在原来的 PATH 开头加上 c:\ant\bin; 3、一个 ant 项目目录结构: c:\HelloWorld :项目主目录 \src :源...
适合在ant下进行编译的工具,以及一些checkstyle,方便实用