Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable aggressive overloading in ProGuard for Android

In order to ease users' stacktraces analysis, I'd like to disable "aggressive overloading" when ProGuard is obfuscating my Android app. In my obfuscated APK, I often have classes containing several methods/fields named a() in the same class, which is quite difficult to analyze a stacktrace, since it doesn't include method parameters or line number.

According to the ProGuard documentation, using option -overloadaggressively forces this overloading. The problem is that ProGuard seems to use this option when obfuscating my app even if my ProGuard configuration file doesn't contain this option:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-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

-keepclasseswithmembers class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

How can I disable this aggressive overloading?

My target is Android 3.2 / API level 13.

like image 947
xav Avatar asked Jan 11 '23 04:01

xav


1 Answers

The option -overloadaggressively only pertains to the return types of methods.

  • The Java language already allows ordinary overloading, where different methods can have the same name, as long as they have different argument types.
  • Java bytecode additionally allows "aggressive" overloading, where different methods can have the same name, as long as they have different argument/return types.

As a result, even -useuniqueclassmembernames can't guarantee unique names, since the names may be overloaded to start with. To get unambiguous stack traces, you should preserve line numbers:

-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute ''

See the ProGuard manual > Examples > Producing useful stack traces.

like image 107
Eric Lafortune Avatar answered Jan 17 '23 14:01

Eric Lafortune