• android批量打包处理


    一、环境安装

          a.      安装JDK最好JDK1.5或更高版本

          b.      安装ANT, 最好使用版本高一点的, Antcontrib的任务需要的Ant1.5或更高版本才能正常工作。

          c.      设置javaant环境变量,ant build.xml会读取系统设置的环境变量.

          d.      下载 ant-contrib.jar 支持build.xml文件中循环处理,下载路径:http://ant-contrib.sourceforge.net/,

                   将下好的包放到ant的lib目录下

    二、android项目环境设置

          

          a.      在命令行下,打开到\android-sdk-windows\tools下执行   androidupdate project --name 项目名称  -t 3 -p 项目路径     

                   执行命令后生成build.xmllocal.properties文件.

          b.      项目路径下创建ant.properties文件 ,内容编辑:

                   key.store=keystore存放路径

                   key.store.password=*******

                   key.alias=别名

                   key.alias.password=*******

          c.  编辑local.properties

                   sdk.dir=E:\\android-sdk-windows   //sdk路径

                   apk.path=F://apk                  //生成的apk存放路径

                   version=3.0                       //项目版本

                   marketchannels.file.path=F:/marketchannels.txt    //渠道文件路径

                   temp.str.path = F:/newstrings.xml                 //temp文件路径

                  marketchannels.txt 存放的是 渠道信息表 如:360手机@www.360.cn#安智网@http://www.anzhi.com/

                  newstrings.xml 里存放的是 <string name="channelname">%channelname%</string>

                   <string name="downloadurl">%downloadurl%</string>

                  将newstrings.xml复制一份到android项目的values,用于读取渠道属性

    d.      编辑bulid.xml ,内容编辑:

        <?xml version="1.0" encoding="UTF-8"?>

          <project

                name="项目名称" default="help" >

            <loadproperties srcFile="local.properties" />

            <!-- 使用第三方的ant包,使ant支持for循环-->

            <taskdef resource="net/sf/antcontrib/antcontrib.properties">  

             <classpath>  

              <pathelement location="${ANT_HOME}/lib/ant-contrib-1.0b3.jar" />

              </classpath>  

             </taskdef>

          <property name="out.dir" value="bin" />

          <property name="out.absolute.dir" location="${out.dir}" />

                <!--定义初始变量-->

        <property name="channelname" value="" />  

        <property name="channelkey" value="" />  

        <!-- 读取存放渠道信息的text -->

        <target name="getdata" >

            <loadfile property="market_channels" srcFile="${marketchannels.file.path}"encoding="GBK"/>

            <echo message="${market_channels}"/>

          </target>

         <!--循环打包 -->

         <target name="deploy" depends="getdata">  

             <foreach target="modify_manifest" list="${market_channels}" param="nameandchannel" delimiter=" #"/>  

         </target>  

         <target name="modify_manifest">  

                     <!-- 获取渠道号码 -->

              <propertyregex override="true" property="channelkey" input="${nameandchannel}" regexp="@(.*)" select="\1"/>

                     <!-- 获取渠道名字 -->

                    <propertyregex override="true" property="channelname" input="${nameandchannel}" regexp="(.*)@" select="\1"/>

                    <echo>  ${channelname} ---------- ${channelkey} </echo>

                    <delete file="./res/values/newstrings.xml"/>

                    <copy file="${temp.str.path}" todir="./res/values/" />  

                   <!-- 正则匹配替换渠道路径 -->

                   <replaceregexp flags="g" byline="true" encoding="UTF-8">  

                         <regexp pattern="%downloadurl%" />

                         <substitution expression="${channelkey}"/>   

                         <fileset dir="./res/values/" includes="newstrings.xml" />  

                   </replaceregexp>   

                   <!-- 正则匹配替换渠道名称 -->

                   <replaceregexp flags="g" byline="true" encoding="UTF-8">  

                          <regexp pattern="%channel%" />

                          <substitution expression="${channelname}"/>   

                          <fileset dir="./res/values/" includes="newstrings.xml" />  

                     </replaceregexp>  

                    <!-- 编译打包 -->

                    <antcall target="release" />

                   <!--将编译签名后的包,复制指定目录并按渠道名重命名  --> 

                   <copy file="${out.absolute.dir}/${ant.project.name}-release.apk" tofile="${apk.path}/${channelname}-${version}.apk" />     

              </target> 

               <property file="ant.properties" />

            <loadproperties srcFile="project.properties" />

           <fail  message="sdk.dir is missing. Make sure to generate local.properties using @apos;android update project&apos;" unless="sdk.dir"     />

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

        </project>

    E.      项目路径下创建antexec.bat文件 编辑

        call ant deploy

    D.      双击antexec.bat,执行打包,在apk存放目录可以生成不同渠道的apk.

     

  • 相关阅读:
    node.js是什么
    python基础 filter ,列表,字典,集合 中根据 条件 筛选 数据
    nginx 自动补全www,当不输入www时候自动补全www
    python爬虫,接口是post请求,参数是request payload 的形式,如何传参
    python使用with开启线程锁
    linux nohup后台执行脚本并指定文件输出 ,nohup 修改默认日志输出文件
    python线程锁
    nginx yum安装启动
    redis desktop manager 远程连接服务器上的redis
    职位列表中英对照
  • 原文地址:https://www.cnblogs.com/John5/p/2862454.html
Copyright © 2020-2023  润新知