Ant 自动打包配置过程

2024-06-17 10:18
文章标签 ant 打包 自动 配置 过程

本文主要是介绍Ant 自动打包配置过程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

  • ant 安装网上很多这里就不多说,自己百度,这里只是提示下下,环境变量问题

         path里最好直接用绝对路径配置,ANT_HOME 有时会不识别,具体原因未知。

Ant 打包apk步骤如下:

  • 生成build.xml文件
  1. 在dos下,进入到我们项目的根目录,执行 android update project -n test1 -p . 命令(注意-n表示项目的名称,-p参数后面有个点 表示当前目录)。
  2. 执行命令后,会在我们的项目下,生成build.xml和local.properties文件。
  3. build.xml 内容如下
<?xml version="1.0" encoding="UTF-8"?>
<project name="test1" 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 intoVersion Control Systems. --><property file="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.dirThe name of the source directory. Default is 'src'.out.dirThe name of the output directory. Default is 'bin'.For other overridable properties, look at the beginning of the rulesfiles in the SDK, at tools/ant/build.xmlProperties related to the SDK location or the project target shouldbe updated using the 'android' tool with the 'update' action.This file is an integral part of the build system for yourapplication and should be checked into Version Control Systems.--><!-- 我们在项目的根目录自己创建 --><property file="ant.properties" /><!-- 替换start --><target name="buildTime"><replaceregexp byline="false" file="./TestProxy.java" replace="public static int mProxy = 34"/></target><!-- 替换end --><!-- if sdk.dir was not set from one of the property file, thenget it from the ANDROID_HOME env var.This must be done before we load project.properties sincethe proguard config can use sdk.dir --><property environment="env" /><condition property="sdk.dir" value="${env.ANDROID_HOME}"><isset property="env.ANDROID_HOME" /></condition><!-- 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 librarydependencies. 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 yourapplication and should be checked into Version Control Systems. --><loadproperties srcFile="project.properties" /><!-- quick check on sdk.dir --><failmessage="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."unless="sdk.dir"/><!--Import per project custom build rules if present at the root of the project.This is the place to put custom intermediary targets such as:-pre-build-pre-compile-post-compile (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})-post-package-post-build-pre-clean--><!-- 我们在项目的根目录自己创建 --><import file="custom_rules.xml" optional="true" /><!-- 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>
  • custom_rules.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules" ><!-- 引用ant-contlib这个扩展包,声明一下 --><taskdef resource="net/sf/antcontrib/antcontrib.properties" ><classpath><pathelement location="${ant.ANT_HOME}/lib/ant-contrib-1.0b3.jar" /></classpath></taskdef><!-- 引用xmltask --><taskdef name="xmltask"classname="com.oopsconsultancy.xmltask.ant.XmlTask"classpath="./xmltask-1.16.jar" /><!-- 定义一个时间变量,打完包后跟渠道号一起命名apk --><tstamp><formatpattern="yyyyMMddhhmm"property="pktime"unit="hour" /></tstamp><!-- 创建apk存放目录 --><mkdir dir="${apk.dir}" ></mkdir><!-- 替换参数 然后打包APK --><target name="replace_parameter" ><!-- 替换服务器配置 --><replaceregexpbyline="false"encoding="UTF-8"flags="g" ><!-- 这个是正则表达式匹配appconfig中url的值 --><regexp pattern="url>(.*)&lt;/url" /><substitution expression="url>${url}&lt;/url" /><filesetdir=""includes="res/xml/appconfig.xml" /></replaceregexp><replaceregexpbyline="false"encoding="UTF-8"flags="g" ><!-- 这个是正则表达式匹配appconfig中url_update的值 --><regexp pattern="url_update>(.*)&lt;/url_update" /><substitution expression="url_update>${url_update}&lt;/url_update" /><filesetdir=""includes="res/xml/appconfig.xml" /></replaceregexp></target><!-- 打包测试环境命令就用这个 --><target name="deploytest" ><!-- 传服务器配置参数到 replace_parameter这个打包target --><antcall target="replace_parameter" ><paramname="url"value="${test.server.url}" /><paramname="url_update"value="${test.server.url.update}" /></antcall><echo message="------ init target run --------- ${test.server.url}" />  <!-- 执行循环打包target foreach_replacechannel --><antcall target="foreach_replacechannel" ><!-- apk命名时候用到的参数 --><paramname="deploy_environment"value="${test.tag.name}" /></antcall></target><!-- 打包生产环境命令就用这个 --><target name="deployrel" ><!-- 传服务器配置参数到 replace_parameter这个打包target --><antcall target="replace_parameter" ><paramname="url"value="${rel.server.url}" /><paramname="url_update"value="${rel.server.url.update}" /></antcall><!-- 执行循环打包target foreach_replacechannel --><antcall target="foreach_replacechannel" ><!-- apk命名时候用到的参数 --><paramname="deploy_environment"value="${release.tag.name}" /></antcall></target><!-- 循环打包的target --><target name="foreach_replacechannel" ><!-- 开始循环打包,从market_channels参数中取出一个渠道号用channel标识,然后通过正则修改manifest文件 --><foreachdelimiter=","list="${market_channels}"param="channel"target="modify_manifest" ></foreach></target><target name="modify_manifest" ><replaceregexpbyline="false"encoding="UTF-8"flags="g" ><!-- 这个是正则表达式匹配manifest中meta,我用的友盟的统计,我 AndroidManifest中的配置为: -->
<!-- 			<meta-data android:value="360shichang" android:name="UMENG_CHANNEL" --><regexp pattern="android:value=&quot;(.*)&quot; android:name=&quot;UMENG_CHANNEL&quot;" /><substitution expression="android:value=&quot;${channel}&quot; android:name=&quot;UMENG_CHANNEL&quot;" /><filesetdir=""includes="AndroidManifest.xml" /></replaceregexp><xmltask source="AndroidManifest.xml" dest="AndroidManifest.xml" encoding="UTF-8" ><attr path="//manifest" attr="android:versionName" value="${app.version}" /><attr path="//manifest" attr="android:versionCode" value="${app.version.code}"/></xmltask><!-- 这里设置最终生成包的存放目录以及apk的名称,注意这里是文件名称,所以变量中不允许出现违规字符,否则将无法生成最终的apk(会出现output is not valid 的错误) --><propertyname="out.final.file"location="${apk.dir}/${app.name}_${channel}_${deploy_environment}_${pktime}.apk" /><antcall target="clean" /><antcall target="release" /></target></project>
  • 打包
  1. 在dos下执行ant deployrel 成功,会在我们项目的目录下,apk下生成对应的apk如图

  • 结束

附上 ant中需要我们手动下载的jar包

https://download.csdn.net/download/u011794223/10892827  xmltask时用

https://mvnrepository.com/artifact/ant-contrib/ant-contrib/1.0b3 通过maven,下载ant-contrib-1.0b3.jar

这篇关于Ant 自动打包配置过程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1069171

相关文章

Linux 安装、配置Tomcat 的HTTPS

Linux 安装 、配置Tomcat的HTTPS 安装Tomcat 这里选择的是 tomcat 10.X ,需要Java 11及更高版本 Binary Distributions ->Core->选择 tar.gz包 下载、上传到内网服务器 /opt 目录tar -xzf 解压将解压的根目录改名为 tomat-10 并移动到 /opt 下, 形成个人习惯的路径 /opt/tomcat-10

uniapp接入微信小程序原生代码配置方案(优化版)

uniapp项目需要把微信小程序原生语法的功能代码嵌套过来,无需把原生代码转换为uniapp,可以配置拷贝的方式集成过来 1、拷贝代码包到src目录 2、vue.config.js中配置原生代码包直接拷贝到编译目录中 3、pages.json中配置分包目录,原生入口组件的路径 4、manifest.json中配置分包,使用原生组件 5、需要把原生代码包里的页面修改成组件的方

C/C++的编译和链接过程

目录 从源文件生成可执行文件(书中第2章) 1.Preprocessing预处理——预处理器cpp 2.Compilation编译——编译器cll ps:vs中优化选项设置 3.Assembly汇编——汇编器as ps:vs中汇编输出文件设置 4.Linking链接——链接器ld 符号 模块,库 链接过程——链接器 链接过程 1.简单链接的例子 2.链接过程 3.地址和

IDEA配置Tomcat远程调试

因为不想把本地的Tomcat配置改乱或者多人开发项目想测试,本文主要是记录一下,IDEA使用Tomcat远程调试的配置过程,免得一段时间不去配置到时候忘记(毕竟这次是因为忘了,所以才打算记录的…) 首先在catalina.sh添加以下内容 JAVA_OPTS="-Dcom.sun.management.jmxremote=-Dcom.sun.management.jmxremote.port

Steam邮件推送内容有哪些?配置教程详解!

Steam邮件推送功能是否安全?如何个性化邮件推送内容? Steam作为全球最大的数字游戏分发平台之一,不仅提供了海量的游戏资源,还通过邮件推送为用户提供最新的游戏信息、促销活动和个性化推荐。AokSend将详细介绍Steam邮件推送的主要内容。 Steam邮件推送:促销优惠 每当平台举办大型促销活动,如夏季促销、冬季促销、黑色星期五等,用户都会收到邮件通知。这些邮件详细列出了打折游戏、

微信小程序开发必知必会:文件结构和基本配置

一、微信小程序基本文件结构 1.  project.config.json:项目的基本配置文件,包括项目名称、appid、项目目录、页面文件夹等。     {"setting": {"urlCheck": false,"es6": true,"postcss": true,"nodeModulesPath": "D:\\\\node_modules"},"appid": "wxd678e

【杂记-浅谈DHCP动态主机配置协议】

DHCP动态主机配置协议 一、DHCP概述1、定义2、作用3、报文类型 二、DHCP的工作原理三、DHCP服务器的配置和管理 一、DHCP概述 1、定义 DHCP,Dynamic Host Configuration Protocol,动态主机配置协议,是一种网络协议,主要用于在IP网络中自动分配和管理IP地址以及其他网络配置参数。 2、作用 DHCP允许计算机和其他设备通

WordPress网创自动采集并发布插件

网创教程:WordPress插件网创自动采集并发布 阅读更新:随机添加文章的阅读数量,购买数量,喜欢数量。 使用插件注意事项 如果遇到404错误,请先检查并调整网站的伪静态设置,这是最常见的问题。需要定制化服务,请随时联系我。 本次更新内容 我们进行了多项更新和优化,主要包括: 界面设置:用户现在可以更便捷地设置文章分类和发布金额。代码优化:改进了采集和发布代码,提高了插件的稳定

Pycharm配置conda环境(解决新版本无法识别可执行文件问题)

引言: 很多小伙伴在下载最新版本的pycharm或者更新到最新版本后为项目配置conda环境的时候,发现文件夹目录中无法显示可执行文件(一般为python.exe),以下就是本人遇到该问题后试验和解决该问题的一些方法和思路。 一般遇到该问题的人群有两种,一种是刚入门对pycharm进行conda环境配置的小白(例如我),不熟悉相关环境配置的操作和过程,还有一种是入坑pycharm有段时间的老手

【青龙面板辅助】JD商品自动给好评获取京豆脚本

1.打开链接 开下面的链接进入待评价商品页面 https://club.jd.com/myJdcomments/myJdcomments.action?sort=0 2.登陆后执行脚本 登陆后,按F12键,选择console,复制粘贴以下代码,先运行脚本1,再运行脚本2 脚本1代码 可以自行修改评价内容。 var content = '材质很好,质量也不错,到货也很快物流满分,包装快递满