dexguard 混淆问题

Posted

技术标签:

【中文标题】dexguard 混淆问题【英文标题】:dexguard obfuscation issue 【发布时间】:2015-06-14 11:26:13 【问题描述】:

我正在使用 dexguard 来混淆我的应用程序,但是当我这样做时,我在运行应用程序时遇到了崩溃。下面是堆栈跟踪。

04-08 17:46:11.786: E/androidRuntime(7569): java.lang.RuntimeException: An error occured while executing doInBackground()
04-08 17:46:11.786: E/AndroidRuntime(7569):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at java.lang.Thread.run(Thread.java:841)
04-08 17:46:11.786: E/AndroidRuntime(7569): Caused by: java.lang.NoSuchFieldError: ˈ
04-08 17:46:11.786: E/AndroidRuntime(7569):     at java.lang.Class.getDeclaredAnnotation(Native Method)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at java.lang.Class.getAnnotation(Class.java:243)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at o.hS.ˊ(:124)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at o.ȑ.ˊ(:113)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at o.ڋ.doInBackground(:42)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-08 17:46:11.786: E/AndroidRuntime(7569):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-08 17:46:11.786: E/AndroidRuntime(7569):     ... 4 more

这是我从 ACRA lib init 方法中得到的,因为我们在其中有 getAnnotation 方法。我用过-keepattributes *Annotation*-keep class org.acra.ACRA *;

但运气不好……

有人知道吗?

谢谢, 吉姆。

【问题讨论】:

【参考方案1】:

您可能不需要混淆 ACRA 代码,因为它不是秘密库。所以你可以这样做:

# Keep all the ACRA classes
-keep class org.acra.**  *; 

或者,如果您非常特别,您可以尝试使用:https://github.com/ACRA/acra/wiki/Proguard 在配置文件中包含以下内容来配置 ACRA:

# keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'.
# Note: if you are removing log messages elsewhere in this file then this isn't necessary
-keep class org.acra.ACRA 
    *;


# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode 
    *;


-keepnames class org.acra.sender.HttpSender$** 
    *;


-keepnames class org.acra.ReportField 
    *;


# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter

    public void addCustomData(java.lang.String,java.lang.String);
    public void putCustomData(java.lang.String,java.lang.String);
    public void removeCustomData(java.lang.String);


# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter

    public void handleSilentException(java.lang.Throwable);
    

【讨论】:

以上是关于dexguard 混淆问题的主要内容,如果未能解决你的问题,请参考以下文章

DexGuard/Proguard 混淆注释值

使用 DexGuard 混淆动态加载的类

如何防止 Dexguard 混淆 android studio 中的资源文件夹?

Android/Java 混淆:R8 与(ProGuard 或 DexGuard)?

我应该在 proGuard 上使用 dexGuard、redEX 来混淆广播接收器吗

DexGuard 如何加密类?