android 下用ant编译脚本执行批量渠道打包


 在工程目录下新建一个文件夹 build,以下是文件夹中的文件 build.xml中的所有内容。


 

  

         

    

    
    

	  
          
     
    
      
          
     
     
    
    
     
	 
    
      
      
      
      
      
      
      
          
      
      
          
      
  


  
    
             




                     
                     
             
         
          
                          
                     
             
         
      

      
          
        
        
        
          
      

      
      
        Creating output directories if needed...  
          
          
      
  
      
      
        Generating R.java / Manifest.java from the resources...  
        resources...resource-dir: ${resource-dir}  
        resources...android-jar: ${android-jar}
        resources...outdir-r: ${outdir-r}
        resources...aapt:${aapt}
          
              
             
              
              
              
              
              
              
              
             
          
      
  
      
      
        Compiling aidl files into Java classes...  
          
              
              
              
                  
              
          
      
  
      
      
         	libs_classpath..${basedir}/libs/ 
        
         	






         	  
         
        libs_classpath..${libs_classpath} 
      
  
      
      
        Converting compiled files and external libraries into ${outdir}/${dex-file}...
          --output=${intermediate-dex-ospath}
          --outdir-classes-ospath=${outdir-classes-ospath}
          --outdir-external-libs=${external-libs}
          
          
            
            
			
			
            
               
        
      
  
      
      
        Packaging resources and assets...  
          
              
              
              
              
              
              
              
              
              
              
              
              
          
      
  
      
      
        Packaging resources...  
          
              
              
              
              
              
              
              
              
              
              
              
          
      
  
      
      
      
          
          
          
      
  
      
      
        Packaging ${out-unsigned-package}, and signing it with a release ...  
        ... ${external-libs-ospath}, .so 文件的路径  
          
             
             
              
              
              
              
              
              
	    	  
            
            
			
          
      
    
      
        Packaging ${out-unsigned-package}, and signing it with a release ...  
        out-unsigned-package-ospath: ${out-unsigned-package-ospath}
        resources-package-ospath: ${resources-package-ospath}
        intermediate-dex-ospath: ${intermediate-dex-ospath}
        srcdir-ospath: ${srcdir-ospath}
        external-libs-ospath: ${external-libs-ospath}
          
             
             
              
              
              
              
              
              
	    	  
              
          
     
  
     
          
        cmcc_jiaotong.key== ${basedir}/${cmcc_jiaotong.key}
         

			
			
			
			

              
              
              
              
            
    		 
              
              
            
               
            
            
          
     

      
         key== ${keystore}
          key.password == ${keystore.password}
           output path == ${out-signed-package-ospath}
            keystore.alias == ${keystore.alias}
          

			
			
			
			

              
              
              
              
              
              
            
            
            
              
          
          
              
              
              
              
              
          
        
    
      
      
          
              
              
              
              
              
          
      
    
      
      
              
                  
                  
                  
              
      
    
   
       ant 的位置:${ant.home}/lib/ant-contrib-1.0b3.jar
		
			
			打印渠道文件存放地址:${file-content}
			
	
	

     
        
      " /> 
	  " /> 
        
        
      
		 
		
		
    
   

  


配置文件中的一些配置信息:build.properties 文件

#===============App set========================
app.name=jiaotongbobao
app.version=2.0.1
#keystore=build/cmcc_jiaotong.key
#keystore.password=cmcc_jiaotong
#keystore.alias=\u4EA4\u901A\u64AD\u62A5
keystore=build/itotem.keystore
keystore.password=itotem
keystore.alias=itotemApp
third_lib=../ItotemBase/
app.output.dir=outputDir
#=============Android set======================
android.api.version=16
android.home=${env.ANDROID_HOME}
#android.home=/Users/Shared/Jenkins/android-dev/android-sdk-macosx
android.tools=${android.home}/tools
android.sdk.folder=${android.home}/platforms/android-${android.api.version}
android.sdk.tools=${android.home}/platform-tools
#===============Java set======================
jdk.home=${env.JAVA_HOME}
#jdk.home=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/
jdk.bin.dir=${jdk.home}/bin
ant.home=${env.ANT_HOME}
#=================google map set=================
google.map.path=${android.home}/add-ons/addon_google_apis_google_inc_${android.api.version}/libs/
#=================================================
  
     
basedir=../
id=${app.name}
outdir=bin
     
android-framework="${android.sdk.folder}/framework.aidl
resource-dir=./res
asset-dir=./assets
srcdir=./src
srcdir-ospath=${basedir}/${srcdir}
external-libs=${basedir}/libs
external-libs-ospath=${basedir}/libs

    
outdir-classes=${outdir}/classes
outdir-classes-ospath=${basedir}/${outdir-classes}

outdir-r=./gen

  
dex-file=classes.dex
intermediate-dex=${outdir}\${dex-file}
intermediate-dex-ospath=${basedir}\${intermediate-dex}
	
      
resources-package=${outdir}/${app.name}.ap_
resources-package-ospath=${basedir}/${resources-package}
out-debug-package=${outdir}/${app.name}-debug.apk
out-debug-package-ospath=${basedir}/${out-debug-package}

#out-app-name=${app.name}_android_${app.version}_${TODAY_CN}_${id}.apk"/>
out-unsigned-package=${outdir}/${app.name}-Unsigned.apk
#out-signed-package=${outdir}/${app.name}_android_${app.version}_${TODAY_CN}_${id}.apk
out-unsigned-package-ospath=${basedir}/${out-unsigned-package}
#out-signed-package-ospath=${basedir}/${out-signed-package}

android-jar=${android.sdk.folder}/android.jar
maps-jar=${external-libs}/maps.jar
    


渠道号的配置文件:ids.cfg

CHANNEL012
CHANNEL013

还需要注意在manifest.xml中的渠道配置信息为:

		     
		     

在代码中检测是否正确打出的渠道包信息:

	/**
	 * 获得渠道号
	 * @param ctx
	 * @return
	 */
	public static String getChanel(Context ctx) {
		String CHANNELID = "000000";
		try {
			ApplicationInfo ai = ctx.getPackageManager().getApplicationInfo(
					ctx.getPackageName(), PackageManager.GET_META_DATA);
			CHANNELID = ai.metaData.getString("SZICITY_CHANNEL");
		} catch (Exception e) {
			//
		}
		Log.e(TAG,"CHANNELID:"+CHANNELID);
//		Toast.makeText(ctx, "CHANNELID:"+CHANNELID, Toast.LENGTH_SHORT).show();
		return CHANNELID;
	}  



然后还需要一个生成安装包的签名文件,最好签名的信息都为英文,和路径信息也都为英文,

因为经测试目前在mac系统环境下中文会编译不通过失败掉。








你可能感兴趣的:(android 下用ant编译脚本执行批量渠道打包)