在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的内容:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="autoDeployAPK" default="deploy">
  3. <!-- 使用第三方的ant包,使ant支持for循环-->
  4. <taskdef resource="net/sf/antcontrib/antcontrib.properties">
  5. <classpath>
  6. <pathelement location="lib/ant-contrib-1.0b3.jar"/>
  7. </classpath>
  8. </taskdef>
  9. <property file="build.properties" />
  10. <!-- The local.properties file is created and updated by the 'android' tool.
  11. It contains the path to the SDK. It should *NOT* be checked into
  12. Version Control Systems.
  13. <property file="local.properties" />
  14. -->
  15. <!-- The ant.properties file can be created by you. It is only edited by the
  16. 'android' tool to add properties to it.
  17. This is the place to change some Ant specific build properties.
  18. Here are some properties you may want to change/update:
  19. source.dir
  20. The name of the source directory. Default is 'src'.
  21. out.dir
  22. The name of the output directory. Default is 'bin'.
  23. For other overridable properties, look at the beginning of the rules
  24. files in the SDK, at tools/ant/build.xml
  25. Properties related to the SDK location or the project target should
  26. be updated using the 'android' tool with the 'update' action.
  27. This file is an integral part of the build system for your
  28. application and should be checked into Version Control Systems.
  29. <property file="ant.properties" />
  30. -->
  31. <property name="jar.libs.dir" value="${jar.libs.dir}" />
  32. <!-- The project.properties file is created and updated by the 'android'
  33. tool, as well as ADT.
  34. This contains project specific properties such as project target, and library
  35. dependencies. Lower level build properties are stored in ant.properties
  36. (or in .classpath for Eclipse projects).
  37. This file is an integral part of the build system for your
  38. application and should be checked into Version Control Systems. -->
  39. <loadproperties srcFile="${project.dir}/project.properties" />
  40. <!-- quick check on sdk.dir -->
  41. <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
  42. unless="sdk.dir"/>
  43. <property name="channelname" value="pateo" />
  44. <property name="channelkey" value="12347" />
  45. <!--循环打包 -->
  46. <target name="deploy">
  47. <foreach target="modify_manifest" list="${channel.list}" param="nameandchannel" delimiter=","></foreach>
  48. </target>
  49. <target name="modify_manifest">
  50. <!-- 获取渠道名字 -->
  51. <propertyregex override="true" property="channelname" input="${nameandchannel}" regexp="(.*):" select="\1"/>
  52. <!-- 获取渠道号码 -->
  53. <propertyregex override="true" property="channelkey" input="${nameandchannel}" regexp=":(.*)" select="\1"/>
  54. <!-- 正则匹配替换渠道号
  55. <replaceregexp flags="g" byline="false" encoding="UTF-8">
  56. <regexp pattern='meta-data android:name="CHANNEL" android:value="(.*)"' />
  57. <substitution expression='meta-data android:name="CHANNEL" android:value="${channelkey}"' />
  58. <fileset dir="" includes="AndroidManifest.xml" />
  59. </replaceregexp>-->
  60. <property name="out.final.file"
  61. location="${apk.out.dir}/${project.name}_${channelname}_${project.version}.apk" />
  62. <antcall target="release" />
  63. </target>
  64. <!-- extension targets. Uncomment the ones where you want to do custom work
  65. in between standard targets -->
  66. <!--
  67. <target name="-pre-build">
  68. </target>
  69. <target name="-pre-compile">
  70. </target>
  71. /* This is typically used for code obfuscation.
  72. Compiled code location: ${out.classes.absolute.dir}
  73. If this is not done in place, override ${out.dex.input.absolute.dir} */
  74. <target name="-post-compile">
  75. </target>
  76. -->
  77. <!--如果项目包含了jni代码,希望在打包时自动重新编译so库,可以修改build.xml文件。
  78. 修改方法为,在引用sdk的build.xml文件之前添加如下target:-->
  79. <!--
  80. <target name="-pre-build" depends="-ndk-build">
  81. </target>
  82. <target name="-ndk-build">
  83. <exec executable="ndk-build" failonerror="true">
  84. <arg value="clean" />
  85. </exec>
  86. <exec executable="ndk-build" failonerror="true" />
  87. </target>
  88. -->
  89. <!-- Import the actual build file.
  90. To customize existing targets, there are two options:
  91. - Customize only one target:
  92. - copy/paste the target into this file, *before* the
  93. <import> task.
  94. - customize it to your needs.
  95. - Customize the whole content of build.xml
  96. - copy/paste the content of the rules files (minus the top node)
  97. into this file, replacing the <import> task.
  98. - customize to your needs.
  99. ***********************
  100. ****** IMPORTANT ******
  101. ***********************
  102. In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
  103. in order to avoid having your file be overridden by tools such as "android update project"
  104. -->
  105. <!-- version-tag: 导入anroid sdk 默认的ant写好的build.xml -->
  106. <import file="${sdk.dir}/tools/ant/build.xml" />
  107. </project>

这个文件主要就是打包的指令,其中大家不难看出

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

自动引用并且执行了你的sdk目录下tools/ant/build.xml,大家有精力可以自己看看这个文件.

build.properties的内容:

  1. #Save
  2. #Wed Oct 23 15:47:27 CST 2013
  3. project.name=MOBILE_ANDROID_PROJECT
  4. jar.libs.dir=libs
  5. build.first=false
  6. key.alias=maomao
  7. key.alias.password=maomao
  8. channel.list=test1\:100411-f91d7ad6c99688b587b299d2c507679d,test2\:100411-f91d7ad6c99688b587b299d2c507679d
  9. java.dir=C\:\\Program Files (x86)\\Java\\jdk1.6.0_10
  10. key.store=C\:\\changeself\\test.keystore
  11. project.dir=C\:\\changeself\\project_android
  12. sdk.dir=C\:\\changeself\\adt-bundle-windows-x86-20130729\\sdk
  13. project.version=1.0.3
  14. key.store.password=maomao
  15. 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以上的版本)的更多相关文章

  1. Android Studio Gradle 多渠道自动打包,动态修改HostUrl,签名apk,混淆配置详解

    文/ skay csdn博客:http://blog.csdn.net/sk719887916/article/details/40541163 最近遇到项目从Eclispe迁移到Android st ...

  2. 深入浅出 - Android系统移植与平台开发(三)- 编译并运行Android4.0模拟器

    作者:唐老师,华清远见嵌入式学院讲师. 1.   编译Android模拟器 在Ubuntu下,我们可以在源码里编译出自己的模拟器及SDK等编译工具,当然这个和在windows里下载的看起来没有什么区别 ...

  3. Android项目实战(三十一):异步下载apk文件并安装(非静默安装)

    前言: 实现异步下载apk文件 并 安装.(进度条对话框显示下载进度的展现方式) 涉及技术点: 1.ProgressDialog   进度条对话框  用于显示下载进度 2.AsyncTask     ...

  4. Android Studio 之生成正式签名的 APK 文件

    生成 APK 文件 •步骤 点击  Build -> Generate Signed...... : 来到如下界面: 选择 APK 选项,点击 Next 来到如下界面: 如果你电脑上没有一个正式 ...

  5. 五 Android Studio打包Eegret App (包名和签名,打出正式包)

    一 定义包名 如下图,在AndroidManifest.xml中的package就是包名 二 创建keystore 选择Build->Generate Signed APK 选择create n ...

  6. 如何用Android studio生成正式签名的APK文件

    必须签名之后才可以发布到app商店中. 平时的调试的app都有默认的签名. 下面是生成带签名的APK的步骤: 1. Build 选择 Generate Signed APK 2. 弹出框,第一次选择C ...

  7. Android之APK文件签名——keytool和jarsigner

    一.生成密钥库将位置定位在jdk的bin文件中,输入以下命名行:keytool -genkey -alias ChangeBackgroundWidget.keystore -keyalg RSA - ...

  8. Android 自动编译、打包生成apk文件 2 - 使用原生Ant方式

    from://http://blog.csdn.net/androiddevelop/article/details/11100109 相关文章列表: <Android 自动编译.打包生成apk ...

  9. 【转】Android项目使用Ant打包,生成build.xml

    记不住,于是原帖转过来,请看原帖:http://blog.csdn.net/ms03001620/article/details/8490238 一.生成build.xml Eclipse中使用Ant ...

随机推荐

  1. [游戏模版18] Win32 五子棋

    >_<:Learning its AI logic. >_<:resource >_<:code: #include <windows.h> // C ...

  2. 博客搬家了,欢迎访问 http://blog.csdn.net/yinpengxiang/

    博客搬家了,欢迎访问 http://blog.csdn.net/yinpengxiang/

  3. my linux tech object

    I want to be a linux kernel development engineer. That's my dream.

  4. Mongodb副本集

    Replication:副本集 副本集可以将客户端的写操作分散到不同的服务器,可以用于灾难恢复,报告和备份. 副本集需要一个主服务器和一个备服务器,以及一个仲裁服务器.仲裁服务器决定将哪一个服务器作为 ...

  5. asp.net时间 日期(DateTime) 的格式处理

    日期格式化{0:yyyy-MM-dd HH:mm:ss.fff}与{0:yyyy-MM-dd hh:mm:ss.fff}的区别 使用24小时制格式化日期:{0:yyyy-MM-dd HH:mm:ss. ...

  6. 整站HTTPS后的跨域请求 CORS是否还有效?

    | 导语  手Q马上就要全量https了,很多业务都有跨域ajax请求的需求,原来使用的CORS头在HTTPS环境中还继续能用吗?我搜遍了谷歌.百度,都没看到有明确的答案,那么就自己来尝试一下吧. 关 ...

  7. 智能配置item

    iTerm配置说明 ==== **这是一个很智能的配置,不论你电脑里面有没有安装iTerm,不管你有没有.zshrc配置文件,git配置文件,git忽略文件,以及git的默认编辑器都已经更改为vim, ...

  8. Thinkphp下嵌套UEditor富文本WEB编辑器

    UEditor是由百度web前端研发部开发所见即所得富文本web编辑器,具有轻量,可定制,注重用户体验等特点,开源基于MIT协议,允许自由使用和修改代码... 本文实际操作于ThinkPHP框架下,现 ...

  9. 未能加载文件或程序集“System.Data.SQLite.DLL”或它的某一个依赖项

    今天在部署code到测试环境的时候 出现了未能加载文件或程序集"System.Data.SQLite.DLL"或它的某一个依赖项 这个错误,其实错误的的原因有很多,1.典型的是是版 ...

  10. 不会用ant打包、部署项目的工程师,不是一个好程序员(测试)

    副标题:利用ant脚本 自动构建svn增量/全量 系统程序升级包 首先请允许我这样说,作为开发或测试,你一定要具备这种本领.你可以手动打包.部署你的工程,但这不是最好的方法.最好的方式就是全自动化的方 ...