ProGuard的ReTrace / Crashlytics不能正确消除混淆错误

时间:2019-01-14 15:57:07

标签: android nullpointerexception proguard deobfuscation crashlytics-android

我们对Crashlytics进行正确的混淆处理存在问题,但我们怀疑这可能是Proguard将Map类的堆栈跟踪信息与我们的映射文件正确翻译的问题。

我们使用MainActivity准备了小型应用程序:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    somemethod();
}

private void somemethod() {
    Model1 model1 = new Model1();
    model1.getModelButReturnNull().something();
}

}

和Model1类:

public class Model1 {
int sum = 0;  

public Model1 getModelButReturnNull() {
    System.out.println("getModelButReturnNull");
    return null;
}

public void something() {
    for (int i = 0; i < 100; i++) {
        sum = sum + i;
    }
}

}

问题是,当我们尝试对Crashlytics的发行版中的堆栈跟踪进行模糊处理或使用proguard的ReTrace时,会得到

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{deobfuscation.test.crashlytics/deobfuscation.test.crashlytics.MainActivity}: java.lang.NullPointerException: Attempt to read from field 'int deobfuscation.test.crashlytics.c.a' on a null object reference
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2951)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
   at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
   at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
   at android.os.Handler.dispatchMessage(Handler.java:106)
   at android.os.Looper.loop(Looper.java:193)
   at android.app.ActivityThread.main(ActivityThread.java:6718)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Caused by java.lang.NullPointerException: Attempt to read from field 'int deobfuscation.test.crashlytics.c.a' on a null object reference
       at deobfuscation.test.crashlytics.MainActivity.deobfuscation.test.crashlytics.Model1.something(MainActivity.java:2013)
       at android.app.Activity.performCreate(Activity.java:7144)
       at android.app.Activity.performCreate(Activity.java:7135)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:193)
       at android.app.ActivityThread.main(ActivityThread.java:6718)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

我们的proguard-rules.pro:

-keep class com.crashlytics.** { *; }
-keep class com.crashlytics.android.**
-keepattributes *Annotation*
-keepattributes  SourceFile, LineNumberTable
-keep public class * extends java.lang.Exception

-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }

这是完整项目的链接:https://ufile.io/99o9c

正如我们在映射文件中看到的,retrace / Crashlytics应该对行进行反模糊处理:deobfuscation.test.crashlytics.c

deobfuscation.test.crashlytics.Model1 -> deobfuscation.test.crashlytics.c:
    int sum -> a

但我们看到:

Caused by java.lang.NullPointerException: Attempt to read from field 'int deobfuscation.test.crashlytics.c.a' on a null object reference

0 个答案:

没有答案