Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5520044
  • 博文数量: 763
  • 博客积分: 12108
  • 博客等级: 上将
  • 技术积分: 15717
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-28 21:21
个人简介

业精于勤,荒于嬉

文章分类

全部博文(763)

文章存档

2018年(6)

2017年(15)

2016年(2)

2015年(31)

2014年(14)

2013年(87)

2012年(75)

2011年(94)

2010年(190)

2009年(38)

2008年(183)

2007年(28)

分类: Android平台

2014-01-20 11:59:51

此脚本是针对于android在线更新的SDK,以前android有离线安装包,后来改为直接在线安装进行,两者的成本在于sdk的路径和一些工具类的路径不同。

 

 

 

此脚本用于进行自动编译用户需要的APK安装包,使用时候,请将签名用的*.keystore放在和build.xml同一目录,并命名为android.keystore,(如想更改,请在build.xml 中的jarsigner target进行更改)

 

build.properties

Java代码 复制代码
  1. android.tools=${sdk.folder}tools   
  2. android_version=2.1  
  3. apk.sdk.home=D/:/androidsdktools/android-sdk_r04-windows/android-sdk-windows/   
  4. apk.tools=${apk.sdk.home}tools/   
  5. application.package=com.test.testname   
  6. bin.dir=${jde.home}bin   
  7. app.name=NewAndroid   
  8. app.source.path=G/:/test/   
  9. jdk.home=C/:/Java_1.6_U18/jdk1.6.0_18/   
  10. output.dir=../outputDir   
  11. password=123456  
  12. sdk.folder=D/:/androidsdktools/android-sdk_r04-windows/android-sdk-windows/platforms/android-2.0.1/   
  13. temp.dir=127980239039628  
[java] view plaincopy
  1. android.tools=${sdk.folder}tools  
  2. android_version=2.1  
  3. apk.sdk.home=D/:/androidsdktools/android-sdk_r04-windows/android-sdk-windows/  
  4. apk.tools=${apk.sdk.home}tools/  
  5. application.package=com.test.testname  
  6. bin.dir=${jde.home}bin  
  7. app.name=NewAndroid  
  8. app.source.path=G/:/test/  
  9. jdk.home=C/:/Java_1.6_U18/jdk1.6.0_18/  
  10. output.dir=../outputDir  
  11. password=123456  
  12. sdk.folder=D/:/androidsdktools/android-sdk_r04-windows/android-sdk-windows/platforms/android-2.0.1/  
  13. temp.dir=127980239039628  

 

 

 

Build.xml

Xml代码 复制代码
  1. xml version="1.0" encoding="UTF-8"?>  
  2. <project name="Test" default="debug" basedir=".">  
  3.     <property file="build.properties">  
  4.     property>  
  5.   
  6.       
  7.       
  8.     <property name="outdir" value="bin" />  
  9.   
  10.       
  11.       
  12.   
  13.     <property name="android-framework" value="${sdk.folder}/framework.aidl" />  
  14.   
  15.       
  16.     <property name="resource-dir" value="res" />  
  17.     <property name="asset-dir" value="assets" />  
  18.     <property name="srcdir" value="src" />  
  19.     <condition property="srcdir-ospath" value="${basedir}/${srcdir}" else="${basedir}/${srcdir}">  
  20.         <os family="windows" />  
  21.     condition>  
  22.   
  23.     <property name="external-libs" value="libs" />  
  24.     <condition property="external-libs-ospath" value="${basedir}/${external-libs}" else="${basedir}/${external-libs}">  
  25.         <os family="windows" />  
  26.     condition>  
  27.   
  28.       
  29.     <property name="outdir-classes" value="${outdir}/classes" />  
  30.     <condition property="outdir-classes-ospath" value="${basedir}/${outdir-classes}" else="${basedir}/${outdir-classes}">  
  31.         <os family="windows" />  
  32.     condition>  
  33.   
  34.     <condition property="zipalign-package-ospath" value="${basedir}/${output.dir}/${app.name}_for_android_${android_version}_${temp.dir}.apk" else="${basedir}/${output.dir}">  
  35.         <os family="windows" />  
  36.     condition>  
  37.       
  38.     <property name="outdir-r" value="src" />  
  39.   
  40.       
  41.     <property name="dex-file" value="classes.dex" />  
  42.     <property name="intermediate-dex" value="${outdir}/${dex-file}" />  
  43.     <condition property="intermediate-dex-ospath" value="${basedir}/${intermediate-dex}" else="${basedir}/${intermediate-dex}">  
  44.         <os family="windows" />  
  45.     condition>  
  46.   
  47.       
  48.     <property name="resources-package" value="${outdir}/${ant.project.name}.ap_" />  
  49.     <condition property="resources-package-ospath" value="${basedir}/${resources-package}" else="${basedir}/${resources-package}">  
  50.         <os family="windows" />  
  51.     condition>  
  52.   
  53.     <property name="out-debug-package" value="${outdir}/${ant.project.name}-debug.apk" />  
  54.     <condition property="out-debug-package-ospath" value="${basedir}/${out-debug-package}" else="${basedir}/${out-debug-package}">  
  55.         <os family="windows" />  
  56.     condition>  
  57.   
  58.     <property name="out-unsigned-package" value="${outdir}/${ant.project.name}-unsigned.apk" />  
  59.     <property name="out-signed-package" value="${outdir}/${ant.project.name}-signed.apk" />  
  60.     <condition property="out-unsigned-package-ospath" value="${basedir}/${out-unsigned-package}" else="${basedir}/${out-unsigned-package}">  
  61.         <os family="windows" />  
  62.     condition>  
  63.     <condition property="out-signed-package-ospath" value="${basedir}/${out-signed-package}" else="${basedir}/${out-signed-package}">  
  64.         <os family="windows" />  
  65.     condition>  
  66.   
  67.       
  68.     <condition property="aapt" value="${android.tools}/aapt.exe" else="${android.tools}/aapt">  
  69.         <os family="windows" />  
  70.     condition>  
  71.     <condition property="zipalign" value="${apk.tools}/zipalign.exe" else="${apk.tools}/zipalign">  
  72.         <os family="windows" />  
  73.     condition>  
  74.     <condition property="jarsigner" value="${jdk.home}/bin/jarsigner.exe" else="${jdk.home}/bin/jarsigner">  
  75.         <os family="windows" />  
  76.     condition>  
  77.     <condition property="aidl" value="${android.tools}/aidl.exe" else="${android.tools}/aidl">  
  78.         <os family="windows" />  
  79.     condition>  
  80.     <condition property="adb" value="${apk.tools}/adb.exe" else="${apk.tools}/adb">  
  81.         <os family="windows" />  
  82.     condition>  
  83.     <condition property="dx" value="${android.tools}/dx.bat" else="${android.tools}/dx">  
  84.         <os family="windows" />  
  85.     condition>  
  86.     <condition property="apk-builder" value="${apk.tools}/apkbuilder.bat" else="${apk.tools}/apkbuilder">  
  87.         <os family="windows" />  
  88.     condition>  
  89.   
  90.     <property name="android-jar" value="${sdk.folder}/android.jar" />  
  91.   
  92.       
  93.   
  94.       
  95.     <target name="dirs" depends="init">  
  96.         <echo>Creating output directories if needed...echo>  
  97.         <mkdir dir="${outdir}" />  
  98.         <mkdir dir="${outdir-classes}" />  
  99.     target>  
  100.   
  101.       
  102.     <target name="resource-src" depends="dirs">  
  103.         <echo>Generating R.java / Manifest.java from the resources...echo>  
  104.         <exec executable="${aapt}" failonerror="true">  
  105.             <arg value="package" />  
  106.             <arg value="-m" />  
  107.             <arg value="-J" />  
  108.             <arg value="${outdir-r}" />  
  109.             <arg value="-M" />  
  110.             <arg value="AndroidManifest.xml" />  
  111.             <arg value="-S" />  
  112.             <arg value="${resource-dir}" />  
  113.             <arg value="-I" />  
  114.             <arg value="${android-jar}" />  
  115.         exec>  
  116.     target>  
  117.   
  118.       
  119.     <target name="aidl" depends="dirs">  
  120.         <echo>Compiling aidl files into Java classes...echo>  
  121.         <apply executable="${aidl}" failonerror="true">  
  122.             <arg value="-p${android-framework}" />  
  123.             <arg value="-I${srcdir}" />  
  124.             <fileset dir="${srcdir}">  
  125.                 <include name="**/*.aidl" />  
  126.             fileset>  
  127.         apply>  
  128.     target>  
  129.   
  130.       
  131.     <target name="compile" depends="dirs, resource-src, aidl">  
  132.         <javac encoding="ascii" target="1.5" debug="true" extdirs="" srcdir="." destdir="${outdir-classes}" bootclasspath="${android-jar}">  
  133.             <classpath>  
  134.                 <fileset dir="${external-libs}" includes="*.jar" />  
  135.             classpath>  
  136.         javac>  
  137.     target>  
  138.   
  139.       
  140.     <target name="dex" depends="compile">  
  141.         <echo>Converting compiled files and external libraries into ${outdir}/${dex-file}...echo>  
  142.         <apply executable="${dx}" failonerror="true" parallel="true">  
  143.             <arg value="--dex" />  
  144.     <script src="/javascripts/tinymce/themes/advanced/langs/zh.js" type="text/javascript">script><script src="/javascripts/tinymce/plugins/javaeye/langs/zh.js" type="text/javascript">script>      <arg value="--output=${intermediate-dex-ospath}" />  
  145.             <arg path="${outdir-classes-ospath}" />  
  146.             <fileset dir="${external-libs}" includes="*.jar" />  
  147.         apply>  
  148.     target>  
  149.   
  150.       
  151.     <target name="package-res-and-assets">  
  152.         <echo>Packaging resources and assets...echo>  
  153.         <exec executable="${aapt}" failonerror="true">  
  154.             <arg value="package" />  
  155.             <arg value="-f" />  
  156.             <arg value="-M" />  
  157.             <arg value="AndroidManifest.xml" />  
  158.             <arg value="-S" />  
  159.             <arg value="${resource-dir}" />  
  160.             <arg value="-A" />  
  161.             <arg value="${asset-dir}" />  
  162.             <arg value="-I" />  
  163.             <arg value="${android-jar}" />  
  164.             <arg value="-F" />  
  165.             <arg value="${resources-package}" />  
  166.         exec>  
  167.     target>  
  168.   
  169.       
  170.     <target name="package-res-no-assets">  
  171.         <echo>Packaging resources...echo>  
  172.         <exec executable="${aapt}" failonerror="true">  
  173.             <arg value="package" />  
  174.             <arg value="-f" />  
  175.             <arg value="-M" />  
  176.             <arg value="AndroidManifest.xml" />  
  177.             <arg value="-S" />  
  178.             <arg value="${resource-dir}" />  
  179.               
  180.             <arg value="-I" />  
  181.             <arg value="${android-jar}" />  
  182.             <arg value="-F" />  
  183.             <arg value="${resources-package}" />  
  184.         exec>  
  185.     target>  
  186.   
  187.       
  188.     <target name="install" depends="debug">  
  189.         <echo>Installing ${out-debug-package} onto default emulator...echo>  
  190.         <exec executable="${adb}" failonerror="true">  
  191.             <arg value="install" />  
  192.             <arg value="${out-debug-package}" />  
  193.         exec>  
  194.     target>  
  195.   
  196.     <target name="reinstall" depends="debug">  
  197.         <echo>Installing ${out-debug-package} onto default emulator...echo>  
  198.         <exec executable="${adb}" failonerror="true">  
  199.             <arg value="install" />  
  200.             <arg value="-r" />  
  201.             <arg value="${out-debug-package}" />  
  202.         exec>  
  203.     target>  
  204.   
  205.       
  206.     <target name="uninstall">  
  207.         <echo>Uninstalling ${application.package} from the default emulator...echo>  
  208.         <exec executable="${adb}" failonerror="true">  
  209.             <arg value="uninstall" />  
  210.             <arg value="${application.package}" />  
  211.         exec>  
  212.     target>  
  213.   
  214.       
  215.     <target name="init" depends="Copy_Ressource">  
  216.         <echo message="Init output directory.....">  
  217.         echo>  
  218.         <mkdir dir="${output.dir}" />  
  219.     target>  
  220.       
  221.     <target name="Copy_Ressource">  
  222.         <echo message="Copy app resource. ">  
  223.         echo>  
  224.         <copy todir="${asset-dir}" overwrite="true" failonerror="false">  
  225.             <fileset dir="${app.source.path}">  
  226.                 <include name="*.*" />  
  227.             fileset>  
  228.         copy>  
  229.        
  230.     target>  
  231.       
  232.     <target name="jarsigner" depends="release">  
  233.         <exec executable="${jarsigner}" failonerror="true">  
  234.             <arg value="-verbose" />  
  235.             <arg value="-storepass" />  
  236.             <arg value="${password}" />  
  237.             <arg value="-keystore" />  
  238.             <arg value="android.keystore" />  
  239.             <arg value="-signedjar" />  
  240.             <arg value="${out-signed-package-ospath}" />  
  241.             <arg value="${out-unsigned-package-ospath}" />  
  242.             <arg value="android.keystore" />  
  243.         exec>  
  244.     target>  
  245.       
  246.     <target name="zipalign" depends="jarsigner">  
  247.         <exec executable="${zipalign}" failonerror="true">  
  248.             <arg value="-v" />  
  249.             <arg value="-f" />  
  250.             <arg value="4" />  
  251.             <arg value="${out-signed-package-ospath}" />  
  252.             <arg value="${zipalign-package-ospath}" />  
  253.         exec>  
  254.     target>  
  255.       
  256.     <target name="adb" depends="zipalign">  
  257.             <exec executable="${adb}" failonerror="true">  
  258.                 <arg value="install" />  
  259.                 <arg value="-r" />  
  260.                 <arg value="${zipalign-package-ospath}" />  
  261.             exec>  
  262.         target>  
  263. project>  
  264. 如果keystore不在此目录, 
    你就修改 : 

         
              
                  
                  
                  
                  
                  
                  
                  
                  
                  
           
      
       
      

    中的 
      
        
    路径, 

    这个两个参数值要一样即可
阅读(5307) | 评论(2) | 转发(1) |
给主人留下些什么吧!~~

llz3834555262015-04-30 14:51:06

lixiaoyu0123:开源的android批量自动打包工具
http://git.oschina.net/bingjian/AutopackingAndroid/attach_files

建立规则的时候,选择AndroidManifest.xml文件,选择替换 <meta-data
            android:name="UMENG_CHANNEL"
            android:value="HW" />
为:
<meta-data
            android:name="UMENG_CHANNEL"
            android:value="91" />

,点开始一会儿就报错:说无法找到字符串

回复 | 举报

lixiaoyu01232014-11-18 21:48:19

开源的android批量自动打包工具
http://git.oschina.net/bingjian/AutopackingAndroid/attach_files