Eclipse下配置Ant脚本并自动打包带签名的Android apk

eclipse虽然用的比较少,但是在一些古老的项目上还会用到滴,其中最麻烦的事情就是打带签名包的问题,不太方便,下面通过本文给大家记录下配置ant,自动打包带签名apk的过程,作为备份。(PC环境为MAC)

1,第一步得安ant,下载对应安装包,解压后配置环境变量:

export ANT_HOME="/Users/yanzi/work/apache-ant-1.9.4" export PATH=${PATH}:${ANT_HOME}/bin

通过which ant检查是否安装成功。

2,在项目目录下运行:android update project -p ./ 如果有依赖包,就到每个依赖包目录下再运行下这个命令。运行完这个命令后会多两个文件:build.xml 和 local.properties

local.properties文件内容:

sdk.dir=/Users/yanzi/work/android-tool/android-sdk-macosx

build.xml文件内容:

<?xml version="1.0" encoding="UTF-8"?> <project name="TongCheng" 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. --> <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.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" /> <!-- if sdk.dir was not set from one of the property file, then get it from the ANDROID_HOME env var. This must be done before we load project.properties since the 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 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' 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>

这两个文件都不用动,最上面project的name里写上自己想要的名字。然后项目根目录下新建个ant.properties,内容如下:

# This file is used to override default values used by the Ant build system. # # This file must be checked in Version Control Systems, as it is # integral to the build system of your project. # This file is only used by the Ant script. # You can use this to override default values such as # 'source.dir' for the location of your java source folder and # 'out.dir' for the location of your output folder. # You can also use it define how the release builds are signed by declaring # the following properties: # 'key.store' for the location of your keystore and # 'key.alias' for the name of the key to use. # The password will be asked during the build when you use the 'release' target. key.alias=com.tongcheng key.store=tongcheng.keystore key.store.password=12377778 key.alias.password=12377778

配置上keystore的相关信息。

这样先执行ant clean,然后执行ant release就ok了!

3,当然为了更爽,你还需要下面这个脚本:

vim release.sh,内容如下:

echo -----------------start--------- start=$(date +%s) ant clean ant release adb uninstall com.android.tongcheng adb install bin/TongCheng-release.apk end=$(date +%s) echo "----over,耗时$[${end} - ${start}]秒---"

之后每次想安装带签名的包,直接./release.sh即可!

以上所述是小编给大家介绍的Eclipse下配置Ant脚本并自动打包带签名的Android apk的相关内容,希望对大家有所帮助!

时间: 2024-10-25 05:02:24

Eclipse下配置Ant脚本并自动打包带签名的Android apk的相关文章

Eclipse下配置Ant脚本并自动打包带签名的Android apk_Android

eclipse虽然用的比较少,但是在一些古老的项目上还会用到滴,其中最麻烦的事情就是打带签名包的问题,不太方便,下面通过本文给大家记录下配置ant,自动打包带签名apk的过程,作为备份.(PC环境为MAC) 1,第一步得安ant,下载对应安装包,解压后配置环境变量: export ANT_HOME="/Users/yanzi/work/apache-ant-1.9.4" export PATH=${PATH}:${ANT_HOME}/bin 通过which ant检查是否安装成功. 2

使用Mybatis Generator结合Ant脚本快速自动生成Model、Mapper等文件的方法_java

MyBatis简介: MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以使用简单的XML或注解用于配置和原始映射,将接口和Java的POJO(Plain Old Java Objects,普通的Java对象)映射成数据库中的记录. 相关阅读:MyBatis入门学习教程(一)-MyBatis快速入门 使用过Mybatis的同学都知道,针对每一个项目中使用到的数据库表都需要建

eclipse下配置外部工具javap命令中文乱码怎么解决??

问题描述 eclipse下配置外部工具javap命令中文乱码怎么解决?? 解决方案 找到解决方法了,windows的cmd默认是bgk编码,eclipse貌似默认utf-8 所以按照下面的办法就没问题了 首先Windows->Preferences, 然后选择General下面的Workspace. Text file encoding选择Other GBK, 如果没有GBK的选项, 没关系, 直接输入GBK三个字母, Apply, GBK编码的中文, 已经不是乱码了 解决方案二: cmd下中文

JAVA EE Eclipse下配置Tomcat服务器

在进行Java web编程之前,必须要进行web服务器的配置,这里选择在Java EE(版本) Eclipse中进行服务器的配置.当然了,在安装Java EE Eclipse之前要先安装JDK,并且要在环境变量中配置好JDK的安装目录,在这里不再多说,如果不清楚,可以看前面写的一篇"在win7下面安装JDK(以32位系统为例)"的文章.这里就假设你已经安装好了JDK,并且已经配置好环境变量.      Java EE Eclipse可以去Eclipse公司的网页上去下载最新版本的,但是

Eclipse下使用ANT编译提示OutOfMemory的解决方法_java

出现此错我的原因是由于ant在执行的时候,默认给JVM的内存不够,需要通过设定启动参数,增加允许使用的内存量.如果是通过命令行直接执行ANT,那么,直接修改启动命令即可.但是,在Eclipse上执行,命令行的设定就不好用了. 自己也是试验了好几次,最后终于搞定. 争取的设定方法是,直接在Eclipse的执行JVM上设定参数,如下: 1.打开Window->Preferences->Java->Installed JREs 2.选中默认(正在)使用的JDK 3.点击Edit..并向Defa

eclipse 下配置heritrix 运行出现这种情况,为何啊 !求助

问题描述 15:38:05.495EVENTStartingJetty/4.2.2315:38:05.565EVENTStartedWebApplicationContext[/,HeritrixConsole]15:38:05.576EVENTThescratchDiryouspecified:E:javacodeHHtargetjsp-compiled-developmentisunusable.15:38:05.590WARN!!Failedtostart:SocketListener@1

[原] Jenkins Android 自动打包配置(转)

一.Jenkins自动打包配置 目标:1. 自动打包:2. 自动上传:3. 友好下载 1. Jenkins简介 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作. 减少重复劳动,减少人工成本. 持续.自动地构建/测试软件项目: 监控一些定时执行的任务: 2. Jenkins配置 添加git plugin和 role插件 设置人员权限,根据角色授权 启动访问http://ip/8080即可,见下3.1 开机自启脚本 添加git项目,配置脚本,见下3.2 项目打包脚本和3.

android使用ant自动打包(包括更改文件中的内容)

在ant打包过程中的一些学习所得以及用于这个项目的build文件的大体思路如下: 首先配置好整个系统所需的ant编译环境,在build.properties中配置好相关的参数.(build.properties文件主要包涵了一些在编译中需要用到工具的路径,以及一些需要配置的参数,如应用包名,项目名,以及一些需要传入的参数.写在build.properties中主要是为了方便配置文件的集中管理)在这次ant打包的需求中,需要修改一个java文件中的两个常量属性.根据这样的需求,首先需要拿到普通an

java 打包成jar后无法运行(在eclipse下可以运行)???

问题描述 打包成jar后无法运行(在eclipse下可以运行)用java-jarxxx.jar命令可以运行!就是双击无法运行!以前可以双击运行重装JDK,后就无法双击运行了,但在eclipse下运行完全正常.请各位指点迷津!!! 解决方案 解决方案二:默认用Java-jar运行解决方案三:是这样的jar是不可以运行的,我们感觉它可以直接运行其实是可以用java打开,就像图片.视频可以双击打开一样.你重装java之后java.exe找不到了,所以就打不开了,你需要把%JAVA_HOME%bin加到