android ant 最簡單的打包簽名,混淆方法

使用ant打包,若是腳本都是咱們本身一步一步來寫的話,是一個比較麻煩的東西。html

關於ant,咱們詳細看下:java

ant支持 ant debug,ant release等命令,咱們須要簽名混淆,那麼就須要ant release這個命令。android

首先:ant環境搭建,這我就很少說了,不少博客都有介紹,包括一些環境配置spring

而後:ant環境能夠以後,咱們須要一個 build.xml文件,這個是ant編譯去找的一個東西apache

 

<?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就簡單了不是一點點了,不過注意配置環境變量哦。json

 

其中 <import file="${sdk.dir}/tools/ant/build.xml" /> 則是導入ant自帶的那個 build.xml,正由於導入了這個腳本 app

<antcall target="release" />這句話才能正常執行less

再而後:咱們添加一個ant使用的配置腳本:這個腳本是由 ant的build.xml去調用執行的,咱們就無論了ide

文件名爲  ant.propertiesui

 

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系統調用,混淆了,系統就找不到了),不然會出問題

關於json的混淆尤爲要注意,可參考上一篇博客  http://blog.csdn.net/brightshadow11111/article/details/9469159

我把個人proguard.cfg腳本貼上來哦

 

-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

#這裏是對gson的處理
-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
-keep class com.xxxx.cmb.entity.** { *; }  
#這裏是對gson的用到的javabean處理
-keep class com.xxxx.ct.entity.** { *; }
-keep class com.xxxx.entity.** { *; } -keep class com.xxxxx.entity.** { *; } ##---------------End: proguard configuration for Gson -----------keep public class * extends android.app.Activity-keep public class * extends android.app.Application-keep public class * extends android.app.Service-keep public class * extends android.content.BroadcastReceiver-keep public class * extends android.content.ContentProvider-keep public class * extends android.app.backup.BackupAgentHelper-keep public class * extends android.preference.Preference-keep public class com.android.vending.licensing.ILicensingService-keep public class * extends net.sf.json.xml.XMLSerializer-keep class android.support.v4.** {*;} -keep interface android.support.v4.app.** {*;} -keep public class * extends android.support.v4.** -keep public class * extends android.app.Fragment-keep class com.google.gson.stream.** {*;} -keep class com.google.gson.examples.android.model.** {*;} -keepclasseswithmembernames class * { native <methods>;}-keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet);}-keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet, int);}-keepclassmembers class * extends android.app.Activity { public void *(android.view.View);}-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String);}-keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *;}-keep public class com.easipass.common.net.secret
#這裏是不混淆三方包
-keep class com.motorola.** { *;}-keep class com.baidu.location.** {*;}-keep class com.google.zxing.** {*;}-keep class android.support.v4.** {*;}-keep class net.sourceforge.pinyin4j.** {*;}-keep class kankan.wheel.widget.** {*;}-keep class org.apache.commons.collections.** {*;}-keep class org.apache.commons.beanutils.** {*;}-keep class org.apache.commons.lang.** {*;}-keep class org.apache.commons.net.** {*;}-keep class net.sf.ezmorph.** {*;}-keep class net.sf.json.** {*;}-keep class com.easipass.util.tools.** {*;}-keep class com.umeng.analytics.** {*;}-keep class com.umeng.common.** {*;}-keep class com.easipass.common.net.** {*;}-keep class net.sf.** {*;}-keep class com.badlogic.** {*;}-keep class * implements com.badlogic.gdx.utils.Json*
相關文章
相關標籤/搜索