Android项目使用Ant打包,生成build.xml


一、生成build.xml

Eclipse中使用Ant为Android打包并且签名

SDK自带文件 在<sdk>tools/ant目录下这3个文件

 

其中build.xml和uibuild.xml中定义了大量基础构建方法和打包策略。我们只需要建立我们自己的build.xml并且存放在项目的根目录下,然后引用一下<sdk>tools/ant/build.xml即可。当然也可以拷贝它然后直接操作。

 

那么如何。以项目AntForAndroid为例。生成一个针对该项目的build.xml呢?

这里需要一个工具。就是SDK自带的android.bat .所在目录<sdk>tools/android.bat

然后通过命令行执行“android update project --path .”即可。完毕后即可通过android命令在当前项目目录下生成一个build.xml文件

 

新生成的3个文件 build.xml,local.properties,proguard-project.exe

二、配置ant.properties 

 

在项目根目录新建一个ant.properties文件(不要去改变他的名字,因为<sdk>\tools\ant\build.xml会引用到这个名字)

并且在里面写入一下数据:

#keystore文件的目录,因为在根目录下所以直接写名字了

key.store=android.keystore

#这个名字就是在生成keystore时那个alias字段的值

key.alias=android

#两个密码分别写建立keystore时的两个密码

key.store.password=(your pwd)

key.alias.password=(your pwd)

 

三、实现自动打签名apk

右键点击项目中的build.xml->run as... 先查看下有多少种任务,当然这些任务都是来自<sdk>\tools\ant\build.xml,项目里的只是引用了它

 

 

窗口打开

 

默认的选择在help上。打签名包的时候执行release这个任务即可。

 

按照以上的步骤配置好之后就能生成签名apk。并且大家可以通过学习<sdk>\tools\ant\build.xml来理解ant的基本奥妙。

最后在项目跟目录\bin下生成apk包

 

Ant是非常强大的。可以实现一下功能

例如

1.在生成apk的文件名里加上日期。

2.把apk文件自动通过邮件发给其他人。

3.apk文件上传服务器

等等

 

第二篇:http://www.xmumu.com/post/2011-11-22/7022215

使用Android Studio 进行配置的时候需要注意(请留意下面遇到的红色字体)。

通过Android命令自动编译出build.xml文件

用途: 做自动集成编译环境.

环境搭配我就不说了(SDK/环境变量等).
(就是把sdk下tools配置到环境变量中)
进入cmd界面.
进入项目目录.


输入: android.bat list target  来查询我们现有的版本list有哪些.



记住这个ID号码,下的代码面会用到.
输入: android update project -n ButtonDemo -t 1 -p E:\workspace\android\ButtonDemo

-n 
对应的是项目名称
-t 就是我们之前查询的SDK版本对应的ID,大家根据自己项目的sdk版本做出选择即可,我这个是android-8 所以用ID 1 .

(每个人本地的sdk版本不一样,导致对应的id会有差异,不要生搬硬套)
-p就是生成的路径(在Android Studio中貌似是AndroidMeniFest.xml所在的目录)
成功后显示:


好了以下是生成的build.xml代码段:

<?xml version="1.0" encoding="UTF-8"?>

<project name="ButtonDemo" default="help">

 

    <!-- The local.properties file is created and updated by the 'android' tool.

         It contains the path to the SDK. It should *NOT* be checked into

         Version Control Systems. -->

    <loadproperties srcFile="local.properties" />

 

    <!-- The ant.properties file can be created by you. It is only edited by the

         'android' tool to add properties to it.

         This is the place to change some Ant specific build properties.

         Here are some properties you may want to change/update:

 

         source.dir

             The name of the source directory. Default is 'src'.

         out.dir

             The name of the output directory. Default is 'bin'.

 

         For other overridable properties, look at the beginning of the rules

         files in the SDK, at tools/ant/build.xml

 

         Properties related to the SDK location or the project target should

         be updated using the 'android' tool with the 'update' action.

 

         This file is an integral part of the build system for your

         application and should be checked into Version Control Systems.

 

         -->

    <property file="ant.properties" />

 

    <!-- The project.properties file is created and updated by the 'android'

         tool, as well as ADT.

 

         This contains project specific properties such as project target, and library

         dependencies. Lower level build properties are stored in ant.properties

         (or in .classpath for Eclipse projects).

 

         This file is an integral part of the build system for your

         application and should be checked into Version Control Systems. -->

    <loadproperties srcFile="project.properties" />

 

    <!-- quick check on sdk.dir -->

    <fail

            message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"

            unless="sdk.dir"

    />

 

 

<!-- extension targets. Uncomment the ones where you want to do custom work

     in between standard targets -->

<!--

    <target name="-pre-build">

    </target>

    <target name="-pre-compile">

    </target>

 

    /* This is typically used for code obfuscation.

       Compiled code location: ${out.classes.absolute.dir}

       If this is not done in place, override ${out.dex.input.absolute.dir} */

    <target name="-post-compile">

    </target>

-->

 

    <!-- Import the actual build file.

 

         To customize existing targets, there are two options:

         - Customize only one target:

             - copy/paste the target into this file, *before* the

               <import> task.

             - customize it to your needs.

         - Customize the whole content of build.xml

             - copy/paste the content of the rules files (minus the top node)

               into this file, replacing the <import> task.

             - customize to your needs.

 

         ***********************

         ****** IMPORTANT ******

         ***********************

         In all cases you must update the value of version-tag below to read 'custom' instead of an integer,

         in order to avoid having your file be overridden by tools such as "android update project"

    -->

    <!-- version-tag: 1 -->

    <import file="${sdk.dir}/tools/ant/build.xml" />

</project>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 可以使用以下命令指定使用 build.xml 文件进行 Ant 构建: ``` ant -buildfile build.xml ``` 其中,-buildfile 参数用于指定要使用的构建文件。在这个例子中,我们指定使用 build.xml 文件进行构建。 ### 回答2: Ant是一个非常流行的Java构建工具,可以用来构建Java项目打包和部署Java应用等。在使用Ant进行构建时,我们需要指定构建所使用build.xml文件。 build.xmlAnt构建工具中的一个配置文件,用来指定构建任务、目标和相关操作,也被称为构建脚本。在build.xml中,开发者可以指定构建过程中要执行的任务和操作,包括编译Java源代码、打包应用、部署到目标服务器等。 在指定Ant构建命令时,我们需要使用命令行或者IDE中的Ant插件。比如,在命令行中执行Ant构建命令时,可以在命令行中指定build.xml文件的路径,例如: ant -buildfile /path/to/build.xml 这个命令会告诉Ant构建工具使用指定路径下的build.xml文件来执行构建任务。如果没有指定-buildfile参数,则默认使用当前目录下的build.xml文件。 在IDE中使用Ant插件时,我们也需要指定build.xml文件的路径。具体操作可以根据不同的IDE而有所不同,通常可以在项目配置或者菜单中进行设置。 总之,无论是在命令行还是IDE中使用Ant构建工具,我们都需要指定构建过程中所使用build.xml文件。该文件定义了构建任务和操作,是Ant构建工具的重要组成部分。 ### 回答3: Ant是一种软件构建工具,它可以自动化地构建软件项目。该工具可以读取一个XML文件(通常命名为build.xml),其中包含了构建项目所需要的配置信息和任务指令,从而生成可执行的软件。 在使用Ant构建项目时,我们可以通过指定build.xml文件来告诉Ant该如何构建项目。具体来说,可以在命令行中使用ant命令,并指定-buildfile选项来指定build.xml文件的路径。例如,假设build.xml文件位于当前工作目录下,我们可以使用以下命令来启动Ant构建: ant -buildfile build.xml 在执行此命令后,Ant会读取build.xml文件,并按照文件中所包含的指令和配置信息来构建项目。通过指定build.xml文件,我们可以非常方便地掌控构建过程,并定制所需要的构建操作,从而满足项目的特定需求。 总之,Ant通过读取并解析build.xml文件来构建软件项目,因此我们可以通过指定build.xml文件来指导Ant工具如何构建项目。这一过程十分简单,只需要在命令行中加入-buildfile选项并指定正确的文件路径即可。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值