android 混淆规则作用,整理Android最全的混淆规则大全(最新的开源框架混淆)

尉迟雅昶
2023-12-01

由于最近需要打包上传apk到应用市场。用到了一些开源项目。但发布apk需要混淆,而很多的项目的混淆规则都不太清楚,找起来太费劲了。就想着整个一个文档。

现在把这些的混淆规则分享给大家,也省得大家再去其它地方查找了。

提前说明:有些混淆规则可能未能及时更新,会有误差,若大家发现,欢迎指明。

proguard-square-retrofit2.pro

# Retrofit 2.X

## https://square.github.io/retrofit/ ##

-dontwarn retrofit2.**

-keep class retrofit2.** { *; }

-keepattributes Signature

-keepattributes Exceptions

-keepclasseswithmembers class * {

@retrofit2.http.* ;

}

proguard-square-retrofit.pro

# Retrofit 1.X

-keep class com.squareup.okhttp.** { *; }

-keep class retrofit.** { *; }

-keep interface com.squareup.okhttp.** { *; }

-dontwarn com.squareup.okhttp.**

-dontwarn okio.**

-dontwarn retrofit.**

-dontwarn rx.**

-keepclasseswithmembers class * {

@retrofit.http.* ;

}

# If in your rest service interface you use methods with Callback argument.

-keepattributes Exceptions

# If your rest service methods throw custom exceptions, because you've defined an ErrorHandler.

-keepattributes Signature

# Also you must note that if you are using GSON for conversion from JSON to POJO representation, you must ignore those POJO classes from being obfuscated.

# Here include the POJO's that have you have created for mapping JSON response to POJO for example.

proguard-square-otto.pro

## Square Otto specific rules ##

## https://square.github.io/otto/ ##

-keepattributes *Annotation*

-keepclassmembers class ** {

@com.squareup.otto.Subscribe public *;

@com.squareup.otto.Produce public *;

}

proguard-square-picasso.pro

## Square Picasso specific rules ##

## https://square.github.io/picasso/ ##

-dontwarn com.squareup.okhttp.**

proguard-square-okhttp3.pro

# OkHttp

-keepattributes Signature

-keepattributes *Annotation*

-keep class okhttp3.** { *; }

-keep interface okhttp3.** { *; }

-dontwarn okhttp3.**

proguard-square-dagger.pro

# Dagger ProGuard rules.

# https://github.com/square/dagger

-dontwarn dagger.internal.codegen.**

-keepclassmembers,allowobfuscation class * {

@javax.inject.* *;

@dagger.* *;

();

}

-keep class dagger.* { *; }

-keep class javax.inject.* { *; }

-keep class * extends dagger.internal.Binding

-keep class * extends dagger.internal.ModuleAdapter

-keep class * extends dagger.internal.StaticInjection

proguard-rx-java.pro

# RxJava 0.21

-keep class rx.schedulers.Schedulers {

public static ;

}

-keep class rx.schedulers.ImmediateScheduler {

public ;

}

-keep class rx.schedulers.TestScheduler {

public ;

}

-keep class rx.schedulers.Schedulers {

public static ** test();

}

proguard-guava.pro

# Configuration for Guava 18.0

#

# disagrees with instructions provided by Guava project: https://code.google.com/p/guava-libraries/wiki/UsingProGuardWithGuava

-keep class com.google.common.io.Resources {

public static ;

}

-keep class com.google.common.collect.Lists {

public static ** reverse(**);

}

-keep class com.google.common.base.Charsets {

public static ;

}

-keep class com.google.common.base.Joiner {

public static com.google.common.base.Joiner on(java.lang.String);

public ** join(...);

}

-keep class com.google.common.collect.MapMakerInternalMap$ReferenceEntry

-keep class com.google.common.cache.LocalCache$ReferenceEntry

# http://stackoverflow.com/questions/9120338/proguard-configuration-for-guava-with-obfuscation-and-optimization

-dontwarn javax.annotation.**

-dontwarn javax.inject.**

-dontwarn sun.misc.Unsafe

# Guava 19.0

-dontwarn java.lang.ClassValue

-dontwarn com.google.j2objc.annotations.Weak

-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

proguard-gson.pro

## GSON 2.2.4 specific rules ##

# Gson uses generic type information stored in a class file when working with fields. Proguard

# removes such information by default, so configure it to keep all of it.

-keepattributes Signature

# For using GSON @Expose annotation

-keepattributes *Annotation*

-keepattributes EnclosingMethod

# Gson specific classes

-keep class sun.misc.Unsafe { *; }

-keep class com.google.gson.stream.** { *; }

proguard-greendao.pro

# GreenDao rules

# Source: http://greendao-orm.com/documentation/technical-faq

#

-keepclassmembers class * extends de.greenrobot.dao.AbstractDao {

public static java.lang.String TABLENAME;

}

-keep class **$Properties

proguard-glide.pro

# Glide specific rules #

# https://github.com/bumptech/glide

-keep public class * implements com.bumptech.glide.module.GlideModule

-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {

**[] $VALUES;

public *;

}

proguard-facebook-fresco.pro

# Fresco v0.8.1 ProGuard rules.

# https://github.com/facebook/fresco

-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip

# Do not strip any method/class that is annotated with @DoNotStrip

-keep @com.facebook.common.internal.DoNotStrip class *

-keepclassmembers class * {

@com.facebook.common.internal.DoNotStrip *;

}

# Keep native methods

-keepclassmembers class * {

native ;

}

-dontwarn okio.**

-dontwarn javax.annotation.**

-dontwarn com.android.volley.toolbox.**

proguard-eventbus-3.pro

## New rules for EventBus 3.0.x ##

# http://greenrobot.org/eventbus/documentation/proguard/

-keepattributes *Annotation*

-keepclassmembers class ** {

@org.greenrobot.eventbus.Subscribe ;

}

-keep enum org.greenrobot.eventbus.ThreadMode { *; }

# Only required if you use AsyncExecutor

-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {

(java.lang.Throwable);

}

proguard-easy-adapter.pro

#Easy-Adapter v1.5.0

-keepattributes *Annotation*

-keepclassmembers class * extends uk.co.ribot.easyadapter.ItemViewHolder {

public (...);

}

proguard-crashlytics-2.pro

# Crashlytics 2.+

-keep class com.crashlytics.** { *; }

-keep class com.crashlytics.android.**

-keepattributes SourceFile, LineNumberTable, *Annotation*

# If you are using custom exceptions, add this line so that custom exception types are skipped during obfuscation:

-keep public class * extends java.lang.Exception

# For Fabric to properly de-

proguard-butterknife-7.pro

# ButterKnife 7

-keep class butterknife.** { *; }

-dontwarn butterknife.internal.**

-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {

@butterknife.* ;

}

-keepclasseswithmembernames class * {

@butterknife.* ;

}

proguard-alibaba-fastjson.pro

# fastjson proguard rules

# https://github.com/alibaba/fastjson

-dontwarn com.alibaba.fastjson.**

-keepattributes Signature

-keepattributes *Annotation*

proguard-action-bar-sherlock.pro

## ActionBarSherlock 4.4.0 specific rules ##

-keep class android.support.v4.app.** { *; }

-keep interface android.support.v4.app.** { *; }

-keep class com.actionbarsherlock.** { *; }

-keep interface com.actionbarsherlock.** { *; }

-keepattributes *Annotation*

## hack for Actionbarsherlock 4.4.0, see https://github.com/JakeWharton/ActionBarSherlock/issues/1001 ##

-dontwarn com.actionbarsherlock.internal.**

proguard-svgandroid.pro

## SVG Android ##

#https://github.com/pents90/svg-android

-keep class com.larvalabs.svgandroid.** {*;}

-keep class com.larvalabs.svgandroid.*$* {*;}

proguard-support-v7-appcompat.pro

-keep public class android.support.v7.widget.** { *; }

-keep public class android.support.v7.internal.widget.** { *; }

-keep public class android.support.v7.internal.view.menu.** { *; }

-keep public class * extends android.support.v4.view.ActionProvider {

public (android.content.Context);

}

proguard-support-design.pro

-dontwarn android.support.design.**

-keep class android.support.design.** { *; }

-keep interface android.support.design.** { *; }

-keep public class android.support.design.R$* { *; }

 类似资料: