zoukankan      html  css  js  c++  java
  • 建立apk定时自动打包系统第二篇——自动上传文件

    《建立apk定时自动打包系统第一篇——Ant多渠道打包并指定打包目录和打包日期》这篇文章中介绍多渠道打包的流程。很多时候我们需要将打包好的apk上传到ftp中,这时候我可以修改custom_rules.xml这个文件就可以实现这个需求了。

    1、下载 common-net-3.3.jar 并将其放在ant安装目录下的lib文件夹中。

    2、修改ant.properties文件

    key.store=./test.keystore
    key.alias=test.keystore
    key.store.password=test12345
    key.alias.password=test12345
    
    #generate test.keystore
    #keytool -genkey -alias test.keystore -keyalg RSA -validity 20000 -keystore test.keystore
    apk.dir=./apk
    app.name=AntDemo
    #channel numbers
    market_channels=myapp-12345,BAI-3s322d

    #upload apk

    #ftp的主机地址,我在本机配置了一个ftp服务器,用于测试

    ftp.hostname=127.0.0.1

    #ftp登录帐号

    ftp.userid=admin

    #登录密码

    ftp.password=6lg4LgCT

    #将apk文件存放ftp服务器中的根目录下,可以自行选择其他目录

    ftp.remotedir=/

    upload apk 后面就是新添加的配置属性,这些属性会在custom_rules.xml文件中引用,当然这个ftp.userid必须有读写权限,否则将无法上传。

    3、修改custom_rules.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="custom_rules" >
    
        <taskdef resource="net/sf/antcontrib/antcontrib.properties" >
    
            <classpath>
    
                <pathelement location="${ant.ANT_HOME}/lib/ant-contrib-1.0b3.jar" />
            </classpath>
        </taskdef>
    
        <tstamp>
    
            <format
                pattern="yyyyMMddhhmm"
                property="pktime"
                unit="hour" />
        </tstamp>
    
        <mkdir dir="${apk.dir}" >
        </mkdir>
    
        <target name="deploy" >
    
            <foreach
                delimiter=","
                list="${market_channels}"
                param="channel"
                target="modify_manifest" >
            </foreach>
        </target>
    
        <target name="modify_manifest" >
    
            <replaceregexp
                byline="false"
                flags="g" >
    
                <regexp pattern="android:value="(.*)" android:name="app_key"" />
    
                <substitution expression="android:value="${channel}" android:name="app_key"" />
    
                <fileset
                    dir=""
                    includes="AndroidManifest.xml" />
            </replaceregexp>
    
            <property
                name="out.final.file"
                location="${apk.dir}/${app.name}_${channel}_${pktime}.apk" />
    
            <antcall target="clean" />
    
            <antcall target="release" />
            <antcall target="upload" />
    
        </target>

     

    <target

            name="upload"

            description="Upload apk to server..." >

     

            <ftp

                action="put"

                binary="yes"

                passive="true"

                password="${ftp.password}"

                remotedir="${ftp.remotedir}"

                separator=""

                server="${ftp.hostname}"

                userid="${ftp.userid}"

                verbose="yes" >

                <!--指定apk所在目录-->

                <fileset dir="${apk.dir}" >

     

                    <include name="${app.name}_${channel}_${pktime}.apk" />

                </fileset>

            </ftp>

     

        </target>

     

    </project>

    在 <antcall target="release" /> 后面添加<antcall target="upload" />这个就是在打包好了之后就执行上传任务。

    修改之后就可以执行ant-deploy命令就可以自动打包并上传到ftp了。

    4、Demo代码

    antdemo.rar

    115网盘礼包码:5lbdiif2eh98

    http://115.com/lb/5lbdiif2eh98

    这个代码包含了多渠道打包以及自动上传ftp的配置,这个代码的ftp是本机测试的,跑的时候需要配置一个ftp地址和有读写权限的用户名和密码

     

  • 相关阅读:
    CentOS最常用命令
    cssreset
    mysql cmd连接 乱码
    帮朋友转发招聘信息 南京知名互联网公司招聘java、测试、前端,具体私聊
    InputStream写文件出现大量NUL
    iOS app开发资料整理
    完美的视图旋转算法
    Windows上使用clang编译
    nodejs
    Rpath handling on Linux
  • 原文地址:https://www.cnblogs.com/angrycode/p/4059690.html
Copyright © 2011-2022 走看看