Android批量生成渠道(dào)包
發表時(shí)間:2020-11-13
發布人(rén):融晨科技
浏覽次數:45
1、在(zài)www.apache.org上(shàng)下載ant并在(zài)自己計算機上(shàng)配置Ant的(de)運行環境(我的(de)資源中共享了(le/liǎo)從Apache下載的(de)ant包,大(dà)家也(yě)可以(yǐ)自己去官網下載)
資源地(dì / de)址:http://download.csdn.net/detail/xiogjie_67/8336379
[img]http://img.blog.csdn.net/20150107111703128?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWlueXVueWluZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
[img]http://img.blog.csdn.net/20150107111732908?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWlueXVueWluZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
2、檢測是(shì)否安裝成功
開始——>運行——cmd——輸入ant回車,如果出(chū)現以(yǐ)下提示,則表示Ant環境設置已經配置好
[img]http://img.blog.csdn.net/20150107112156892?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWlueXVueWluZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
3、爲(wéi / wèi)了(le/liǎo)能讓ant能批量生成android的(de)apk文件,需要(yào / yāo)将ant-contrib-1.0b3.jar(我的(de)資源中有此文件可下載http://download.csdn.net/detail/xiogjie_67/8336247)文件放到(dào)ant的(de)lib目錄中去
[img]http://img.blog.csdn.net/20150107112938184?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWlueXVueWluZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
4、在(zài)Eclipse中指定Ant目錄(不(bù)要(yào / yāo)用Eclipse自帶的(de)Ant)Window——>prefercens
[img]http://img.blog.csdn.net/20150107113340874?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWlueXVueWluZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
5、創建Android測試批量打包工程
在(zài)工程下創建幾個(gè)文件:(也(yě)就(jiù)是(shì)項目的(de)根目錄下,與src、res是(shì)平級的(de)關系)
(1)build.xml
(2)local.properties
(3)ant.properties
說(shuō)明一下,這(zhè)三個(gè)文件的(de)關系,build.xml文件是(shì)最主要(yào / yāo)的(de)文件,local.properties與ant.properties文件是(shì)build.xml中引用的(de)文件,也(yě)就(jiù)是(shì)一些變量的(de)設置主要(yào / yāo)是(shì)在(zài)這(zhè)兩個(gè)文件當中設置。
源碼分别如下:
build.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- 項目名稱CreateApk,可用全局替換爲(wéi / wèi)當前項目名稱 --> <project name="CreateApk" default="deploy" > <!-- 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" /> <!-- 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 an env var" 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> <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 --> <taskdef resource="net/sf/antcontrib/antcontrib.properties" > <classpath> <pathelement location="D:/ant/lib/ant-contrib-1.0b3.jar" /> </classpath> </taskdef> <import file="${sdk.dir}/tools/ant/build.xml" /> <target name="deploy" > <foreach delimiter="," list="${market_channels}" param="channel" target="modify_manifest" > </foreach> </target> <target name="modify_manifest" > <!-- <replaceregexp file="AndroidManifest.xml" encoding="utf-8" match="android:value=http://www.sjsjw.com/100/000593MYM004194/"(.*)"" replace=""/> -->
local.propertieslocal.properties
sdk.dir=d:/android-sdk-windows
ant.properties
application.package=com.test.createapk ant.project.name=CreateApk java.encoding=utf-8 out.absolute.dir=e:/apk/compile gos.path=e:/apk/createapk key.store=D:/keystore/key.keystore key.store.password=hy123456 key.alias=china key.alias.password=hy123456 app_version=1.0.0 market_channels=1001,1002 publish.date=2015-1-7
釋意如下:
a、程序包名
b、項目名稱
c、項目編碼
d、臨時(shí)文件存放位置
e、apk文件存放位置
f、秘鑰所在(zài)位置
g、秘鑰密碼
h、秘鑰别名
i、别名密碼
j、版本
k、渠道(dào)名稱,要(yào / yāo)以(yǐ)逗号分隔,必須在(zài)一行内
l、發布日期
6、運行與生成
(1)檢查自己配置的(de)那些個(gè)目錄在(zài)本地(dì / de)磁盤中是(shì)否已經創建好了(le/liǎo)文件夾
(2)檢查build.xml文件中設置與引用的(de)文件(local.properties、ant.properties)是(shì)否準備好
(3)右擊build.xml文件——>run as ——> ant build
7、示例代碼源文件下載地(dì / de)址
http://download.csdn.net/detail/xiogjie_67/8336267