码迷,mamicode.com
首页 > 其他好文 > 详细

应用程序的混淆

时间:2015-10-07 14:40:41      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:

应用程序的混淆


混淆步骤:
1、在工程的根目录,找到project.properties文件
2、将下面一句注释给打开
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt  
3、然后将\sdk\tools\proguard\proguard-android.txt复制到工程的根目录下,并将project.properties下句改成:
proguard.config=proguard-android.txt
4、\工程名\proguard\mapping.txt 混淆的映射文件,混淆后对应的名字
4、混淆后,apk大小也会变小,因为名字都变短了
5、四大组件和自定义view对象也没有改变,因为在布局文件中用到了,如果给混淆了,那么将找不到,还有反射的类也不要给混淆
6、proguard-android.txt详解
proguard-android.txt详解:
自己保留自己的类,如:
-keep class  cn.zengfansheng.mobilesafe.domain.AppInfo
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
 
-dontusemixedcaseclassnames  不要使用混合大小写的类名
-dontskipnonpubliclibraryclasses  三方使用的类库也会混淆
-verbose 日志 \proguard\*.txt 否则,下面的几个txt文件将会没有
 
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize   不要被代码优化(会将没有使用的方法删除,如回调函数)
-dontpreverify 不要对代码预先的校验
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.
 
-keepattributes *Annotation* 带注解的保留(反射)
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
 
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}
 
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {  保留view
   void set*(***);
   *** get*();
}
 
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity { 保留Activity
   public void *(android.view.View);
}
 
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * { 保留枚举
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
 
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
 
-dontwarn net.youmi.android.**  
    -keep class net.youmi.android.** {   有米的保留
    *; 
    } 
-keep class  cn.zengfansheng.mobilesafe.domain.AppInfo
 
-keepclassmembers class **.R$* { 保留R文件
    public static <fields>;
}
 
# The support library contains references to newer platform versions.
# Don‘t warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**
问题:
解决:由于第三方(如广告平台有米),已经对代码进行的混淆,此时需要忽略掉
-dontwarn net.youmi.android.**
    -keep class net.youmi.android.** {
    *;  
    }    
解决2:升级Proguard。目前最新的proguard是4.7版,我这边升级到Proguard4.6就OK了。
从proguard官网下载4.6的,覆盖到tools/proguad/bin、lib这两个文件夹就OK了.我这边是这样解决的。
下载地址:http://sourceforge.net/projects/proguard/files/latest/download?source=files
技术分享
技术分享
 
 





应用程序的混淆

标签:

原文地址:http://www.cnblogs.com/relice/p/4858598.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!