首页 > 代码库 > android ant 打包全过程 包含library,so,jar,混淆,签名
android ant 打包全过程 包含library,so,jar,混淆,签名
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
<?xml version="1.0" encoding="utf-8"?> <!-- Build an Android project. --> <project name="StoreApp" basedir="." default="release" > <!-- 通用属性 --> <property file="build.properties" /> <!-- 主工程绝对路径 --> <property name="storeapp.abs.src" value=http://www.mamicode.com/"${storeapp.abs}/src" />>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<String, Object> params = new HashMap<String, Object>(); 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<String, Object> 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(); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。