How to tell ProGuard obfuscation methods and class names?

I use ProGuard to obfuscate my apk, but there are no changes in class names and methods - they are the same as before. Only variable names are changed.

Most of them do not extend classes, such as Activity; there is some inheritance in my code, but it is 100% written by me.

I use d2j-dex2jar and jd-gui to check the results.

Some classes are excluded due to the use of GSON, here is my proguard-project.txt:

-keep class com.google.ads.** # Don't proguard AdMob classes -dontwarn com.google.ads.** # Temporary workaround for v6.2.1. It gives a warning that you can ignore # Add any classes the interact with gson -keep class com.revicostudio.gravityrun.playerdata.PlayerData -keep class com.revicostudio.gravityrun.playerdata.SettingsDescriptor -keep class com.revicostudio.gravityrun.playerdata.ShipStatus -keep class com.revicostudio.gravityrun.descriptors.ShipDescriptor -keep class com.revicostudio.gravityrun.descriptors.Ships -keep class com.revicostudio.gravityrun.game.galaxies.Galaxies -keep public class com.badlogic.** {*;} ##---------------Begin: proguard configuration common for all Android apps ---------- -optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontskipnonpubliclibraryclassmembers -dontpreverify -verbose -dump class_files.txt -printseeds seeds.txt -printusage unused.txt -printmapping mapping.txt -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -allowaccessmodification -keepattributes *Annotation* -renamesourcefileattribute SourceFile -keepattributes SourceFile,LineNumberTable -repackageclasses '' -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 -dontnote com.android.vending.licensing.ILicensingService # Explicitly preserve all serialization members. The Serializable interface # is only a marker interface, so it wouldn't save them. -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(); } # Preserve all native method names and the names of their classes. -keepclasseswithmembernames class * { native <methods>; } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet, int); } # Preserve static fields of inner classes of R classes that might be accessed # through introspection. -keepclassmembers class **.R$* { public static <fields>; } # Preserve the special static methods that are required in all enumeration classes. -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep public class * { public protected *; } -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } ##---------------End: proguard configuration common for all Android apps ---------- ##---------------Begin: proguard configuration for Gson ---------- # 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* # Gson specific classes -keep class sun.misc.Unsafe { *; } #-keep class com.google.gson.stream.** { *; } # Application classes that will be serialized/deserialized over Gson -keep class com.google.gson.examples.android.model.** { *; } ##---------------End: proguard configuration for Gson ---------- 
+8
java android obfuscation proguard
source share
3 answers

If you have this problem with classes (Activity, Services or BroadcastReceivers) then this is normal.

Proguard does not confuse Component names.


And if you do classes that are defined as

 -keep class com.revicostudio.gravityrun.playerdata.PlayerData -keep class com.revicostudio.gravityrun.playerdata.SettingsDescriptor -keep class com.revicostudio.gravityrun.playerdata.ShipStatus -keep class com.revicostudio.gravityrun.descriptors.ShipDescriptor -keep class com.revicostudio.gravityrun.descriptors.Ships -keep class com.revicostudio.gravityrun.game.galaxies.Galaxies 

ALSO their name cannot be changed due to the keep option.


Try removing the line -keep public class * { public protected *; } -keep public class * { public protected *; }

+7
source share

For some time, when obfuscating the class name does not work, the reason is "butterknife" so add the rules below to your proguard file.

 # Butterknife -dontwarn butterknife.internal.** -keep class butterknife.** { *; } -keep class **$$ViewInjector { *; } -keepclasseswithmembernames class * { @butterknife.InjectView <fields>; } -keepclasseswithmembernames class * { @butterknife.OnClick <methods>; @butterknife.OnEditorAction <methods>; @butterknife.OnItemClick <methods>; @butterknife.OnItemLongClick <methods>; @butterknife.OnLongClick <methods>; } 

NOTE. Use the above rules only when using butterknife.

+2
source share

The previous Butterknife instructions specific to proguard lead to this problem, if you use butterknife and an older version, such as version 7, make sure you do not have this line in your protected rules.

 -keepnames class * { @butterknife.Bind *;} 

This causes all class names to not be confused.

Use the configuration below for butterknife, better and in the future proof compare with another sentence.

 # ButterKnife -keep class butterknife.** { *; } -dontwarn butterknife.internal.** -keep class **$$ViewBinder { *; } -keepclasseswithmembernames class * { @butterknife.* <fields>; } -keepclasseswithmembernames class * { @butterknife.* <methods>; } 
+1
source share

All Articles