8. Keep rules
-keep
• keep class and class members
-keepclassmembers
• keep class members if their class is kept
-keepclasseswithmembers
• keep class with members if all the class members
are present
9. Keep rules
-keepnames
• short for -keep,allowshrinking class_specification
-keepclassmembernames
-keepclasseswithmembernames
12. Keep Attributes
-keepattributes EnclosingMethod
• specified the method in which the class was
defined
-keepattributes InnerClasses
• if you have inner class that can be reference from
outside of the library
14. Keep Modifiers
allowshrinking
• Specifies whether the entry points specified in the keep tag may
be shrunk.
allowoptimization
• Specifies whether the entry points specified in the keep tag may
be optimized.
allowobfuscation
• Specifies whether the entry points specified in the keep tag may
be obfuscated.
26. Generated ProGuard config
• build/intermediates/proguard-rules
• components in AndroidManifest.xml
• custom views in layouts
• only when minifyEnabled true
27. Config merging
-printconfiguration configuration.txt
• merging is a bit stupid
-keepattributes
*Annotation*,SourceFile,LineNumberTable,Signature,Excepti
ons,*Annotation*,Exceptions,*Annotation*,Exceptions,*Anno
tation*,Signature,Exceptions,*Annotation*,Exceptions,Sign
ature,*Annotation*,Signature,Exceptions,*Annotation*,Exce
ptions,*Annotation*,Signature,Exceptions,*Annotation*,Sig
nature,Signature,Exceptions,*Annotation*,Signature
29. Deobfuscation
• ReTrace
• retrace.sh mapping.txt [<stacktrace_file>]
• completeness depends on presence of line
number tables
• -keepattributes SourceFile,LineNumberTable
• ambiguous without these attributes - it will list
all possible original method names
• -renamesourcefileattribute MyApp
• resolve unknown source
32. Some library configs
• Retrofit
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions
• ButterKnife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}
33. Some library configs
• Otto
-keepattributes *Annotation*
-keepclassmembers class ** {
@com.squareup.otto.Subscribe public *;
@com.squareup.otto.Produce public *;
}
36. Tips, Tricks & Traps
• never use
-dontwarn **
-dontnote **
37. Tips, Tricks & Traps
• in library projects, in customerProguardFiles don’t
use:
• -printconfiguration configuration.txt
• -dontobfuscate, -dontoptimize, …
• -keepattributes
SourceFile,LineNumberTable,LocalVariableTable,L
ocalVariableTypeTable
• declare the bare minimum
38. Tips, Tricks & Traps
-applymapping <file>
• reuse previous mapping
-obfuscationdictionary <file>
• custom dictionary
• you can e.g. use Java keywords there (not that
helpful)
39. Tips, Tricks & Traps
-repackageclasses 'com.example.obfuscated'
• in Java there can be a problem when class tries
to load resource in the same directory
40. DexGuard
• comercial
• extra features
• resource obfuscation
• string encryption
• class encryption
• dex splitting
• native code obfuscation