Ant管理安卓项目的自动化打包命令

Ant管理安卓项目的自动化打包命令

一、配置ant

1、登陆ant下载网页:http://ant.apache.org/bindownload.cgi,点击红框内容进行ant下载。

2、把ant下载包解压放进指定目录下。

3、配置ant的系统环境,如下

4、在dos环境中输入ant -version 测试ant环境配置是否成功。

二、使用ant命令给安卓项目生成build.xml和local.properties配置文件

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配置文件

三、使用Ant命令进行生成测试版apk和未签名的apk

编译打包项目:在已经生成了的build.xml和local.properties配置文件的项目目录下用dos输入如下指令

ant debug:生成一个测试版apk,默认使用debug key进行签名,生成的apk(your_project_name-debug.apk)在项目的bin目录下。

ant release:生成一个未签名和未aligned的apk包,project_name-release-unsigned.ap和project_name-release-unaligned.apk在项目的bin目录下。

例如:

ant debug命令

D:\Faith_yee‘s Workplace\hehenian-mobile>android update project --name hehenian-
mobile --target android-18 --path "D:\Faith_yee‘s Workplace\hehenian-mobile"
Updated project.properties
Updated local.properties
Updated file D:\Faith_yee‘s Workplace\hehenian-mobile\build.xml
Updated file D:\Faith_yee‘s Workplace\hehenian-mobile\proguard-project.txt
It seems that there are sub-projects. If you want to update them
please use the --subprojects parameter.

D:\Faith_yee‘s Workplace\hehenian-mobile>ant debug
Buildfile: D:\Faith_yee‘s Workplace\hehenian-mobile\build.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_20140101\sdk

-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 Workplace\hehenian-mobilebin\classes

-post-compile:

-obfuscate:

-dex:
      [dex] input: D:\Faith_yee‘s Workplace\hehenian-mobile\bin\classes
      [dex] input: D:\Faith_yee‘s Workplace\hehenian-mobile\libs\android-support
-v4.jar
      [dex] Using Pre-Dexed android-support-v4-017fd1f299aa33ccf51747cafa4120bf.
jar <- D:\Faith_yee‘s Workplace\hehenian-mobile\libs\android-support-v4.jar
      [dex] Found Deleted Target File
      [dex] Converting compiled files and external libraries into D:\Faith_yee‘s
 Workplace\hehenian-mobile\bin\classes.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 Workplace\hehenian
-mobile\res
   [crunch] To destination dir: D:\Faith_yee‘s Workplace\hehenian-mobile\bin\res

   [crunch] Processing image to cache: D:\Faith_yee‘s Workplace\hehenian-mobileres\drawable-hdpi\hehenianlogo_new.png => D:\Faith_yee‘s Workplace\hehenian-mobi
le\bin\res\drawable-hdpi\hehenianlogo_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 Workplace\hehenian-mobile\bin\hehenian
-mobile-debug.apk
[propertyfile] Updating property file: D:\Faith_yee‘s Workplace\hehenian-mobilebin\build.prop
[propertyfile] Updating property file: D:\Faith_yee‘s Workplace\hehenian-mobilebin\build.prop
[propertyfile] Updating property file: D:\Faith_yee‘s Workplace\hehenian-mobilebin\build.prop
[propertyfile] Updating property file: D:\Faith_yee‘s Workplace\hehenian-mobilebin\build.prop

-post-build:

debug:

BUILD SUCCESSFUL
Total time: 4 seconds

D:\Faith_yee‘s Workplace\hehenian-mobile>

ant release命令

D:\Faith_yee‘s Workplace\hehenian-mobile>ant release
Buildfile: D:\Faith_yee‘s Workplace\hehenian-mobile\build.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_20140101\sdk

-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 Workplace\hehenian-mobile\bin\clas
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 Workplace\hehenian-mobile\bin\classes
     [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 Workplace\hehenian-mobil
e\bin\classes

-post-compile:

-obfuscate:

-dex:
      [dex] input: D:\Faith_yee‘s Workplace\hehenian-mobile\bin\classes
      [dex] input: D:\Faith_yee‘s Workplace\hehenian-mobile\libs\android-support
-v4.jar
      [dex] Using Pre-Dexed android-support-v4-017fd1f299aa33ccf51747cafa4120bf.
jar <- D:\Faith_yee‘s Workplace\hehenian-mobile\libs\android-support-v4.jar
      [dex] Found Deleted Target File
      [dex] Converting compiled files and external libraries into D:\Faith_yee‘s
 Workplace\hehenian-mobile\bin\classes.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 Workplace\hehenian
-mobile\res
   [crunch] To destination dir: D:\Faith_yee‘s Workplace\hehenian-mobile\bin\res

   [crunch] Processing image to cache: D:\Faith_yee‘s Workplace\hehenian-mobileres\drawable-hdpi\hehenianlogo_new.png => D:\Faith_yee‘s Workplace\hehenian-mobi
le\bin\res\drawable-hdpi\hehenianlogo_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 Workplace\hehenian-mobile\bin\hehenian-mo
bile-release-unsigned.apk manually
     [echo] and run zipalign from the Android SDK tools.
[propertyfile] Updating property file: D:\Faith_yee‘s Workplace\hehenian-mobilebin\build.prop
[propertyfile] Updating property file: D:\Faith_yee‘s Workplace\hehenian-mobilebin\build.prop
[propertyfile] Updating property file: D:\Faith_yee‘s Workplace\hehenian-mobilebin\build.prop
[propertyfile] Updating property file: D:\Faith_yee‘s Workplace\hehenian-mobilebin\build.prop

-release-sign:

-post-build:

release:

BUILD SUCCESSFUL
Total time: 4 seconds

D:\Faith_yee‘s Workplace\hehenian-mobile>

四、给项目生成签名后的apk

基于ant自动编译打包现有的android项目,可以在ant打包应用的时候加入签名信息,如果开发人员需要使用ant来生成有签名的apk,那么需要进行如下步骤。

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来导出,谷歌建议此密钥只需创建一次,因为可能我们开发的多个app需要数据共享,这里就省略了。

2、在项目根目录下运行 ant release 命令就会帮你生成一个经过签名和aligned的apk,生成的apk(yourprojectname-release.apk)在bin目录下,而app的key就按配置文件里的路径保存。

D:\Faith_yee‘s Workplace\hehenian-mobile>ant release
Buildfile: D:\Faith_yee‘s Workplace\hehenian-mobile\build.xml

-check-env:
 [checkenv] Android SDK Tools Revision 21.1.0
 [checkenv] Installed at D:\adt-bundle-windows-x86_64_20140101\sdk

-setup:
     [echo] Project Name: hehenian-mobile
  [gettype] Project Type: Application

-pre-clean:

clean:
   [delete] Deleting directory D:\Faith_yee‘s Workplace\hehenian-mobile\bin
   [delete] Deleting directory D:\Faith_yee‘s Workplace\hehenian-mobile\gen
[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_20140101\sdk

-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 Workplace\hehenian-mobile\bin
    [mkdir] Created dir: D:\Faith_yee‘s Workplace\hehenian-mobile\bin\res
    [mkdir] Created dir: D:\Faith_yee‘s Workplace\hehenian-mobile\gen
    [mkdir] Created dir: D:\Faith_yee‘s Workplace\hehenian-mobile\bin\classes
    [mkdir] Created dir: D:\Faith_yee‘s Workplace\hehenian-mobile\bin\dexedLibs
     [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 Workplace\hehenian-mobil
e\bin\classes

-post-compile:

-obfuscate:

-dex:
      [dex] input: D:\Faith_yee‘s Workplace\hehenian-mobile\bin\classes
      [dex] input: D:\Faith_yee‘s Workplace\hehenian-mobile\libs\android-support
-v4.jar
      [dex] Pre-Dexing D:\Faith_yee‘s Workplace\hehenian-mobile\libs\android-sup
port-v4.jar -> android-support-v4-017fd1f299aa33ccf51747cafa4120bf.jar
      [dex] Converting compiled files and external libraries into D:\Faith_yee‘s
 Workplace\hehenian-mobile\bin\classes.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 Workplace\hehenian
-mobile\res
   [crunch] To destination dir: D:\Faith_yee‘s Workplace\hehenian-mobile\bin\res

   [crunch] Processing image to cache: D:\Faith_yee‘s Workplace\hehenian-mobileres\drawable-hdpi\hehenianlogo_new.png => D:\Faith_yee‘s Workplace\hehenian-mobi
le\bin\res\drawable-hdpi\hehenianlogo_new.png
   [crunch] Processing image to cache: D:\Faith_yee‘s Workplace\hehenian-mobileres\drawable-mdpi\ic_launcher.png => D:\Faith_yee‘s Workplace\hehenian-mobile\bi
n\res\drawable-mdpi\ic_launcher.png
   [crunch]   (processed image to cache entry D:\Faith_yee‘s Workplace\hehenian-
mobile\bin\res\drawable-mdpi\ic_launcher.png: 0% size of source)
   [crunch] Processing image to cache: D:\Faith_yee‘s Workplace\hehenian-mobileres\drawable-xhdpi\ic_launcher.png => D:\Faith_yee‘s Workplace\hehenian-mobile\b
in\res\drawable-xhdpi\ic_launcher.png
   [crunch]   (processed image to cache entry D:\Faith_yee‘s Workplace\hehenian-
mobile\bin\res\drawable-xhdpi\ic_launcher.png: 76% size of source)
   [crunch] Processing image to cache: D:\Faith_yee‘s Workplace\hehenian-mobileres\drawable-xxhdpi\ic_launcher.png => D:\Faith_yee‘s Workplace\hehenian-mobilebin\res\drawable-xxhdpi\ic_launcher.png
   [crunch] libpng error: Not a PNG file
   [crunch]   (processed image to cache entry D:\Faith_yee‘s Workplace\hehenian-
mobile\bin\res\drawable-xxhdpi\ic_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 Workplace\hehenian-mobile\bin\heheni
an-mobile-release.apk
[propertyfile] Creating new property file: D:\Faith_yee‘s Workplace\hehenian-mob
ile\bin\build.prop
[propertyfile] Updating property file: D:\Faith_yee‘s Workplace\hehenian-mobilebin\build.prop
[propertyfile] Updating property file: D:\Faith_yee‘s Workplace\hehenian-mobilebin\build.prop
[propertyfile] Updating property file: D:\Faith_yee‘s Workplace\hehenian-mobilebin\build.prop

-post-build:

release:

BUILD SUCCESSFUL
Total time: 8 seconds

D:\Faith_yee‘s Workplace\hehenian-mobile>

带签名的apk打包成功!

五、项目中带有第三方的jar包或关联了library库的ant打包方法

1、带有第三方jar包的打包

只要把第三方的jar包放入到项目下的libs文件夹里就可以

2、关联了library库的ant打包方法

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
时间: 2024-10-22 04:35:02

Ant管理安卓项目的自动化打包命令的相关文章

ANT自动打包U3D安卓项目研究笔记

概述 因项目使用Atlassian Stash作为项目源码管理端,且其支持Ant命令自动编译,可使其根据最新的代码自动打包,故产生该研究Ant打包的任务.在此将研究过程及一些相关知识整理记录在此. 本文部分内容可以说就是Android和Ant自动打包的配置,只是在其基础上扩充了Unity3D的部分. 阅读本文需要:知道Android开发环境大概需要哪些东西,知道Unity3D编辑器的基本使用方法. 本文并不是系统学习Ant以及Android自动打包的文章,只是笔者通过网络搜索一系列文章,然后通过

在Hudson中,使用ant自动对安卓项目编译打包apk

本文对如何在hudson中配置ant编译打包apk进行说明,主要包括build.xml文件的编写.环境的配置.在Hudson中创建任务. 一.为安卓项目创建build.xml文件 1.打开cmd进入sdk目录下的tools目录,输入: android.bat list target  来查询我们现有的版本list有哪些.如下图: 途中用红框圈出的 id 与蓝框圈出的版本号对应关系,下面需要用到. 2.打开安卓项目工程下的 project.properties 文件,查看target 版本号,如下

安卓项目打包时候报错--解决方案

今天在打包的时候报了一堆同样的错误,是因为引入PulltoRefreshLibrary这个库导致的,只要一打包,就会报八百多个同样的错误,可能是因为在打包的时候,引用库的时候有冲突一类的: 具体解决方案: 第一步:右键安卓项目--->属性 第二步:直接看图 第三步:选择 Ignore All 然后点击Apply 第四步:clean整个安卓项目 第五步:打包-->直至成功.

Python 编程快速上手 让繁琐工作自动化-第十一章实践项目 11.11.1命令行邮件程序

11.11.1 命令行邮件程序 编写一个程序,通过命令行接受电子邮件地址和文本字符串.然后利用selenium登录到你的邮件账号,将该字符串作为邮件,发送到提供的地址(你也许希望为这个程序建立一个独立的邮件账号).这是为程序添加通知功能的一种好方法.你也可以编写类似的程序,从Facebook 或Twitter 账号发送消息.这个项目弄了好几天,头都快炸了,终于弄好了代码如下:#!/usr/bin/env python#encoding:utf-8 '''@author:Kevinbr/>@aut

Jenkins自动化部署安卓项目

一.简介 Android SDK:(software development kit)软件开发工具包.被软件开发工程师用于为特定的软件包.软件框架.硬件平台.操作系统等建立应用软件的开发工具的集合.因此,Android SDK 指的是Android专属的软件开发工具包.Gradle:是一个基于JVM的构建工具,是一款通用灵活的构建工具,支持maven, Ivy仓库,支持传递性依赖管理,而不需要远程仓库或者是pom.xml和ivy.xml配置文件,基于Groovy,build脚本使用Groovy编

Mac Jenkins+fastlane 简单几步实现iOS自动化打包发布

最近在使用jenkins 实现ios自动化打包发布蒲公英过程实践遇到了一些坑,特意记录下来方便有需要的人. 进入正题: 一.安装Jenkins 1.Mac上安装Jenkins 遇到到坑 因为 Jenkins 的pkg安装包默认安装位置为shared文件夹,后续会遇到权限问题,所以放弃pkg安装.(说明:也许是安装时选择了本机所有用户可用的原因) 如果已经使用pkg文件方式安装了,卸载方法:找到该文件 /Library/Application Support/Jenkins/Uninstall.c

Jenkins自动化打包--war包

一.需求 Jenkins大多数情况下都是用来部署Java项目,Java项目有一个特点是>需要编译和打包的,一般情况下编译和打包都是用maven完成,所以系统环境中需要安装maven.因本公司仓库使用svn,这里通过svn部署. 二.实验环境 三.实验步骤 1.安装插件 "系统管理"--"管理插件"--"可选插件" Java 项目所需插件下载 2.安装打包工具maven (1)软件下载 wget http://mirror.bit.edu.c

Spring入门(四):使用Maven管理Spring项目

让我们先回顾下本系列的前3篇博客: Spring入门(一):创建Spring项目 Spring入门(二):自动化装配bean Spring入门(三):通过JavaConfig装配bean 1.为什么要使用Maven? 之前我们新建的项目,项目所要依赖的第三方jar包都在项目的类路径下(通常为lib目录),如下所示: 使用这种方式,我们无法知道第三方类库的依赖关系,比如导入一个特定的jar包时,可能此jar包还依赖于其他的jar包,其他的jar包又依赖于更多的jar包,这也是我们平常遇到的Clas

7)SSH批量管理分发项目

ssh服务认证类型介绍 从SSH客户端来看,SSH服务主要提供两种级别的安全验证,具体级别如下: 基于口令的安全验证: 基于口令的安全验证的方式就是大家一直在用的,只要知道服务器的SSH连接账号和口令,应用服务器的IP及开放的端口,默认为22,就可以通过SSH客户端登录到这台远程主机.此时,联机过程中所有传输的数据都是加密的. 基于口令的我们可以通过expect,pssh,sshpass实现批量管理. 期中集群:一键搭建及优化50台服务器集群 基于密钥的安全验证: 基于密钥的安全验证方式是指,需