如何在 Android 上使用混淆(使用 ProGuard)的应用程序进行调试?
当我遇到这样的问题时,
ERROR/AndroidRuntime(18677): Caused by: java.lang.NullPointerException
ERROR/AndroidRuntime(18677): at com.companyname.a.a.a(Unknown Source)
我怎样才能知道问题出在哪里并调试这个问题? 我只得到 ProGuard 的映射输出,不知道行号。 谢谢。
When I got something like this
ERROR/AndroidRuntime(18677): Caused by: java.lang.NullPointerException
ERROR/AndroidRuntime(18677): at com.companyname.a.a.a(Unknown Source)
How can I know where the problem is and debug this issue?
I only got the mapping output from ProGuard and don't know the line number.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将以下行添加到您的 proguard 配置中。
现在,您的堆栈跟踪将包括行号,并且通过使用 proguard 附带的 retrace 工具(包含在 Android SDK 中),您可以像平常一样进行调试。
请注意,即使您没有使用这两个配置选项,只要您有映射文件,retrace 仍然可以输出有用的信息,尽管并不完全明确。
注意:带有映射的文件是由 proguard 配置选项生成的:
在 Android SDK 附带的 ant 文件中,它被设置为 mapping.txt。
祝你好运。
Add the following lines to your proguard configuration.
Now your stack traces will include line numbers, and by using the retrace tool that ships with proguard (included in the Android SDK), you are able to debug like normal.
Note that even if you didn't use these two configuration options, retrace still can output useful information provided you have the mappings file, albeit not totally unambiguously.
Note: the file with the mappings is produced by the proguard configuration option:
In the ant file shipped with the Android SDK, it is set to mapping.txt.
Good luck.
要利用 Android Market 帐户中的任何堆栈跟踪,您可以使用通过 ProGuard 配置中的
-printmapping
选项生成的映射文件,以及 ReTrace(ProGuard 配套工具)来解码堆栈跟踪。您也可以使用地图文件的内容手动解码,但这很乏味。在 ProGuard 手册的示例下,有一节介绍了生成有用的模糊堆栈跟踪,包括如何保留行号。
不幸的是,如果您没有设置 ProGuard 来保留行号,那么您将只能识别抛出异常的方法。
To make use of any stack traces from your Android Market account, you can use your map file, produced with the
-printmapping
option in the ProGuard config, with ReTrace (ProGuard companion tool) to decode the stack trace. You can also decode by hand using the contents of the map file, but this is tedious.In the ProGuard Manual under examples, there is a section about producing useful obfuscated stack traces including how to keep line numbers.
Unfortunately if you did not set the ProGuard to keep the line numbers, then you will only be able to identify the method that throws the exception.
要回溯混淆的 ProGuard 文件,请执行以下步骤:
您需要安装 Proguard。
Proguard 为您提供了一个 UI 模式,这是一个很棒的回溯工具。
打开MAC机中找到的proguardgui.sh
您可以通过终端运行它。
To retrace back obfuscated ProGuard file do the following steps:
You need to install Proguard.
Proguard provides you with a UI mode which is great tool to retrace.
Open up the proguardgui.sh which you find it in MAC machine
You can run it through the terminal.
将堆栈跟踪粘贴到 stack_trace.txt 中
运行以下命令: java -jar retrace.jar classes-processed.map stack_trace.txt
retrace.jar 位于 sdk\tools\proguard\lib\retrace.jar
classes-processed.map 是混淆时由 proguard 生成的输出文件
Paste your stack trace in stack_trace.txt
Run the following command: java -jar retrace.jar classes-processed.map stack_trace.txt
retrace.jar is at sdk\tools\proguard\lib\retrace.jar
classes-processed.map is the output file generated by proguard when you did obfuscation
以下是 Android SDK 中有关 retrace 工具的官方文档的链接:https ://developer.android.com/studio/build/shrink-code#decode-stack-trace
这篇文章也很好:https://medium.com/@maheshwar.ligade/de-obfuscate-stack-traces-6e19a52a3379
对于所有复制粘贴的兄弟:
Here's a link to official documentation on retrace tool from Android SDK: https://developer.android.com/studio/build/shrink-code#decode-stack-trace
This article is good too: https://medium.com/@maheshwar.ligade/de-obfuscate-stack-traces-6e19a52a3379
For all you copy-paste bros: