android proguard
使用中遇到的问题;
1.
明明该类没有混淆但是报Caused by: java.lang.ClassCastException:
发现没类型没了:(加入下面)
#避免使用泛型的位置混淆后出现类型转换错误:
-keepattributes Signature
2.can't find referenced class
(加入)
-dontwarn
或者具体的
-dontwarn com.xx.bbb.**
3.有些使用这样的方法直接反编译被删除了;
(加入)
-keepclassmembers class * {
void *(android.view.View);
*** *Click(...);
*** *Event(...);
}
**********************************************************************************
前面的一些问题忘记了,这两个是记得最清楚的,希望记录下来能帮助到大家,一起学习;
**********************************************************************************
下面是我的混淆文件,希望如果你在做的时候遇到问题可以在下面回复记录;
**********************************************************************************
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
#不能混淆的代码
#系统接口
#Jni接口
#其他如四大组件、View等
#第三方类库如android-support
-dontwarn
#出现can't find referenced class的警告时,可以在proguard.cfg中添加-ignorewarnings来解决。
-ignorewarnings
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
#避免使用泛型的位置混淆后出现类型转换错误:
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.backup.BackupAgentHelper
-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.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep public class * extends android.support.v4.**
-keep public class * extends android.app.Fragment
#不要混淆xUtils com.lidroid.xutils中的注解类型,添加混淆配置:
-keep class * extends java.lang.annotation.**
#-keep public class * extends com.calendar.storm.manager.http.ZCBaseHttp
#-keep public class * extends com.calendar.storm.manager.http.ZCHttpManger
-keep class com.calendar.storm.manager.http.** { *; }
-keep class com.calendar.storm.manager.https.** { *; }
-keep class com.calendar.storm.entity.** { *; }
-keep class com.icaikee.xrzgp.model.** { *; }
#-keep class com.icaikee.xrzgp.request.** { *; }
-keep class com.icaikee.xrzgp.response.** { *; }
-keep class com.icaikee.xrzgp.db.** { *; }
-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 class * extends android.support.v4.Fragment {
# public void *(android.view.View);
#}
-keepclassmembers class * {
void *(android.view.View);
*** *Click(...);
*** *Event(...);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep class **.R$* {
*;
}
-keep public class * implements java.io.Serializable {
public *;
}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
#********************lib**************************
-keep class org.xclcharts.** { *; }
-keep class com.tencent.bugly.** { *; }
-keep class com.umeng.fb.** { *; }
-keep class com.google.zxing.** { *; }
-keep class com.alibaba.fastjson.** { *; }
-keep class de.greenrobot.dao.** { *; }
-keep class org.apache.http.entity.mime.** { *; }
-keep class javax.inject.** { *; }
-keep class com.jpush.android.** { *; }
-keep class com.tencent.** { *; }
-keep class com.nineoldandroids.** { *; }
-keep class com.squareup.okhttp.** { *; }
-keep class okio.** { *; }
-keep class com.tencent.stat.** { *; }
-keep class com.umeng.socialize.** { *; }
-keep class com.umeng.analytics.** { *; }
-keep class com.umeng.onlineconfig.** { *; }
-keep class com.lidroid.xutils.** { *; }
-keep class com.nostra13.universalimageloader.** { *; }
-keep class com.loopj.android.http.** { *; }