An Excerpt of Android Confusion

Posted by daedlus on Thu, 25 Jul 2019 10:52:58 +0200

Write in front

Dear friends and relatives, brothers and sisters of CSDN, I want to kill you! Here should be applause, disappeared nearly two months of Han Xiaodai, I came back, again need applause, the dull finally adapted to the new company's various models (in fact, hands from a 0-1 project). The followers will begin to fulfill their unfinished tasks and responsibilities. On the first day of business, it's not difficult to come. Let's talk about confusion. In fact, I was confused by the alliance. Finally, thank you for your concern and support. Let's get to the point.

1. Open up confusion

1. Find the gradle file of the app model for the project

2. Turn on the confusion switch

3. Find the confusion rule file

Interpretation of Confusion Rules

- include {filename} reads configuration parameters from a given file   
- basedirectory {directoryname} specifies the base directory as the relative file name for the future   
- injars {class_path} specifies the application jar,war,ear, and directory to be processed   
- outjars {class_path} specifies the name of the jar,war,ear, and directory to be output after processing.   
- libraryjars {classpath} specifies the library files required by the application jar,war,ear, and directory to be processed   
- dontskip nonpubliclibraryclasses specifies that non-public library classes are not ignored.   
- dontskip nonpubliclibraryclass members specify that members of library classes that do not ignore package visibility.  

Retention options   
- keep {Modifier} {class_specification} protects specified class files and class members   
- Keep class members {modifier} {class_specification} protect members of a specified class, and they will protect better if such classes are protected  
- keep classes with memberships {class_specification} protects members of specified classes and classes, provided that all specified classes and class members exist.   
- keepnames {class_specification} protects the name of the specified class and its members (if they do not compress steps to delete)   
- keep class membernames {class_specification} protects the name of the member of the specified class (if they do not compress steps to delete)   
- keep classes with member names {class_specification} protects the name of the specified class and class members if all the specified class members are present (after the compression step)   
- printseeds {filename} lists the member-keep options for classes and classes, which are standard output to a given file   

compress   
- dontshrink uncompressed input class file   
-printusage {filename}   
- dontwarn does not terminate if there is a warning  
-whyareyoukeeping {class_specification}       

optimization   
- dontoptimize does not optimize input class files   
- assumenosideeffects {class_specification} optimization assumes the specified method without any side effects   
- allowaccessmodification optimization allows access to and modification of modifier classes and class members   

confusion   
- dontobfuscate does not confuse input class files   
-printmapping {filename}   
- Apply mapping {filename} Reuse mapping increases confusion   
- obfuscation dictionary {filename} uses keywords in a given file as the name of the method to be obfuscated   
- Application of intrusive overload in overload aggressivity confusion   
- useuniqueclass membernames identifies the name of the member of the unified obfuscation class to increase obfuscation   
- Flatten package hierarchy {package_name} repackages all renamed packages and places them in a given single package   
- repackage class {package_name} repackage all renamed class files in a given single package   
- Dontusemixed class names do not produce a variety of class names when confused   
- Keep attributes {attribute_name,...} protect given optional attributes, such as LineNumberTable, LocalVariable Table, SourceFile, Deprecated, Synthetic, Signature, and   

InnerClasses.   
- renamesourcefileattribute {string} sets the string constants given in the source file  

3. Common confusion rules

#Specify the compression level of the code
-optimizationpasses 5

#Wrapped without mixing case and case
-dontusemixedcaseclassnames

#Do not ignore non-public library classes
-dontskipnonpubliclibraryclasses

 #Optimizing class files that do not optimize input
-dontoptimize

 #Pre-verification
-dontpreverify

 #Whether to log in case of confusion
-verbose

 # The algorithm used in confusion
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
#Ignore warnings
-ignorewarnings
#If you have a reference to the v4 package, you can add the following line
-keep public class * extends android.support.v4.app.Fragment
#List the code deleted from the apk
-printusage proguard/unused.txt
#Mapping before and after confusion
-printmapping proguard/mapping.txt

#If v4 or v7 package is referenced
-dontwarn android.support.**
#Keep the native approach unambiguous
#-keepclasseswithmembernames class * {
#    native <methods>;
#}
#Keep custom control classes unambiguous
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}
#Keep custom control classes unambiguous
-keepclassmembers class * extends android.app.Activity {
  public void *(android.view.View);
}
-keep public class * extends android.view.View {
    public <init>(android.content.Context);
  public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
   public void set*(...);
}
#Keep Parcelable unambiguous
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

#Keep Serializable unambiguous
-keepnames class * implements java.io.Serializable
#Do not confuse resource classes
-keepclassmembers class **.R$* {
   public static <fields>;
}
#Avoid confusing generics if confusing error reporting is recommended to turn off
#-keepattributes Signature
#Remove the code of Log class to print all levels of logs, and use it as a forbidden log when typing formal packages. Here it can be used as a function of forbidding log printing. Another implementation scheme is controlled by variables of BuildConfig.DEBUG.
-assumenosideeffects class android.util.Log {
    public static *** v(...);
    public static *** i(...);
   public static *** d(...);
    public static *** w(...);
    public static *** e(...);
}

#Substantive class
#Change to your package name
-keep public class com.test.test.entity.**{*;}
#Third-party package
#------------------------------------------------- Alliance - -----------------------------------------------------------------------------------------------------------------
-dontwarn com.taobao.**
-dontwarn anet.channel.**
-dontwarn anetwork.channel.**
-dontwarn org.android.**
-dontwarn org.apache.thrift.**
-dontwarn com.xiaomi.**
-dontwarn com.huawei.**

-keepattributes *Annotation*

-keep class com.taobao.** {*;}
-keep class org.android.** {*;}
-keep class anet.channel.** {*;}
-keep class com.umeng.** {*;}
-keep class com.xiaomi.** {*;}
-keep class com.huawei.** {*;}
-keep class org.apache.thrift.** {*;}

-keep class com.alibaba.sdk.android.**{*;}
-keep class com.ut.**{*;}
-keep class com.ta.**{*;}

-keep public class **.R$*{
   public static final int *;
}
#---------------------------------Glide-------------------------------
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

## for DexGuard only
#-keepresourcexmlelements manifest/application/meta-data@value=GlideModule

#Baidu ocr - -------------------------------------------------------------------------------------------------------------------
-keep class com.baidu.ocr.sdk.**{*;}
-dontwarn com.baidu.ocr.**
#---------------------------------fastJson-------------------------------
-dontwarn com.alibaba.fastjson.**
-keep class com.alibaba.fastjson.** { *; }

#---------------------------------banner-------------------------------
-keep class com.youth.banner.** {
    *;
 }

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

#---------------------------------androidx-------------------------------
-keep class com.google.android.material.** {*;}
-keep class androidx.** {*;}
-keep public class * extends androidx.**
-keep interface androidx.** {*;}
-dontwarn com.google.android.material.**
-dontnote com.google.android.material.**
-dontwarn androidx.**

# support-v7
#-dontwarn android.support.v7.**
#-keep class android.support.v7.internal.** { *; }
#-keep interface android.support.v7.internal.** { *; }
#-keep class android.support.v7.** { *; }

# support design
#---------------------------------support design-------------------------------
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }
#-------------- Retrofit----------------------------------------
#-dontwarn retrofit2.**
#-keep class retrofit2.** { *; }

-dontnote retrofit2.Platform
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
-dontwarn retrofit2.Platform$Java8
-keepattributes Signature
-keepattributes Exceptions



#-keepattributes Signature-keepattributes Exceptions
# --------------RxJava RxAndroid-------------------------------
-dontwarn sun.misc.**
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
    long producerIndex;
    long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode consumerNode;
}

#-------------- Gson------------------------
-keep class com.google.gson.stream.** { *; }
-keepattributes EnclosingMethod

I haven't written anything for two months. I'm trying my best. Thank you for your friends and relatives. Some of the content of this article comes from: Android confusion Thank you very much.

Topics: Android Google Apache SDK