0%

基于 Android SDK 的 Ant 环境配置 (二)

如果你没有看过上篇 基于AndroidSDK的Ant环境配置 (一) ,那就先去看吧.

配置

查看 project.properties

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-23

从文件中可以看到, project.properties 是告诉 Ant 需要编译的目标API版本,你可以手动修改版本号或是在 android update project 命令时添加 -t API版本号 参数.

注意看这两行:

1
2
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

第二行是决定 Ant 编译时是否启用 Proguard 来对程序进行代码混淆和优化的选项,把注释符去掉即可启用.

Proguard 启用时, Ant 会先到 AndroidSDK 的对应目录下加载默认的混淆参数,然后再加载项目目录下的 proguard-project.txt ,我们可以在这文件中添加自定义的参数.

为了方便浏览,我们不在这里启用 Proguard,而是在 local.properties 中配置.

配置 local.properties

1
2
3
4
5
6
7
8
9
10
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.

# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=G:\\Dev\\AndroidSDK

可以看到在文件中已经帮我们配置好 AndroidSDK 的位置了,接下来我们要在这里添加自己的配置.

1
2
3
4
5
6
7
8
9
10
11
12
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.

# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=G:\\Dev\\AndroidSDK
# Proguard
proguard.config=${sdk.dir}\\tools\\proguard\\proguard-android.txt:proguard-project.txt

在这里我为 Ant 启用了 Proguard.

有关 Proguard 的配置,请点击 这里 来查看详细的用法.

配置 ant.properties

可选项,如果不需要

1
2
3
4
5
6
7
8
# 签名
key.store=G:\\Devs\\test.keystore
# alias
key.alias=test
# 签名密码
key.store.password=password
# alias密码
key.alias.password=aliaspass

在这里我为 Ant 指定了编译时使用的签名和密码.

现在我们就可以编译出带签名的程序了.

欢迎关注我的其它发布渠道