1、登陸ant下載網頁:http://ant.apache.org/bindownload.cgi,點擊紅框內容進行ant下載。
2、把ant下載包解壓放進指定目錄下。
3、配置ant的系統環境,以下
4、在dos環境中輸入ant -version 測試ant環境配置是不是成功。
1、在dos環境下輸入命令:
android update project --name <project_name> --target <target_ID>--path <path_to_your_project>
注意:target可以通過命令android list target查看target的id
例如:
安卓項目中生成了build.xml和local.properties配置文件
編譯打包項目:在已生成了的build.xml和local.properties配置文件的項目目錄下用dos輸入以下指令
ant debug:生成1個測試版apk,默許使用debug key進行簽名,生成的apk(your_project_name-debug.apk)在項目的bin目錄下。
ant release:生成1個未簽名和未aligned的apk包,project_name-release-unsigned.ap和project_name-release-unaligned.apk在項目的bin目錄下。
例如:
ant debug命令
D:Faith_yee's Workplacehehenian-mobile>android update project --name hehenian-
mobile --target android⑴8 --path "D:Faith_yee's Workplacehehenian-mobile"
Updated project.properties
Updated local.properties
Updated file D:Faith_yee's Workplacehehenian-mobileuild.xml
Updated file D:Faith_yee's Workplacehehenian-mobileproguard-project.txt
It seems that there are sub-projects. If you want to update them
please use the --subprojects parameter.
D:Faith_yee's Workplacehehenian-mobile>ant debug
Buildfile: D:Faith_yee's Workplacehehenian-mobileuild.xml
-set-mode-check:
-set-debug-files:
-check-env:
[checkenv] Android SDK Tools Revision 21.1.0
[checkenv] Installed at D:adt-bundle-windows-x86_64_20140101sdk
-setup:
[echo] Project Name: hehenian-mobile
[gettype] Project Type: Application
-set-debug-mode:
-debug-obfuscation-check:
-pre-build:
-build-setup:
[echo] Resolving Build Target for hehenian-mobile...
[gettarget] Project Target: Android 4.3
[gettarget] API level: 18
[echo] ----------
[echo] Creating output directories if needed...
[echo] ----------
[echo] Resolving Dependencies for hehenian-mobile...
[dependency] Library dependencies:
[dependency] No Libraries
[echo] ----------
[echo] Building Libraries with 'debug'...
[subant] No sub-builds to iterate on
-code-gen:
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[renderscript] No RenderScript files to compile.
[echo] ----------
[echo] Handling Resources...
[aapt] Found Deleted Target File
[aapt] Generating resource IDs...
[echo] ----------
[echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.
-pre-compile:
-compile:
[javac] Compiling 1 source file to D:Faith_yee's Workplacehehenian-mobile
binclasses
-post-compile:
-obfuscate:
-dex:
[dex] input: D:Faith_yee's Workplacehehenian-mobileinclasses
[dex] input: D:Faith_yee's Workplacehehenian-mobilelibsandroid-support
-v4.jar
[dex] Using Pre-Dexed android-support-v4-017fd1f299aa33ccf51747cafa4120bf.
jar <- D:Faith_yee's Workplacehehenian-mobilelibsandroid-support-v4.jar
[dex] Found Deleted Target File
[dex] Converting compiled files and external libraries into D:Faith_yee's
Workplacehehenian-mobileinclasses.dex...
[dx] Merged dex A (28 defs/38.5KiB) with dex B (309 defs/349.3KiB). Resul
t is 337 defs/470.8KiB. Took 0.2s
-crunch:
[crunch] Crunching PNG Files in source dir: D:Faith_yee's Workplacehehenian
-mobile
es
[crunch] To destination dir: D:Faith_yee's Workplacehehenian-mobilein
es
[crunch] Processing image to cache: D:Faith_yee's Workplacehehenian-mobile
resdrawable-hdpihehenianlogo_new.png => D:Faith_yee's Workplacehehenian-mobi
lein
esdrawable-hdpihehenianlogo_new.png
[crunch] Crunched 1 PNG files to update cache
[crunch] libpng error: Not a PNG file
-package-resources:
[aapt] Found Deleted Target File
[aapt] Creating full resource package...
-package:
[apkbuilder] Found Deleted Target File
[apkbuilder] Creating hehenian-mobile-debug-unaligned.apk and signing it with a
debug key...
-post-package:
-do-debug:
[zipalign] Running zip align on final apk...
[echo] Debug Package: D:Faith_yee's Workplacehehenian-mobileinhehenian
-mobile-debug.apk
[propertyfile] Updating property file: D:Faith_yee's Workplacehehenian-mobile
binuild.prop
[propertyfile] Updating property file: D:Faith_yee's Workplacehehenian-mobile
binuild.prop
[propertyfile] Updating property file: D:Faith_yee's Workplacehehenian-mobile
binuild.prop
[propertyfile] Updating property file: D:Faith_yee's Workplacehehenian-mobile
binuild.prop
-post-build:
debug:
BUILD SUCCESSFUL
Total time: 4 seconds
D:Faith_yee's Workplacehehenian-mobile>
ant release命令
D:Faith_yee's Workplacehehenian-mobile>ant release
Buildfile: D:Faith_yee's Workplacehehenian-mobileuild.xml
-set-mode-check:
-set-release-mode:
-release-obfuscation-check:
[echo] proguard.config is ${proguard.config}
-pre-build:
-check-env:
[checkenv] Android SDK Tools Revision 21.1.0
[checkenv] Installed at D:adt-bundle-windows-x86_64_20140101sdk
-setup:
[echo] Project Name: hehenian-mobile
[gettype] Project Type: Application
-build-setup:
[echo] Switching between debug and non debug build: Deleting previous compi
lation output...
[delete] Deleting directory D:Faith_yee's Workplacehehenian-mobileinclas
ses
[echo] Resolving Build Target for hehenian-mobile...
[gettarget] Project Target: Android 4.3
[gettarget] API level: 18
[echo] ----------
[echo] Creating output directories if needed...
[mkdir] Created dir: D:Faith_yee's Workplacehehenian-mobileinclasses
[echo] ----------
[echo] Resolving Dependencies for hehenian-mobile...
[dependency] Library dependencies:
[dependency] No Libraries
[echo] ----------
[echo] Building Libraries with 'release'...
[subant] No sub-builds to iterate on
-code-gen:
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[renderscript] No RenderScript files to compile.
[echo] ----------
[echo] Handling Resources...
[aapt] Found Deleted Target File
[aapt] Generating resource IDs...
[echo] ----------
[echo] Handling BuildConfig class...
[buildconfig] Build type changed: Generating new BuildConfig class.
-pre-compile:
-compile:
[javac] Compiling 12 source files to D:Faith_yee's Workplacehehenian-mobil
einclasses
-post-compile:
-obfuscate:
-dex:
[dex] input: D:Faith_yee's Workplacehehenian-mobileinclasses
[dex] input: D:Faith_yee's Workplacehehenian-mobilelibsandroid-support
-v4.jar
[dex] Using Pre-Dexed android-support-v4-017fd1f299aa33ccf51747cafa4120bf.
jar <- D:Faith_yee's Workplacehehenian-mobilelibsandroid-support-v4.jar
[dex] Found Deleted Target File
[dex] Converting compiled files and external libraries into D:Faith_yee's
Workplacehehenian-mobileinclasses.dex...
[dx] Merged dex A (28 defs/38.5KiB) with dex B (309 defs/349.3KiB). Resul
t is 337 defs/470.8KiB. Took 0.2s
-crunch:
[crunch] Crunching PNG Files in source dir: D:Faith_yee's Workplacehehenian
-mobile
es
[crunch] To destination dir: D:Faith_yee's Workplacehehenian-mobilein
es
[crunch] Processing image to cache: D:Faith_yee's Workplacehehenian-mobile
resdrawable-hdpihehenianlogo_new.png => D:Faith_yee's Workplacehehenian-mobi
lein
esdrawable-hdpihehenianlogo_new.png
[crunch] Crunched 1 PNG files to update cache
[crunch] libpng error: Not a PNG file
-package-resources:
[aapt] Current build type is different than previous build: forced aapt run
.
[aapt] Creating full resource package...
-package:
[apkbuilder] Current build type is different than previous build: forced apkbuil
der run.
[apkbuilder] Creating hehenian-mobile-release-unsigned.apk for release...
-post-package:
-release-prompt-for-password:
-release-nosign:
[echo] No key.store and key.alias properties found in build.properties.
[echo] Please sign D:Faith_yee's Workplacehehenian-mobileinhehenian-mo
bile-release-unsigned.apk manually
[echo] and run zipalign from the Android SDK tools.
[propertyfile] Updating property file: D:Faith_yee's Workplacehehenian-mobile
binuild.prop
[propertyfile] Updating property file: D:Faith_yee's Workplacehehenian-mobile
binuild.prop
[propertyfile] Updating property file: D:Faith_yee's Workplacehehenian-mobile
binuild.prop
[propertyfile] Updating property file: D:Faith_yee's Workplacehehenian-mobile
binuild.prop
-release-sign:
-post-build:
release:
BUILD SUCCESSFUL
Total time: 4 seconds
D:Faith_yee's Workplacehehenian-mobile>
基于ant自動編譯打包現有的android項目,可以在ant打包利用的時候加入簽名信息,如果開發人員需要使用ant來生成有簽名的apk,那末需要進行以下步驟。
1、加入簽名信息:
在項目的根目錄下建1個ant.properties文件,輸入以下內容,其中keystore密碼和alias密碼可以不指定(防泄漏),那末在命令履行的進程中會要求你輸入。
#keystore的路徑,必須使用正斜杠 ant是linux習慣的!
key.store= "E:/wp_android_sample/me.key"
#keystore的密碼
#key.store.password=*****
#alias名
key.alias=me
#alias密碼
#key.alias.password=******
例如:
注意:keystore文件可以從eclipse導出或通過sdktool來導出,谷歌建議此密鑰只需創建1次,由于可能我們開發的多個app需要數據同享,這里就省略了。
2、在項目根目錄下運行 ant release 命令就會幫你生成1個經過簽名和aligned的apk,生成的apk(yourprojectname-release.apk)在bin目錄下,而app的key就按配置文件里的路徑保存。
D:Faith_yee's Workplacehehenian-mobile>ant release
Buildfile: D:Faith_yee's Workplacehehenian-mobileuild.xml
-check-env:
[checkenv] Android SDK Tools Revision 21.1.0
[checkenv] Installed at D:adt-bundle-windows-x86_64_20140101sdk
-setup:
[echo] Project Name: hehenian-mobile
[gettype] Project Type: Application
-pre-clean:
clean:
[delete] Deleting directory D:Faith_yee's Workplacehehenian-mobilein
[delete] Deleting directory D:Faith_yee's Workplacehehenian-mobilegen
[getlibpath] Library dependencies:
[getlibpath] No Libraries
[subant] No sub-builds to iterate on
-set-mode-check:
-set-release-mode:
-release-obfuscation-check:
[echo] proguard.config is ${proguard.config}
-pre-build:
-check-env:
[checkenv] Android SDK Tools Revision 21.1.0
[checkenv] Installed at D:adt-bundle-windows-x86_64_20140101sdk
-setup:
[echo] Project Name: hehenian-mobile
[gettype] Project Type: Application
-build-setup:
[echo] Resolving Build Target for hehenian-mobile...
[gettarget] Project Target: Android 4.3
[gettarget] API level: 18
[echo] ----------
[echo] Creating output directories if needed...
[mkdir] Created dir: D:Faith_yee's Workplacehehenian-mobilein
[mkdir] Created dir: D:Faith_yee's Workplacehehenian-mobilein
es
[mkdir] Created dir: D:Faith_yee's Workplacehehenian-mobilegen
[mkdir] Created dir: D:Faith_yee's Workplacehehenian-mobileinclasses
[mkdir] Created dir: D:Faith_yee's Workplacehehenian-mobileindexedLibs
[echo] ----------
[echo] Resolving Dependencies for hehenian-mobile...
[dependency] Ordered libraries:
[echo] ----------
[echo] Building Libraries with 'release'...
[subant] No sub-builds to iterate on
-code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[renderscript] No RenderScript files to compile.
[echo] ----------
[echo] Handling Resources...
[aapt] Generating resource IDs...
[echo] ----------
[echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.
-pre-compile:
-compile:
[javac] Compiling 12 source files to D:Faith_yee's Workplacehehenian-mobil
einclasses
-post-compile:
-obfuscate:
-dex:
[dex] input: D:Faith_yee's Workplacehehenian-mobileinclasses
[dex] input: D:Faith_yee's Workplacehehenian-mobilelibsandroid-support
-v4.jar
[dex] Pre-Dexing D:Faith_yee's Workplacehehenian-mobilelibsandroid-sup
port-v4.jar -> android-support-v4-017fd1f299aa33ccf51747cafa4120bf.jar
[dex] Converting compiled files and external libraries into D:Faith_yee's
Workplacehehenian-mobileinclasses.dex...
[dx] Merged dex A (28 defs/38.5KiB) with dex B (309 defs/349.3KiB). Resul
t is 337 defs/470.8KiB. Took 0.1s
-crunch:
[crunch] Crunching PNG Files in source dir: D:Faith_yee's Workplacehehenian
-mobile
es
[crunch] To destination dir: D:Faith_yee's Workplacehehenian-mobilein
es
[crunch] Processing image to cache: D:Faith_yee's Workplacehehenian-mobile
resdrawable-hdpihehenianlogo_new.png => D:Faith_yee's Workplacehehenian-mobi
lein
esdrawable-hdpihehenianlogo_new.png
[crunch] Processing image to cache: D:Faith_yee's Workplacehehenian-mobile
resdrawable-mdpiic_launcher.png => D:Faith_yee's Workplacehehenian-mobilei
n
esdrawable-mdpiic_launcher.png
[crunch] (processed image to cache entry D:Faith_yee's Workplacehehenian-
mobilein
esdrawable-mdpiic_launcher.png: 0% size of source)
[crunch] Processing image to cache: D:Faith_yee's Workplacehehenian-mobile
resdrawable-xhdpiic_launcher.png => D:Faith_yee's Workplacehehenian-mobile
in
esdrawable-xhdpiic_launcher.png
[crunch] (processed image to cache entry D:Faith_yee's Workplacehehenian-
mobilein
esdrawable-xhdpiic_launcher.png: 76% size of source)
[crunch] Processing image to cache: D:Faith_yee's Workplacehehenian-mobile
resdrawable-xxhdpiic_launcher.png => D:Faith_yee's Workplacehehenian-mobile
bin
esdrawable-xxhdpiic_launcher.png
[crunch] libpng error: Not a PNG file
[crunch] (processed image to cache entry D:Faith_yee's Workplacehehenian-
mobilein
esdrawable-xxhdpiic_launcher.png: 73% size of source)
[crunch] Crunched 4 PNG files to update cache
-package-resources:
[aapt] Creating full resource package...
-package:
[apkbuilder] Current build type is different than previous build: forced apkbuil
der run.
[apkbuilder] Creating hehenian-mobile-release-unsigned.apk for release...
-post-package:
-release-prompt-for-password:
-release-nosign:
-release-sign:
[echo] Signing final apk...
[zipalign] Running zip align on final apk...
[echo] Release Package: D:Faith_yee's Workplacehehenian-mobileinheheni
an-mobile-release.apk
[propertyfile] Creating new property file: D:Faith_yee's Workplacehehenian-mob
ileinuild.prop
[propertyfile] Updating property file: D:Faith_yee's Workplacehehenian-mobile
binuild.prop
[propertyfile] Updating property file: D:Faith_yee's Workplacehehenian-mobile
binuild.prop
[propertyfile] Updating property file: D:Faith_yee's Workplacehehenian-mobile
binuild.prop
-post-build:
release:
BUILD SUCCESSFUL
Total time: 8 seconds
D:Faith_yee's Workplacehehenian-mobile>
帶簽名的apk打包成功!
只要把第3方的jar包放入到項目下的libs文件夾里就能夠
1、在dos里進入到library項目的根目錄下,并輸入anroid update lib-project -p ./
2、library項目一樣會生成build.xml和local.properties配置文件
3、在dos里回到自己的項目根目錄下,輸入以下命令
android update project --name <project_name> --target <target_ID>--path <path_to_your_project> --subprojects