命令行下创建Android工程,用Ant部署编译

1、环境准备

告诉 path 要指向到 Android SDK 目录的 tools 子目录中,如 d:\android-sdk-windows\tools
要用 ant 编译部署的话,再把 ant 的 bin 目录加入到 path 上,如 D:\apache-ant-1.8.2\bin

cmd进到命令行下,执行:

android create project -k com.fujitsu.wujj -n Hello  -a HelloAndroid -t 15 -p d:\TestAndroid

-k 工程包名: com.fujitsu.wujj

-n 工程名�0�2 : Hello

-a Activity子类名: HelloAndroid

-t 工程使用的平台 Target: 15 ( 基于Android SDK4.0.3),是执行 android list targets 显示出的 target id 值

-p 工程存储路径: c:\TestAndroid

控制台下输出:

Created project directory: c:\TestAndroid
Created directory C:\TestAndroid\src\cc\unmi\android\test
Added file c:\TestAndroid\src\cc\unmi\android\test\HelloAndroid.java
Created directory C:\TestAndroid\res
Created directory C:\TestAndroid\bin
Created directory C:\TestAndroid\libs
Created directory C:\TestAndroid\res\values
Added file c:\TestAndroid\res\values\strings.xml
Created directory C:\TestAndroid\res\layout
Added file c:\TestAndroid\res\layout\main.xml
Created directory C:\TestAndroid\res\drawable-hdpi
Created directory C:\TestAndroid\res\drawable-mdpi
Created directory C:\TestAndroid\res\drawable-ldpi
Added file c:\TestAndroid\AndroidManifest.xml
Added file c:\TestAndroid\build.xml
Added file c:\TestAndroid\proguard.cfg

我们知道生成了什么文件,目录下存在 build.xml 文件。这时候,还没 gen 目录,bin 目录是空的。

现在如果已配置好了 ant,就可以进到 c:\TestAndroid 目录下,执行 ant help, 显示出可以使用的 ant 的 target 选项:

help:
[echo] Android Ant Build. Available targets:
[echo]�0�2�0�2�0�2 help:�0�2�0�2�0�2�0�2�0�2 Displays this help.
[echo]�0�2�0�2�0�2 clean:�0�2�0�2�0�2�0�2 Removes output files created by other targets.
[echo]�0�2�0�2�0�2 compile:�0�2�0�2 Compiles project's .java files into .class files.
[echo]�0�2�0�2�0�2 debug:�0�2�0�2�0�2�0�2 Builds the application and signs it with a debug key.
[echo]�0�2�0�2�0�2 release:�0�2�0�2 Builds the application. The generated apk file must be
[echo]�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2 signed before it is published.
[echo]�0�2�0�2�0�2 install:�0�2�0�2 Installs/reinstalls the debug package onto a running
[echo]�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2 emulator or device.
[echo]�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2 If the application was previously installed, the
[echo]�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2 signatures must match.
[echo]�0�2�0�2�0�2 uninstall: Uninstalls the application from a running emulator or
[echo]�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2�0�2 device.

也就是可以用 ant compile, ant release, ant install 等进行编译,打包,部署等。

ant compile 在 bin 下编译出 class 文件,生成 gen 目录及 R.java。
ant release 在 bin 下生成 classes.dex, Hello.ap_ 和 Hello-unsigned.apk。

要是你现在启动了 Android 模拟器,启动模拟器的命令是 emulator -avd avd名。关于创建 avd 的做法这里略去。

 

那现在可以执行 ant install

ant install 指令最后的过程是:

-package-debug-sign:
[apkbuilder] Creating Hello-debug-unaligned.apk and signing it with a debug key...

debug:
[echo] Running zip align on final apk...
[echo] Debug Package: C:\TestAndroid\bin\Hello-debug.apk

install:
[echo] Installing d:\TestAndroid\bin\Hello-debug.apk onto default emulator or device...
[exec]�0�2�0�2�0�2�0�2 pkg: /data/local/tmp/Hello-debug.apk
[exec] Success
[exec] 35 KB/s (13235 bytes in 0.359s)

BUILD SUCCESSFUL

在 d:\TestAndroid 下新生成了 Hello-debug-unaligned.apk 和 Hello-debug.apk, 然后部署到模拟器上的是 Hello-debug.apk。当然有了 apk,你也可以直接使用 adb install Hello-debug.apk 来安装到模拟器上。

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值