文章目录
- 一、将混淆后的报错信息转为原始报错信息
- 二、retrace.bat 命令执行目录
- 三、暴露更少信息
更多 ProGuard 混淆配置参考 : https://www.guardsquare.com/en/products/proguard/manual/usage
一、将混淆后的报错信息转为原始报错信息
前提 : proguard-rules.pro 混淆配置中配置保留行数 ;
代码语言:javascript复制# 保留行数
-keepattributes SourceFile,LineNumberTable
混淆后的报错信息 :
代码语言:javascript复制2020-11-10 12:01:59.426 28142-28142/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: kim.hsl.handler, PID: 28142
java.lang.RuntimeException: Unable to start activity ComponentInfo{kim.hsl.handler/kim.hsl.handler.MainActivity}: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3897)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8349)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
at b.a.a.a.<init>(Handler.java:30)
at kim.hsl.handler.MainActivity.onCreate(MainActivity.kt:24)
at android.app.Activity.performCreate(Activity.java:8085)
at android.app.Activity.performCreate(Activity.java:8073)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3870)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8349)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
将上述混淆后的报错信息 , 保存到 bug.txt 文件中 , 放在 appbuildoutputsmappingdebug 目录里 ;
在 Sdktoolsproguardbin 中找到 retrace.bat 工具 ;
使用上述 retrace.bat 命令 , 通过 Proguard 混淆映射文件 mapping.txt , 还原被混淆过的 报错信息 ;
进入 D: 01_Programs 01_Android 02_SdkSdktoolsproguardlib 目录 , 然后在该目录执行上述命令 ;
代码语言:javascript复制D: 01_Programs 01_Android 02_SdkSdktoolsproguardbinretrace.bat -verbose D: 02_Project 02_Android_LearnHandlerappbuildoutputsmappingdebugmapping.txt D: 02_Project 02_Android_LearnHandlerappbuildoutputsmappingdebugbug.txt
一定要注意 , 必须在 D: 01_Programs 01_Android 02_SdkSdktoolsproguardlib 目录中执行该命令 ;
还原结果 :
代码语言:javascript复制D: 01_Programs 01_Android 02_SdkSdktoolsproguardlib>D: 01_Programs 01_Android 02_SdkSdktoolsproguardbinretrace.bat -verbose D: 02_Project 02_Android_LearnHandlerappbuildoutputsmappingdebugmapping.txt D: 02_Project 02_Android_LearnHandlerappbuildoutputsmappingdebugbug.txt
2020-11-10 12:01:59.426 28142-28142/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: kim.hsl.handler, PID: 28142
java.lang.RuntimeException: Unable to start activity ComponentInfo{kim.hsl.handler/kim.hsl.handler.MainActivity}: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3897)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8349)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
at kim.hsl.handler.Handler.void <init>()(Handler.java:30)
at kim.hsl.handler.MainActivity.void onCreate(android.os.Bundle)(MainActivity.kt:24)
at android.app.Activity.performCreate(Activity.java:8085)
at android.app.Activity.performCreate(Activity.java:8073)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3870)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076)聽
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)聽
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)聽
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)聽
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)聽
at android.os.Handler.dispatchMessage(Handler.java:110)聽
at android.os.Looper.loop(Looper.java:219)聽
at android.app.ActivityThread.main(ActivityThread.java:8349)聽
at java.lang.reflect.Method.invoke(Native Method)聽
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)聽
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)聽
D: 01_Programs 01_Android 02_SdkSdktoolsproguardlib>
二、retrace.bat 命令执行目录
必须在 D: 01_Programs 01_Android 02_SdkSdktoolsproguardlib 目录中执行 retrace.bat 命令 , 如果在别的目录会报下面的错误 ;
代码语言:javascript复制Error: Unable to access jarfile ..libretrace.jar
三、暴露更少信息
使用以下配置 , 可以暴露更少信息 ;
代码语言:javascript复制-renamesourcefileattribute H
完整配置如下 :
代码语言:javascript复制# 保留行数
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute H
报错信息如下 :
代码语言:javascript复制2020-11-10 12:15:41.634 29988-29988/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: kim.hsl.handler, PID: 29988
java.lang.RuntimeException: Unable to start activity ComponentInfo{kim.hsl.handler/kim.hsl.handler.MainActivity}: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3897)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8349)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
at b.a.a.a.<init>(H:30)
at kim.hsl.handler.MainActivity.onCreate(H:24)
at android.app.Activity.performCreate(Activity.java:8085)
at android.app.Activity.performCreate(Activity.java:8073)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3870)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8349)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
使用 -renamesourcefileattribute H 配置 前后对比对比 :
之前报错时 , 会将 Handler 暴露出来 ;
代码语言:javascript复制 Caused by: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
at b.a.a.a.<init>(Handler.java:30)
at kim.hsl.handler.MainActivity.onCreate(MainActivity.kt:24)
使用 -renamesourcefileattribute H 配置后 , 报错信息如下 :
代码语言:javascript复制 Caused by: java.lang.NullPointerException: Attempt to read from field 'b.a.a.d b.a.a.b.a' on a null object reference
at b.a.a.a.<init>(H:30)
at kim.hsl.handler.MainActivity.onCreate(H:24)