【代码】android 程序代码混淆 proguard 脚本 proguard.cfg

 android 代码混淆
1 proguard.cfg,这就是混淆所需的proguard脚本啊。
 
其代码如下:
 
view plain
-optimizationpasses 5 
-dontusemixedcaseclassnames 
-dontskipnonpubliclibraryclasses 
-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 com.android.vending.licensing.ILicensingService 
-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 *; 
} 

从脚本中可以看到,混淆中保留了继承自Activity、Service、Application、BroadcastReceiver、ContentProvider等基本组件。
并保留了所有的Native变量名及类名,所有类中部分以设定了固定参数格式的构造函数,枚举等等。(详细信息请参考<proguard_path>/examples中的例子及注释。)
2 在工程的"default.properties"中添加这样一句话“proguard.config=proguard.cfg”
 
 
打包签名后的.apk就是混淆的,其实我们只要做一步就可以了就是在"default.properties"中添加这样一句话“proguard.config=proguard.cfg”就可以了。
 
出现错误:
[INFO] Warning: there were 294 unresolved references to classes or interfaces.
[INFO]          You may need to specify additional library jars (using '-library
jars').
[INFO] Warning: there were 3 unresolved references to program class members.
      You should consider explicitly keeping the mentioned class members
      (using '-keep' or '-keepclassmembers').
[INFO]          Your input classes appear to be inconsistent.
[INFO]          You may need to recompile them and try again.
[INFO]          Alternatively, you may have to specify the option
[INFO]          '-dontskipnonpubliclibraryclassmembers'.
[INFO] java.io.IOException: Please correct the above warnings first.
[INFO]  at proguard.Initializer.execute(Initializer.java:321)
[INFO]  at proguard.ProGuard.initialize(ProGuard.java:211)
[INFO]  at proguard.ProGuard.execute(ProGuard.java:86)
[INFO]  at proguard.ProGuard.main(ProGuard.java:492)

解决方法如下:解决方法找到了,在proguard.cfg文件中加入-ignorewarnings就可以跳过这个错误了。


本文出自 “清源教育” 博客,转载请注明此处,谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值