Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android ant 打包全過程 包含library,so,jar,混淆,簽名

android ant 打包全過程 包含library,so,jar,混淆,簽名

編輯:關於Android編程

1.先來一個基礎的配置文件(build.properties)

##最後生成目錄
#relase.abs.dir=C:\\Users\\Administrator\\Desktop
#
##工程絕對路徑
#storeapp.abs=F:\\ZhangLeRepository\\trunk\\Andorid\\StoreApp
#photoview.abs=F:\\ZhangLeRepository\\trunk\\Andorid\\PhotoView
#andbase.abs=F:\\ZhangLeRepository\\trunk\\Andorid\\AndBase
#xutils.abs=F:\\ZhangLeRepository\\trunk\\Andorid\\xutils
#
##SDK相關工具變量
#sdk.home=F:\\adt\\sdk
#sdk.platform=android-19
#jdk.home=F:\\java
#
#
##簽名配置
#keystore.path=???
#keystore.storepass=???
#keystore.keypass=???
#keystore.alias=???

3.上bulid.xml




    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
     
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  	
  	
    
        Cleaning the project...
        
            
            
        
        
            
            
        
    
	
    
        Generating R.java / Manifest.java from the resources...  
        
            
            
              
              
            
            
            
            
          
            
            
            
            
               
              
                   
                   
            
               
              
                   
            
            
               
              
                   

              
                         
            
            
            
        
    
     
    
        Compiling aidl files into Java classes...
        
            
            
            
            
                
                
            
        
    
    
	
	
		Generating BuildConfig.java...
		
            
			
			
			
			
			
			
		
	
	
	
		Generating BuildConfig.java...
		
            
			
			
			
			
			
			
		
	
	
		Generating BuildConfig.java...
		
            
			
			
			
			
			
			
		
	
	
		Generating BuildConfig.java...
		
            
			
			
			
			
			
			
		
	
    
    
    
        
            
				
				
				
				
			 
        
    
    
    
        proguard...
        
        
            
			
            
            
  		    
            
            
            
            
			
                   
             
            
            
            
            
			   
  		    
			
			
			
            
			
            
			
			
			
			
			
            ;} " />
		    
		    
		    
		    ;}" /> 
			
			
		    
		    
			;} " />
			
		    ;}" />
		   
		   
		   
		   
		   
		  	
		   
		   
		   
		   
		   
		   
		  
        
        
        
        
        
        
    
    
    
    
        Converting compiled files and external libraries into dex format file...
        
            
            
            
          
            
            
            
				 
            
            
				 
            
            
				 
            
        
    
     
    
        Packaging resources and assets...
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
           
            
            
            
            
            
            
        
    
    
    
    
        Packaging an unsigned APK file...
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        
    
    
    
	
		Packaging signed apk for release...
		
			
			
			
			
			
			
			
			
            
            
			
			
		
	
	

3.其中有個buildconfig的工具,這裡共享源碼,到處為可運行的jar即可

/**
 *  2014-6-11   上午11:07:22
 *  Created By niexiaoqiang
 */

package com.xiaoqiang.genbuildconfig;

import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;

/**
 * 生成BuildConfig文件
 * @author niexiaoqiang
 */
public class GenBuildConfig {
	public static final String ABDIR = "abdir";
	public static final String PACKAGE = "pakage";
	public static final String DEBUG = "debug";
	public static final String FILENAME = "BuildConfig.java";

	public static void main(String[] args) {
		int paramsLength = args.length;
		if (paramsLength % 2 == 0) {
			HashMap params = new HashMap();
			for (int i = 0; i < paramsLength; i = i + 2) {
				params.put(args[i], args[i + 1]);
			}
			String content = getBuildConfigContent(params);
			//創建文件夾
			File dir = new File(params.get(ABDIR).toString());
			if (!dir.exists()) {
				dir.mkdirs();
			}
			createFile(content, dir, params.get(PACKAGE).toString());
		}
	}

	/**
	 * 創建文件
	 * @param content
	 * @param dir
	 * @param packageStr
	 */
	public static void createFile(String content, File dir, String packageStr) {
		File javaFileDir = new File(dir, packageStr.replace(".", "\\"));
		if (!javaFileDir.exists()) {
			javaFileDir.mkdirs();
		}
		File javaFile = new File(javaFileDir, FILENAME);
		javaFile.setWritable(true);
		try {
			FileWriter writer = new FileWriter(javaFile, false);
			writer.write(content);
			writer.flush();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 生成文件內容
	 * @param params
	 * @return
	 */
	public static String getBuildConfigContent(HashMap params) {
		StringBuilder sb = new StringBuilder();
		sb.append("/**\r\n");
		sb.append(" * Create By com.xiaoqiang.genbuildconfig\r\n");
		sb.append(" */\r\n");
		sb.append("\r\n");
		sb.append("package " + params.get(PACKAGE) + ";\r\n");
		sb.append("\r\n");
		sb.append("public final class BuildConfig {\r\n");
		sb.append("  public final static boolean DEBUG = " + params.get(DEBUG) + ";\r\n");
		sb.append("}");
		return sb.toString();
	}

}





  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved