[转]使用ant让Android自动打包的build.xml,自动生成签名的apk文件(支持android4.0以上的版本)
在android4.0以后的sdk里那个脚本就失效了,主要是因为 apkbuilder这个程序不见了;
人家sdk升级,我们的脚本也要跟上趟,修改一下喽。
上网一查,大家的文章还停留在我去年的脚本程度,算了,自己动手查阅了资料之后,具体实现如下:
先输一下生成key的命令
keytool -genkey -alias android.keystore -keyalg RSA -validity 20000 -keystore android.keystore
输入keystore密码:
再次输入新密码:
您的名字与姓氏是什么?
[Unknown]: Pelephone
您的组织单位名称是什么?
[Unknown]: Pelephone
您的组织名称是什么?
[Unknown]: Pelephone
您所在的城市或区域名称是什么?
[Unknown]: 广州
您所在的州或省份名称是什么?
[Unknown]: 广东
该单位的两字母国家代码是什么
[Unknown]: 86
CN=Pelephone, OU=Pelephone, O=Pelephone, L=广州, ST=广东, C=86 正确吗?
[否]: y
在工程的根目录 创建2个文件,分别:
1、build.xml
2、build.properties
build.xml的内容:
- <?xml version="1.0" encoding="UTF-8"?>
- <project name="autoDeployAPK" default="deploy">
- <!-- 使用第三方的ant包,使ant支持for循环-->
- <taskdef resource="net/sf/antcontrib/antcontrib.properties">
- <classpath>
- <pathelement location="lib/ant-contrib-1.0b3.jar"/>
- </classpath>
- </taskdef>
- <property file="build.properties" />
- <!-- 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" />
- -->
- <property name="jar.libs.dir" value="${jar.libs.dir}" />
- <!-- 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.dir}/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 an env var"
- unless="sdk.dir"/>
- <property name="channelname" value="pateo" />
- <property name="channelkey" value="12347" />
- <!--循环打包 -->
- <target name="deploy">
- <foreach target="modify_manifest" list="${channel.list}" param="nameandchannel" delimiter=","></foreach>
- </target>
- <target name="modify_manifest">
- <!-- 获取渠道名字 -->
- <propertyregex override="true" property="channelname" input="${nameandchannel}" regexp="(.*):" select="\1"/>
- <!-- 获取渠道号码 -->
- <propertyregex override="true" property="channelkey" input="${nameandchannel}" regexp=":(.*)" select="\1"/>
- <!-- 正则匹配替换渠道号
- <replaceregexp flags="g" byline="false" encoding="UTF-8">
- <regexp pattern='meta-data android:name="CHANNEL" android:value="(.*)"' />
- <substitution expression='meta-data android:name="CHANNEL" android:value="${channelkey}"' />
- <fileset dir="" includes="AndroidManifest.xml" />
- </replaceregexp>-->
- <property name="out.final.file"
- location="${apk.out.dir}/${project.name}_${channelname}_${project.version}.apk" />
- <antcall target="release" />
- </target>
- <!-- 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>
- -->
- <!--如果项目包含了jni代码,希望在打包时自动重新编译so库,可以修改build.xml文件。
- 修改方法为,在引用sdk的build.xml文件之前添加如下target:-->
- <!--
- <target name="-pre-build" depends="-ndk-build">
- </target>
- <target name="-ndk-build">
- <exec executable="ndk-build" failonerror="true">
- <arg value="clean" />
- </exec>
- <exec executable="ndk-build" failonerror="true" />
- </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: 导入anroid sdk 默认的ant写好的build.xml -->
- <import file="${sdk.dir}/tools/ant/build.xml" />
- </project>
这个文件主要就是打包的指令,其中大家不难看出
- <import file="${sdk.dir}/tools/ant/build.xml" />
自动引用并且执行了你的sdk目录下tools/ant/build.xml,大家有精力可以自己看看这个文件.
build.properties的内容:
- #Save
- #Wed Oct 23 15:47:27 CST 2013
- project.name=MOBILE_ANDROID_PROJECT
- jar.libs.dir=libs
- build.first=false
- key.alias=maomao
- key.alias.password=maomao
- channel.list=test1\:100411-f91d7ad6c99688b587b299d2c507679d,test2\:100411-f91d7ad6c99688b587b299d2c507679d
- java.dir=C\:\\Program Files (x86)\\Java\\jdk1.6.0_10
- key.store=C\:\\changeself\\test.keystore
- project.dir=C\:\\changeself\\project_android
- sdk.dir=C\:\\changeself\\adt-bundle-windows-x86-20130729\\sdk
- project.version=1.0.3
- key.store.password=maomao
- apk.out.dir=apk
这个文件里面,
project.name 就是你的工程名,其实最后体现在APK的名字
key.alias和key.alias.password是你的 签名文件里的东西,自己先生成去
channel.list就是你的渠道名字,支持多个渠道,test1和test2,......testn,自己按照格式去填写,你写了几个渠道就会生成几个apk
java.dir 自己的java本机的安装目录
key.store 自己签名文件的本机存放目录
project.dir 你的工程本机存放目录
sdk.dir 你的android sdk本机存放目录
project.version 工程的版本号,最后也会体现在apk的名字里
key.store.password
apk.out.dir 在你的工程根目录存放apk生成的目录
ok,配置好上述2个文件后,在cmd命令行下,键入你的工程目录,执行 ant命令
最后会在你的apk.out.dir生成你需要的apk文件
转自:http://weibo.com/changeself
[转]使用ant让Android自动打包的build.xml,自动生成签名的apk文件(支持android4.0以上的版本)的更多相关文章
- Android Studio Gradle 多渠道自动打包,动态修改HostUrl,签名apk,混淆配置详解
文/ skay csdn博客:http://blog.csdn.net/sk719887916/article/details/40541163 最近遇到项目从Eclispe迁移到Android st ...
- 深入浅出 - Android系统移植与平台开发(三)- 编译并运行Android4.0模拟器
作者:唐老师,华清远见嵌入式学院讲师. 1. 编译Android模拟器 在Ubuntu下,我们可以在源码里编译出自己的模拟器及SDK等编译工具,当然这个和在windows里下载的看起来没有什么区别 ...
- Android项目实战(三十一):异步下载apk文件并安装(非静默安装)
前言: 实现异步下载apk文件 并 安装.(进度条对话框显示下载进度的展现方式) 涉及技术点: 1.ProgressDialog 进度条对话框 用于显示下载进度 2.AsyncTask ...
- Android Studio 之生成正式签名的 APK 文件
生成 APK 文件 •步骤 点击 Build -> Generate Signed...... : 来到如下界面: 选择 APK 选项,点击 Next 来到如下界面: 如果你电脑上没有一个正式 ...
- 五 Android Studio打包Eegret App (包名和签名,打出正式包)
一 定义包名 如下图,在AndroidManifest.xml中的package就是包名 二 创建keystore 选择Build->Generate Signed APK 选择create n ...
- 如何用Android studio生成正式签名的APK文件
必须签名之后才可以发布到app商店中. 平时的调试的app都有默认的签名. 下面是生成带签名的APK的步骤: 1. Build 选择 Generate Signed APK 2. 弹出框,第一次选择C ...
- Android之APK文件签名——keytool和jarsigner
一.生成密钥库将位置定位在jdk的bin文件中,输入以下命名行:keytool -genkey -alias ChangeBackgroundWidget.keystore -keyalg RSA - ...
- Android 自动编译、打包生成apk文件 2 - 使用原生Ant方式
from://http://blog.csdn.net/androiddevelop/article/details/11100109 相关文章列表: <Android 自动编译.打包生成apk ...
- 【转】Android项目使用Ant打包,生成build.xml
记不住,于是原帖转过来,请看原帖:http://blog.csdn.net/ms03001620/article/details/8490238 一.生成build.xml Eclipse中使用Ant ...
随机推荐
- CentOS升级MySQL到5.5
centOS的yum安装的MySQL是5.1版本,可通过官方的rpm包安装5.5版本 # 查看安装的相关项 rpm -qa|grep -i mysql # 停止服务 service mysqld st ...
- RabbitMQ(一) -- Hello world
RabbitMQ -- Hello world RabbitMQ使用AMQP通信协议(AMQP是一个提供统一消息服务的应用层标准协议,基于此协议的客户端与消息中间件可传递消息,并不受客户端/中间件不同 ...
- DOS与Linux的换行字符
一.vim打开window下的文件出现 ^M 首先理解,dos(windows)下建立的文件的换行是 ^M\$ (CRLF) ,而在Linux下面,仅仅是以 \$ (LF) 来做断行符号: (^M\ ...
- JS获取元素CSS值的各种方法分析
先来看一个实例:如何获取一个没有设置大小的字体? <!DOCTYPE html> <html lang="en"> <head> <met ...
- atitit.团队建设总结o6o fix
atitit.团队建设o6o fix #----- 无限放大梦想 2 要有自己的方向...主动添加自己的东东.. 3 有几个tech site,能晓得最新的的知识.. 3 有问题多交流, 3 失败的造 ...
- atitit.dw不能显示正确的百分比高度in dw的解决
atitit.dw不能显示正确的百分比高度in dw的解决 div 设置35%的高度,三,不能正确的显示高度...环境dw cs6 但是设置161px奏能ok了...表明这个是dw的一个bug... ...
- Leetcode 283 Move Zeroes 字符串
class Solution { public: void moveZeroes(vector<int>& nums) { ; ; i< nums.size(); ++i){ ...
- 深入学习系列--Data Structure--02字符串
字符串可以说是我们实际工作中使用最多的数据类型了,常见的字符串操作包括链接.取子串.格式化等.这部分内容总体来说比较容易理解,最难的部分要数字符串的模式匹配方法了,尤其是KMP算法,需要通过实践加以记 ...
- XXXXXXXX系统失败总结
2013年底因同事离职接手了他负责的<XXXXXX病例系统>,当时由3个刚毕业的同事在做,框架使用Spring+Hibernate+SpringMVC+EasyUI,因为当时的主力开发人员 ...
- navigationBar设置透明
//设置全透明方式 一.完全不用图片(iOS7之后有效)[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBar ...