2-step code obfuscation and 2-step code obfuscation
[Step 1 ]:
Modify build. gradle under module
BuildTypes {
Release {
// Whether to confuse
MinifyEnabled true
// Location of the obfuscated File
// Proguard is a free tool for compressing, optimizing, and confusing Java bytecode files
ProguardFiles getDefaultProguardFile('proguard-android.txt '), 'proguard-rules. Pro'
}
}
[Step 2 ]:
Add in proguard-rules.pro:
# Specify the code compression level
-Optimizationpasses 5
# Case insensitive
-Dontusemixedcaseclassnames
# Do not ignore non-public library classes
-Dontskipnonpubliclibraryclasses
# Optimize input class files
-Dontoptimize
# Pre-check
-Dontpreverify
# Whether logs are recorded during Obfuscation
-Verbose
# Obfuscation algorithm
-Optimizations! Code/simplification/arithmetic ,! Field /*,! Class/merging /*
# Protection Annotation
-Keepattributes * Annotation *
# Keep classes that are not obfuscated
-Keep public class * extends android. app. Fragment
-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 * extends android. app. backup. BackupAgentHelper
-Keep public class * extends android. preference. Preference
-Keep public class com. android. vending. licensing. ILicensingService
# If a v4 package is referenced, you can add the following line.
-Keep public class * extends android. support. v4.app. Fragment
# Ignore warning
-Ignorewarning
# Record the generated log data, which is output in the root directory of the project during gradle build ##
# Internal structure of all classes in the apk package
-Dump class_files.txt
# Unobfuscated classes and members
-Printseeds seeds.txt
# List codes deleted from the apk
-Printusage unused.txt
# Mappings before and after Obfuscation
-Printmapping mapping.txt
######## Record the generated log data. During gradle build, output-end in the root directory of the Project ######
##### Obfuscation and Protection of part of the code of your project and the referenced third-party jar package library #######
#-Libraryjars libs/umeng-analytics-v5.2.4.jar
# Samsung application market needs to add: sdk-v1.0.0.jar, look-v1.0.1.jar
#-Libraryjars libs/sdk-v1.0.0.jar
#-Libraryjars libs/look-v1.0.1.jar
# If you do not want to confuse keep
-Keep class com. lippi. recorder. iirfilterdesigner .**{*;}
# Umeng
-Keep class com. umeng .**{*;}
# Special project processing code
# Ignore warning
-Dontwarn com. lippi. recorder. utils **
# Keep a complete package
-Keep class com. lippi. recorder. utils .**{
*;
}
-Keep class com. lippi. recorder. utils. AudioRecorder {*;}
# If the v4 or v7 package is referenced
-Dontwarn android. support .**
#### Obfuscation and Protection of part of the code of your project and reference third-party jar package library-end ####
-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 native methods not obfuscated
-Keepclasseswithmembernames class *{
Native <methods>;
}
# Keep custom control classes unobfuscated
-Keepclasseswithmembers class *{
Public <init> (android. content. Context, android. util. AttributeSet );
}
# Keep custom control classes unobfuscated
-Keepclassmembers class * extends android. app. Activity {
Public void * (android. view. View );
}
# Keep Parcelable unobfuscated
-Keep class * implements android. OS. Parcelable {
Public static final android. OS. Parcelable $ Creator *;
}
# Keep Serializable unobfuscated
-Keepnames class * implements java. io. Serializable
# Keep Serializable not to be confused and the enum class not to be confused
-Keepclassmembers class * implements java. io. Serializable {
Static final long serialVersionUID;
Private static final java. io. ObjectStreamField [] serialPersistentFields;
! Static! Transient <fields>;
! Private <fields>;
! Private <methods>;
Private void writeObject (java. io. ObjectOutputStream );
Private void readObject (java. io. ObjectInputStream );
Java. lang. Object writeReplace ();
Java. lang. Object readResolve ();
}
# Keep The enum class enumerative. If the enum class is not obfuscated, we recommend that you directly use the-keepclassmembers class * implements java. io. Serializable mentioned above.
#-Keepclassmembers enum *{
# Public static ** [] values ();
# Public static ** valueOf (java. lang. String );
#}
-Keepclassmembers class *{
Public void * ButtonClicked (android. view. View );
}
# Do not confuse Resource Classes
-Keepclassmembers class **. R$ *{
Public static <fields>;
}
# Avoid obfuscation and generics. If obfuscation reports errors, we recommend that you disable them.
#-Keepattributes Signature
# If the log is removed and tested, we recommend that you define a switch to determine whether to output logs.
#-Assumenosideeffects class android. util. Log {
# Public static boolean isLoggable (java. lang. String, int );
# Public static int v (...);
# Public static int I (...);
# Public static int w (...);
# Public static int d (...);
# Public static int e (...);
#}
# If the Gson parsing package is used, you can directly Add the following lines to successfully confuse them. Otherwise, an error will be reported.
# Gson
#-Libraryjars libs/gson-2.2.2.jar
-Keepattributes Signature
# Gson specific classes
-Keep class sun. misc. Unsafe {*;}
# Application classes that will be serialized/deserialized over Gson
-Keep class com. google. gson. examples. android. model .**{*;}