7

我正在使用 Proguard 来混淆 Android 应用程序。一切正常,但我正在努力从错误报告中追溯堆栈跟踪。

这是我的混淆代码的摘录:

    private ez a(x paramx)
  {
    return (ez)this.J.get(paramx);
  }

  private void a(com.b.a.f paramf)
  {
    Iterator localIterator = this.K.iterator();
    while (true)
    {
      if (!localIterator.hasNext())
        return;
      em localem = (em)localIterator.next();
      if (localem.a((int)(this.i / this.m - 202.0F), (int)(202.0F + (this.i + this.n) / this.m), (int)(this.j / this.m - 202.0F), (int)(202.0F + (this.j + this.o) / this.m)))
        localem.a(paramf, this.m, this.i, this.j);
    }
  }

  private void a(com.b.a.f paramf, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    Iterator localIterator = this.J.entrySet().iterator();
    while (true)
    {
      if (!localIterator.hasNext())
        return;
      ez localez = (ez)((Map.Entry)localIterator.next()).getValue();
      if (localez.a(paramInt1, paramInt2, paramInt3, paramInt4))
        localez.a(paramf, this.k, this.m, this.i, this.j);
    }
  }

您会注意到上述所有 3 个方法(取自同一个类)具有相同的名称 = 'a'。当然这在运行时不会造成问题,因为它们有不同的参数。但是在我混淆的堆栈跟踪中:

java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at java.util.concurrent.CopyOnWriteArrayList.get(CopyOnWriteArrayList.java:117)
at uk.co.ionage.ionage.co.a(Unknown Source)
at uk.co.ionage.ionage.co.g(Unknown Source)
at uk.co.ionage.ionage.n.b(Unknown Source)
at uk.co.ionage.ionage.n.a(Unknown Source)
at uk.co.ionage.ionage.co.a(Unknown Source)
at uk.co.ionage.ionage.co.a(Unknown Source)
at uk.co.ionage.ionage.Gameplay.a(Unknown Source)
at uk.co.ionage.ionage.cn.run(Unknown Source)

这是个问题。我不知道它指的是哪个“a”方法。当我使用retrace.bat 时,它会列出所有名为“a”的方法。

这是我的 proguard.config:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-dontwarn android.support.**
-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

-keepclasseswithmembernames 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 class * extends android.app.Activity {
   public void *(android.view.View);
}

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

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

##---------------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.gameanalytics.android.** { *; }
##---------------End: proguard configuration for Gson ----------

这是非常典型的,除了我在最后添加了一些内容来帮助支持我对 JSON/GSON 的使用。

我可以添加一个选项来强制 proguard 给每个方法一个不同的名称吗?

4

1 回答 1

15

由于缺少行号,堆栈跟踪变得模棱两可。您可以使用以下 ProGuard 选项保留它们:

-renamesourcefileattribute MyApplication
-keepattributes SourceFile,LineNumberTable

请参阅 ProGuard 手册 > ReTrace >使用

请参阅 ProGuard 手册 > 示例 >生成有用的堆栈跟踪

或者,您可以分配唯一的名称:

-useuniqueclassmembernames

然而。方法名称可以从一开始就被重载,而 ProGuard 不会改变这一点。

旁注:如果您正确设置了 project.properties,最新版本的 Android SDK 会自动应用您配置的默认部分:

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
于 2013-07-28T13:47:06.873 回答