Android如何代码混淆,防止apk程序被反编译

如题所述

下面具体说一说怎么样让SDK2.3下的proguard.cfg文件起作用,先来看看android-sdk-windows\tools\lib\proguard.cfg的内容:view plain 1. -optimizationpasses 5 2. -dontusemixedcaseclassnames 3. -dontskipnonpubliclibraryclasses 4. -dontpreverify 5. -verbose 6. -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7. 8. -keep public class * extends android.app.Activity 9. -keep public class * extends android.app.Application 10. -keep public class * extends android.app.Service 11. -keep public class * extends android.content.BroadcastReceiver 12. -keep public class * extends android.content.ContentProvider 13. -keep public class * extends android.app.backup.BackupAgentHelper 14. -keep public class * extends android.preference.Preference 15. -keep public class com.android.vending.licensing.ILicensingService 16. 17. -keepclasseswithmembernames class * { 18. native <methods>; 19. } 20. 21. -keepclasseswithmembernames class * { 22. public <init>(android.content.Context, android.util.AttributeSet); 23. } 24. 25. -keepclasseswithmembernames class * { 26. public <init>(android.content.Context, android.util.AttributeSet, int); 27. } 28. 29. -keepclassmembers enum * { 30. public static **[] values(); 31. public static ** valueOf(java.lang.String); 32. } 33. 34. -keep class * implements android.os.Parcelable { 35. public static final android.os.Parcelable$Creator *; 36. } 从脚本中可以看到,混淆中保留了继承自Activity、Service、Application、BroadcastReceiver、ContentProvider等基本组件以及com.android.vending.licensing.ILicensingService, 并保留了所有的Native变量名及类名,所有类中部分以设定了固定参数格式的构造函数,枚举等等。) 让proguard.cfg起作用的做法很简单,就是在eclipse自动生成的default.properties文件中加上一句“proguard.config=proguard.cfg”就可以了 完整的default.properties文件应该如下:view plain 1. # This file is automatically generated by Android Tools. 2. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3. # 4. # This file must be checked in Version Control Systems. 5. # 6. # To customize properties used by the Ant build system use, 7. # "build.properties", and override values to adapt the script to your 8. # project structure. 9. 10. # Project target. 11. target=android-9 12. proguardproguard.config=proguard.cfg 大功告成,正常的编译签名后就可以防止代码被反编译了。
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网