有关android安全性的问题--代码混淆

转自:http://www.cnblogs.com/dream-sky/archive/2012/11/15/2771648.html

 


在project.properties里加上   proguard.config=proguard.cfg

proguard.cfg 配置如下:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

#忽略警告 也可以用-ignorewarnings
-dontwarn

#声明第三方jar包,不用管第三方jar包中的.so文件(如果有)
-libraryjars libs/tencent_openapi.jar
-libraryjars libs/httpmime-4.1.3.jar
-libraryjars libs/weibo.sdk.android.sso.jar
-libraryjars libs/android-support-v4.jar

-libraryjars  libs/AHibernate-1.1.jar
-libraryjars  libs/core.jar
-libraryjars  libs/gson-1.6.jar

-libraryjars  libs/android-support-v4.jar
-libraryjars  libs/baidumapapi_v2_1_2.jar
-libraryjars  libs/locSDK_3.1.jar
-libraryjars  libs/pinyin4j-2.5.0.jar

-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

-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 *;
}

#不混淆第三方jar包中的类
-keep class com.baidu.mapapi.** {*;}
-keep class com.tencent.tauth.** {*;}
-keep class org.apache.http.entity.mime.** {*;}
-keep class android.support.v4.** {*;}
-keep class android.net.http.** {*;}
-keep class com.weibo.sdk.android.** {*;}
-keep class com.sina.sso.** {*;}

-keep interface net.sourceforge.pinyin4j.** { *; }
-keep interface vi.com.gdi.bgl.android.** { *; }
-keep interface cn.sharesdk.** { *; }

说明一下,第三方jar包中如果有.so文件,不用去理会,引入的第三方jar文件不要混淆,否则可能会报异常

项目涉及到的jar包:

我自己项目中的混淆

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify

-dontwarn android.support.v4.**  
-dontwarn com.baidu.mapapi.utils.*
-dontwarn com.baidu.platform.comapi.b.*
-dontwarn com.baidu.platform.comapi.map.  
-dontwarn demo.** 
-dontwarn org.scribe.services.**
    
-libraryjars  libs/AHibernate-1.1.jar
-libraryjars  libs/core.jar
-libraryjars  libs/gson-1.6.jar

-libraryjars  libs/android-support-v4.jar
-libraryjars  libs/baidumapapi_v2_1_2.jar
-libraryjars  libs/locSDK_3.1.jar
-libraryjars  libs/pinyin4j-2.5.0.jar

-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
-keep public class * extends net.sourceforge.pinyin4j.**
-keep public class * extends vi.com.gdi.bgl.android.**
-keep public class * extends android.support.v4.**
-keep public class * extends cn.sharesdk.**
-keep public class * extends com.baidu.**
-keep public class * extends demo.**
-keep class net.sourceforge.pinyin4j.** {*;}
-keep class vi.com.gdi.bgl.android.** {*; }
-keep class cn.sharesdk.** {*;}
-keep class com.baidu.** {*;}
-keep class demo.** {*;}

-keep interface net.sourceforge.pinyin4j.** { *; }
-keep interface vi.com.gdi.bgl.android.** { *; }
-keep interface cn.sharesdk.** { *; }
-keep interface com.baidu.** { *; }
-keep interface demo.** { *; }
-keepattributes *Annotation*

##---------------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  
##---------------End: proguard configuration for Gson  ---------- 


-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-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

-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 *;
}

 

posted @ 2013-11-13 20:43  西北野狼  阅读(942)  评论(0编辑  收藏  举报