Hon*_*ong 7 android-studio android-proguard android-studio-3.4
自动生成的 proguard-rules.pro 具有以下内容:
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
Run Code Online (Sandbox Code Playgroud)
多年来,我一直对此进行评论,直到 Android Studio 3.4默认使用R8而不是 ProGuard ,它才能完美运行。
让我们使用以下示例:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
at net.foo.anroid.Foo.wb.d(SourceFile:453)
at net.foo.anroid.Foo.wb.a(SourceFile:213)
at net.foo.anroid.Foo.wb.n(SourceFile:103)
at net.foo.anroid.Foo.qa.run(Unknown Source:2)
at java.lang.Thread.run(Thread.java:764)
Run Code Online (Sandbox Code Playgroud)
当使用 ProGuard 时,行号(例如 453、213...)曾经是 Java 代码源文件中的实际行号,但它们不再是 R8。即使使用官方推荐的反混淆工具ReTrace也无法恢复原始行号。
“-keepattributes SourceFile,LineNumberTable”究竟是做什么的?
小智 0
当您使用 R8 混淆代码时,会发生的情况是名称被替换为较小的名称,如 a、b、1 等。由此产生的影响是类中的代码行数将会减少,因为字符数量较少。
现在,如果您看到堆栈跟踪,它将与修改后的代码无关。因为行号会改变。使用上面的 -keepattributes,它可以确保您在堆栈跟踪中获得正确的行号。
请参阅文档说需要 LineNumberTable 属性来消除方法内优化位置之间的歧义。
| 归档时间: |
|
| 查看次数: |
392 次 |
| 最近记录: |