android ant 最简单的打包签名,混淆方法
使用ant打包,如果脚本都是我们自己一步一步来写的话,是一个比较麻烦的东西。
关于ant,我们详细看下:
ant支持 ant debug,ant release等命令,我们需要签名混淆,那么就需要ant release这个命令。
首先:ant环境搭建,这我就不多说了,很多博客都有介绍,包括一些环境配置
然后:ant环境可以之后,我们需要一个 build.xml文件,这个是ant编译去找的一个东西
<?xml version="1.0" encoding="UTF-8"?> <project name="EPAPP" default="helpme" > <property file="local.properties" /> <property file="ant.properties" /> <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" /> <import file="custom_rules.xml" optional="true" /> <!-- import file="build_of_sdk.xml" / --> <import file="${sdk.dir}/tools/ant/build.xml" /> <target name="cleand" depends="clean" > <delete file="./assets/config.properties"/> </target> <target name="d" depends="cleand" > <property name="out.final.file" value="./dist/develop/ep.apk" /> <mkdir dir="./dist/develop"/> <antcall target="release" /> </target> <target name="helpme"> <echo>Android Ant Build For EPAPP. Available targets:</echo> <echo> helpme: Displays this help.</echo> <echo> d: Builds for final.</echo> <echo> Final release for production.</echo> <echo>Please feel free to ask help from wangle@easipass.com</echo> <echo>Sorry for this messed English show. :) </echo> </target> </project> <?xml version="1.0" encoding="UTF-8"?> <project name="EPAPP" default="helpme" > <property file="local.properties" /> <property file="ant.properties" /> <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" /> <import file="custom_rules.xml" optional="true" /> <!-- import file="build_of_sdk.xml" / --> <import file="${sdk.dir}/tools/ant/build.xml" /> <target name="cleand" depends="clean" > <delete file="./assets/config.properties"/> </target> <target name="d" depends="cleand" > <property name="out.final.file" value="./dist/develop/ep.apk" /> <mkdir dir="./dist/develop"/> <antcall target="release" /> </target> <target name="helpme"> <echo>Android Ant Build For EPAPP. Available targets:</echo> <echo> helpme: Displays this help.</echo> <echo> d: Builds for final.</echo> <echo> Final release for production.</echo> <echo>Please feel free to ask help from wangle@easipass.com</echo> <echo>Sorry for this messed English show. :) </echo> </target>
</project>这个脚本对应 ant 的build.xml就简单了不是一点点了,不过注意配置环境变量哦。
其中 <import file="${sdk.dir}/tools/ant/build.xml" /> 则是导入ant自带的那个 build.xml,正因为导入了这个脚本
<antcall target="release" />这句话才能正常执行
再然后:我们添加一个ant使用的配置脚本:这个脚本是由 ant的build.xml去调用执行的,我们就不管了
文件名为 ant.properties
proguard.config=proguard.cfg key.store=./xxxxx.keystore key.alias=xxxx key.store.password=123456 key.alias.password=123456 proguard.config=proguard.cfg key.store=./xxxxx.keystore key.alias=xxxx key.store.password=123456 key.alias.password=123456
这个不用说也知道是干嘛用的了哦,打开混淆,导入签名啦。第一行是打开混淆,第二行往下则是导入签名,以及签名密码
至于签名,就不说啦,有了签名
key.store=./xxxxx.keystore 这个是给出签名的路径,我是直接将签名拷贝到了工程目录下了,你可以自己配置哦.
到这里架子已经搭建出来了哦,接下来就是根据自己的特殊需要,添加一些处理了
这里稍微花点控件介绍一下混淆
proguard.cfg这个是混淆脚本,由于一些三方包和android自带的四大组件等等,我们不能让他们混淆(三方包一般已经混淆过一次,再混淆则会出问题,而四大组建是因为它们会被android系统调用,混淆了,系统就找不到了),否则会出问题
我把我的proguard.cfg脚本贴上来哦
<P></P><PRE class=html name="code">-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-dontoptimize
-ignorewarnings
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keepattributes Signature
#这里是导入工程中所用到的一些三方包
-libraryjars libs/android-support-v4.jar
-libraryjars libs/umeng_sdk.jar
-libraryjars libs/android-wheel.jar
-libraryjars libs/com.springsource.org.apache.commons.beanutils-1.8.0.jar
-libraryjars libs/com.springsource.org.apache.commons.collections-3.2.1.jar
-libraryjars libs/com.springsource.org.apache.commons.lang-2.1.0.jar
-libraryjars libs/com.springsource.org.apache.commons.net-1.4.1.jar
-libraryjars libs/core.jar
-libraryjars libs/ezmorph-1.0.1.jar
-libraryjars libs/gson-1.7.1.jar
-libraryjars libs/json-lib-2.3-jdk15.jar
-libraryjars libs/ksoap2-android-assembly-3.0.0-RC.4-jar-with-dependencies.jar
-libraryjars libs/locSDK_3.1.jar
-libraryjars libs/mobiletools.jar
-libraryjars libs/pinyin4j-1.1.0.jar
-dontskipnonpubliclibraryclassmembers
-dontskipnonpubliclibraryclasses
</PRE><PRE class=html name="code">#这里是对gson的处理</PRE><PRE class=html name="code" sizcache="1" sizset="6">-keep class com.google.**{*;}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
<SPAN style="COLOR: rgb(255,0,0)">-keep class com.<SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif">xxxx</SPAN><补充:移动开发 , Android ,