zoukankan      html  css  js  c++  java
  • Android APK混淆

    APK混淆

    1 修改project.properties文件 即可实现对项目进行全局混码
    将proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
    前的#去掉即可

    2 proguard-project.txt 混淆的申明 有一些代码不能被混淆

    -optimizationpasses 5                                                           # 指定代码的压缩级别
    -dontusemixedcaseclassnames                                                     # 是否使用大小写混合
    -dontskipnonpubliclibraryclasses                                                # 是否混淆第三方jar
    -dontpreverify                                                                  # 混淆时是否做预校验
    -verbose                                                                        # 混淆时是否记录日志
    -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*        # 混淆时所采用的算法
    
    -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 方法不被混淆
        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 * {                                                      # 保持枚举 enum 类不被混淆
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }
    
    -keep class * implements android.os.Parcelable {                                # 保持 Parcelable 不被混淆
      public static final android.os.Parcelable$Creator *;
    }
    
    -keepclassmembers class * {
       public <init>(org.json.JSONObject);
    }
    
    -keep class android.support.v4.**{*;}
    -keepattributes *Annotation*
    
    -keep class MyClass;                                                            # 保持自己定义的类不被混淆
    -optimizationpasses 5
    -dontusemixedcaseclassnames
    -dontskipnonpubliclibraryclasses
    -dontpreverify
    -verbose
    -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
    
    -keepattributes *Annotation*
    -keepattributes Signature
    
    -libraryjars libs/apns_1.0.6.jar
    -libraryjars libs/armeabi/libBaiduMapSDK_v2_3_1.so
    -libraryjars libs/armeabi/liblocSDK4.so
    -libraryjars libs/baidumapapi_v2_3_1.jar
    -libraryjars libs/core.jar
    -libraryjars libs/gesture-imageview.jar
    -libraryjars libs/gson-2.0.jar
    -libraryjars libs/infogracesound.jar
    -libraryjars libs/locSDK_4.0.jar
    -libraryjars libs/ormlite-android-4.48.jar
    -libraryjars libs/ormlite-core-4.48.jar
    -libraryjars libs/universal-image-loader-1.9.0.jar
    
    -keep class com.baidu.** { *; } 
    -keep class vi.com.gdi.bgl.android.**{*;}
    
    -keep public class * extends android.app.Fragment  
    -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 * extends android.support.v4.**
    -keep public class com.android.vending.licensing.ILicensingService
    
    -keep class com.google.gson.stream.** { *; }
    -keep class com.google.gson.examples.android.model.** { *; }
    -keep class com.uuhelper.Application.** { *; }
    -keep class net.sourceforge.zbar.** { *; }
    -keep class com.google.android.gms.** { *; } 
    
    -keep class com.bank.pingan.model.** { *; }
    
    -keep public class * extends com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
    -keep public class * extends com.j256.ormlite.android.apptools.OpenHelperManager
     
    -keep class com.android.vending.licensing.ILicensingService
    -keep class android.support.v4.** { *; }  
    -keep class org.apache.commons.net.** { *; }  
    -keep class com.tencent.** { *; }  
     
    -keep class com.umeng.** { *; }  
    -keep class com.umeng.analytics.** { *; }  
    -keep class com.umeng.common.** { *; }  
    -keep class com.umeng.newxp.** { *; }  
     
    -keep class com.j256.ormlite.** { *; }  
    -keep class com.j256.ormlite.android.** { *; }  
    -keep class com.j256.ormlite.field.** { *; }  
    -keep class com.j256.ormlite.stmt.** { *; } 
    
    -dontwarn android.support.v4.**  
    -dontwarn org.apache.commons.net.** 
    -dontwarn com.tencent.**  
    
    -keepclasseswithmembernames class * {
        native <methods>;
    }
    
    -keepclasseswithmembernames class * {
        public <init>(android.content.Context, android.util.AttributeSet);
    }
    
    -keepclasseswithmembernames class * {
        public <init>(android.content.Context, android.util.AttributeSet, int);
    }
    
    -keepclassmembers enum * {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }
    
    -keep class * implements android.os.Parcelable {
      public static final android.os.Parcelable$Creator *;
    }
    
    -keepclasseswithmembers class * {
        public <init>(android.content.Context);
    }
    
    -dontshrink
    -dontoptimize
    -dontwarn com.google.android.maps.**
    -dontwarn android.webkit.WebView
    -dontwarn com.umeng.**
    -dontwarn com.tencent.weibo.sdk.**
    -dontwarn com.facebook.**
    
    -keep enum com.facebook.**
    -keepattributes Exceptions,InnerClasses,Signature
    -keepattributes *Annotation*
    -keepattributes SourceFile,LineNumberTable
    
    -keep public interface com.facebook.**
    -keep public interface com.tencent.**
    -keep public interface com.umeng.socialize.**
    -keep public interface com.umeng.socialize.sensor.**
    -keep public interface com.umeng.scrshot.**
    
    -keep public class com.umeng.socialize.* {*;}
    -keep public class javax.**
    -keep public class android.webkit.**
    
    -keep class com.facebook.**
    -keep class com.umeng.scrshot.**
    -keep public class com.tencent.** {*;}
    -keep class com.umeng.socialize.sensor.**
    
    -keep class com.tencent.mm.sdk.openapi.WXMediaMessage {*;}
    
    -keep class com.tencent.mm.sdk.openapi.** implements com.tencent.mm.sdk.openapi.WXMediaMessage$IMediaObject {*;}
    
    -keep class im.yixin.sdk.api.YXMessage {*;}
    -keep class im.yixin.sdk.api.** implements im.yixin.sdk.api.YXMessage$YXMessageData{*;}
    
    -keep public class [your_pkg].R$*{
        public static final int *;
    }

    使用Gson库混淆后报错的解决办法

    java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.meibeike.meiphoto.common.protocol.model.Cloud123EntityListEntity

    proguard-project.txt配置文件中添加两项即可

    -keepattributes Signature

    -keepattributes *Annotation*

    -keep class sun.misc.Unsafe { *; }
    -keep class com.google.gson.examples.android.model.** { *; }

  • 相关阅读:
    Unity3D命令行Build
    关于Unity3D的协程(Coroutine)
    牛腩购物34:支付宝的集成和使用(web网站和web应用程序一眼判断的区别),支付宝即时到账
    linqpad 的下载使用
    linq 的延时执行和即时执行
    冒泡排序
    c# 的继承,继承类实例化的时候,会先调用基类的构造函数,然后再调用自己的构造函数,base 的用法,有override和没有override的区别
    zoj1002 Fire Net
    zjut1675 I like DPS!!!
    zjut1673搭数字II
  • 原文地址:https://www.cnblogs.com/huanyi0723/p/5103574.html
Copyright © 2011-2022 走看看