1. 程式人生 > >android Ant 批量多渠道打包!

android Ant 批量多渠道打包!

一直以來都是手動打包android程式,真可謂苦不堪言啊,以前試過用ant打包,但是失敗了,最近剛到新公司,又開始研究ant這玩意了,查閱了網上一些文章,結合自己的情況,硬是要弄出來才行,這裡就作下記錄吧。

1,準備

ant打包自然需要ant,可以去http://ant.apache.org/下載解壓,也可以使用eclipse自帶的(如果有的話)。

驗證ant是否安裝好,在控制檯輸入Cmd 回車, ant 回車,如果出現:

   Buildfile: build.xml does not exist!
   Build failed

恭喜你已經ant配置成功!!

2,配置環境變數和新增擴充套件元件

在環境變數中需要新增ANT_HOME,JAVA_HOME,ANDROID_SDK_HOME等著幾個變數(原因是有些寫法使用了此變數,儘可能多的寫出來避免錯誤),並且還要path變數將%ANT_HOME%\bin;%ANT_HOME%\lib;%JAVA_HOME%/lib;%JAVA_HOME%/bin等。

下載 ant-contrib-1.0b3.jar放在ant 的 lib資料夾下,(如果使用的是eclipse自帶的,請配置ant變數並新增到指定位置如圖,確保呼叫的ant包含有擴充套件元件)。

preferences配置

3,編寫build.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- 專案名稱yinyuedongting,可用全域性替換為當前專案名稱 -->
<project
    name="yinyuedongting"
    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:/androidDev/batch-package-tool/ant1.8.3/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="(.*)"" replace=""/> -->

        <replaceregexp
            byline="false"
            flags="g" >

            <regexp pattern="android:name="UMENG_CHANNEL" android:value="(.*)"" />

            <substitution expression="android:name="UMENG_CHANNEL" android:value="${channel}"" />

            <fileset
                dir=""
                includes="AndroidManifest.xml" />
        </replaceregexp>
        <!-- <property  name="out.release.file" value="${out.absolute.dir}/${channel}.apk"/> -->

        <antcall target="release" />

        <copy tofile="${gos.path}/yinyuedongting_${channel}.apk" >

            <fileset
                dir="${out.absolute.dir}/"
                includes="yinyuedongting-release.apk" />
        </copy>

        <delete includeEmptyDirs="true" >

            <fileset
                dir="${out.absolute.dir}"
                includes="**/*" />
        </delete>

        <echo message="===========================" />
    </target>

</project>

以上的可以全部拷貝,然後通過全域性替換掉專案名稱,例子中專案名稱為yinyuedongting

4,配置local.properties

此處只有一個選項就是android sdk路徑,

sdk.dir=D:\\adt-bundle-windows\\sdk,改為你自己的sdk路徑,注意用雙斜槓轉義

5.配置ant.properties

application.package=com.yuanhang.yinyuedongting   程式包名
ant.project.name=yinyuedongting 專案名稱
java.encoding=utf-8 專案編碼

out.absolute.dir=d:/apk/compile  臨時檔案存放位置
gos.path=d:/apk/yinyuedongting   apk檔案存放位置

key.store=D:/\u5F00\u53D1\u8D44\u6599\/rainie.keystore  祕鑰所在位置
key.store.password=rainie  祕鑰密碼
key.alias=rainie   祕鑰別名
key.alias.password=rainie  別名密碼

app_version=1.0.0  版本
market_channels=default  渠道名稱,要以逗號分隔,必須在一行內
注意使用的是友盟渠道,如果要修改則自行在build.xml中修改

以上這些都配置好後,即可巡行ant 打包應用,也可以通過eclipse外掛快速執行編譯指令,以上過程已執行成功,並且換了不同專案也同樣沒問題。

最後一個問題就是,這個ant的build.xml檔案尚未對引用到library專案作出編譯,所以有引用到library專案的不能執行成功,解決辦法是將library專案所有資原始檔copy到現有專案
中,方能編譯成功。

相關推薦

android Ant 批量多渠道打包

一直以來都是手動打包android程式,真可謂苦不堪言啊,以前試過用ant打包,但是失敗了,最近剛到新公司,又開始研究ant這玩意了,查閱了網上一些文章,結合自己的情況,硬是要弄出來才行,這裡就作下記錄吧。 1,準備 ant打包自然需要ant,可以去http://an

android Ant 批量多渠道打包 總結

最近研究android裡用ant打多個渠道的apk包,終於搞出頭緒!!走了很多錯路,希望大家不要這樣子!!下面就是個人的幾點總結,希望對大家有幫助:      首先說的是我用的ant不是eclipse和android SDk裡面自帶的ant,而是從這裡下載的 -- Ant

Ant_android Ant 批量多渠道打包(2)

最近研究android裡用ant打多個渠道的apk包,終於搞出頭緒!!走了很多錯路,希望大家不要這樣子!!下面就是個人的幾點總結,希望對大家有幫助:      首先說的是我用的ant不是eclipse和android SDk裡面自帶的ant,而是從這裡下載的

借騰訊開源 VasDolly,談談 Android 簽名和多渠道打包的原理

一、前言 Hi,大家好,我是承香墨影! 當我們需要釋出一款 App 到應用市場的時候,一般需要我們針對不同的市場生產不同的渠道包,它們使用的是同一套程式碼,只是會包含一些各自的渠道資訊,用於我們做資料分析。 前幾天,企鵝電競團隊開源了自己的 And

Android美團多渠道打包Walle整合

一、為什麼使用美團多渠道打包的方式? 打包更加快速 傳統的通過productFlavors渠道包的方式,渠道10個以內還可以接受,如果100個渠道包,每個包需要打5Min,就是將近10個小時的打包,而採用美團Walle多渠道打包的方式只需要打一個包的時間。 配置更加靈活 可以在APK渠道包中通過配

Android 友盟多渠道打包

目錄 一、簡介 一、簡介 為了統計不同渠道上的下載數量及使用者活動情況,方便後臺做運營統計。我們需要在安裝包中新增不同的標識(渠道資訊 Channel)。多渠道的實現方式多種多樣,此篇只實現友盟多渠道打包的方法。友盟多渠道打包方法試用於少量的渠道,如果要

Android美團多渠道打包方式

以umeng為例,官方的渠道配置方式: <!-- 友盟API Key --> <meta-data android:name="UMENG_APPKEY" android:va

【騰訊Bugly乾貨分享】Android 新一代多渠道打包神器

關於作者: 李濤,騰訊Android工程師,14年加入騰訊SNG增值產品部,期間主要負責手Q動漫、企鵝電競等專案的功能開發和技術優化。業務時間喜歡折騰新技術,寫一些技術文章,個人技術部落格:www.ltlovezh.com 。 ApkChanne

Android中的多渠道打包之友盟統計篇(二)

上篇簡單瞭解了Android中的多渠道打包,這篇主要說正事了---》 如何多渠道打包: 首先,多渠道打包最重要的是可以統計不同渠道下的應用的情況,比如下載量,日活量等等.. 關於統計的話國內有兩個比較出名的第三方統計工具吧:友盟統計和百度移動統計 這篇說的是用友盟,如果想要

android gradle配置多渠道打包

1.gradle檔案中定製productFlavors: //為同一個應用建立不同的版本,比如一個國內版本,一個國外版   productFlavors {     home {       manifestPlaceholder

Android利用Gradle多渠道打包如何動態替換資源,文字

動態替換APP logo 首先我們在app的build.gradle下面加入如下程式碼,以oem1為示例, productFlavors { oem1 { manifestPlaceholders = [

Android 新一代多渠道打包神器

ApkChannelPackage是一種快速多渠道打包工具,同時支援基於V1和V2簽名進行渠道打包。外掛本身會自動檢測Apk使用的簽名方法,並選擇合適的多渠道打包方式,對使用者來說完全透明。 概述 眾所周知,因為國內Android應用分發市場的現狀,我們在釋出APP

Android開發AndroidStudio多渠道打包

 最近不斷有朋友向我諮詢AndroidStudio多渠道的打包方法,今天整理一下之前積累的打包套路,寫一篇文章,手把手的教給大家。         說到多渠道,這裡不得不提一下友盟統計,友盟統計是大家日常開發中常用的渠道統計工具,而我們的打包方法就是基於友盟統計實施的。按

Android Studio--Gradle多渠道打包

由於國內Android市場眾多渠道,為了統計每個渠道的下載及其它資料統計,就需要我們針對每個渠道單獨打包,如果讓你打幾十個市場的包豈不煩死了,不過有了Gradle,這再也不是事了。友盟多渠道打包廢話不多說,以友盟統計為例,在AndroidManifest.xml裡面會有這麼一

Android使用指令碼多渠道打包

本文對 https://github.com/pengjianbo/MutiChannelPackup Python指令碼,對指令碼作了擴充套件: - 支援命令列引數,支援多flavor渠道打包 - 路徑優化,支援配置多個flavor,多個flavor

Android幾種多渠道打包

1、什麼是多渠道打包在不同的應用市場可能有不同的統計需求,需要為每個應用市場釋出一個安裝包,這裡就引出了Android的多渠道打包。在安裝包中新增不同的標識,以此區分各個渠道,方便統計app在市場的各種。 2、幾種打包方式 友盟 UMeng Android Studio自帶 美團 Walle 3、開始使

gradle打包android (實現外部導入簽名文件、多渠道打包、導入ant腳本)

gradle打包 tree clu download csdn ssp pes 基礎 net 近期一直在做android自己主動打包,之前已經完畢了用純命令行的形式打包、原生態ant腳本打包。和基於android的SDK的打包。而且實現了多渠道打包,後來同

拒絕多渠道打包,一招解放Android工程師

完全省去安卓工程師製作渠道包時間(每次升級只須向渠道管理人員提供一個母包即可),同時也節省渠道管理人員時間,並且提供了豐富、實時報表和實時排重、自定義事件統計等功能的創新渠道包製作工具,而且是免費的。 App推廣,離不開渠道,識別使用者來自哪個渠道,發現渠道質量的高低,是決定App推廣決策的關鍵資料參考,這

Android中利用Shareinstall進行多渠道一鍵自動打包

目前國內的安卓渠道有幾百家,我們要根據不同的渠道打不同渠道的apk來統計每個渠道帶來的使用者數,統計每個渠道使用者的存活率和活躍度等等資訊,但是手動對每個渠道的APK進行簽名打包實在是讓人感到厭煩且低效,這時我們需要一個全自動化的打包工具----Shareins

Android ANT 多渠道打包解決方案

<span style="font-size:18px;"><!--Android 分渠道打包步驟--> <!--打包之前請確定--> ANDROID_HOME 環境變數 即ANDROID_SDK的安裝路徑 如: