ProGuard和UncaughtExceptionHandler

时间:2016-01-07 17:07:00

标签: java android proguard android-proguard

我尝试将ProGuard与我自己的UncaughtExceptionHandler类一起使用。没有ProGuard,一切都运行良好。但是如果我启用它,则永远不会调用函数uncaughtException。

public class MyBug implements UncaughtExceptionHandler
{
    private UncaughtExceptionHandler defaultUEH;

    public ASBug() {
        alert("init");
        defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
    }

    public void addHandlerToThread(Thread t) {
        alert("set");
        t.setUncaughtExceptionHandler(this);
    }

    @Override
    public void uncaughtException(Thread t, Throwable e)
    {
        alert("catch");
    }


    static void alert(final String message) {

        ***.context().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                AlertDialog.Builder bld = new  AlertDialog.Builder(***.context());
                bld.setMessage(message);
                bld.setNeutralButton("OK", null);
                bld.create().show();
            }
        });
    }
}

proguard的-rules.txt

-keepclasseswithmembers public class com.asgardsoft.core.ASBug

1 个答案:

答案 0 :(得分:0)

明确要求proguard保留班级

-keepclass your.package.name.UncaughtExceptionHandler