具有自定义ReportSender的ACRA 5.1.3不会发送CrashReportData

时间:2019-02-04 17:14:59

标签: android mobile acra

我正在尝试使用自定义报告发送器在Android客户端上实现ACRA库,但无法使它发送实际的错误日志。 这是我的代码:

def acraVersion = '5.1.3'    

dependencies {

    implementation "ch.acra:acra-core:$acraVersion"
    implementation "ch.acra:acra-http:$acraVersion"
    implementation "ch.acra:acra-toast:$acraVersion"
}

我的自定义报告发送者类:

public class MyCrashReportSender implements ReportSender {


    public MyCrashReportSender(Context context) {

    }


    @Override
    public void send(@NonNull Context context, @NonNull CrashReportData errorContent) {
        Timber.e("============== Crash report "+ errorContent.toString());
    }

    public static class MyCrashReportSenderFactory implements ReportSenderFactory {

        @NonNull
        @Override
        public ReportSender create(@NonNull Context context, @NonNull CoreConfiguration config) {
            return new MyCrashReportSender(context);
        }

        @Override
        public boolean enabled(@NonNull CoreConfiguration config) {
            return true;
        }
    }
}

最后是我的Application.class,我在其中初始化lib

@AcraCore(buildConfigClass = BuildConfig.class,
        reportSenderFactoryClasses = MyCrashReportSender.MyCrashReportSenderFactory.class,
        reportFormat=StringFormat.JSON)
public class App extends Application {
...
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        CoreConfigurationBuilder builder = new CoreConfigurationBuilder(this);
        builder.setBuildConfigClass(BuildConfig.class).setReportFormat(StringFormat.JSON);
        builder.getPluginConfigurationBuilder(ToastConfigurationBuilder.class).setText("This better work");
        ACRA.init(this, builder);
    }
}

当我在设备上运行客户端时,会从ACRA获取此日志:

02-04 16:48:29.900 17609-17609/com.mypackageName.client I/ACRA: ACRA is enabled for com.mypackageName, initializing...

当发生异常时,ACRA会捕获错误日志:

02-04 17:09:33.261 17609-17609/com.mypackageName E/ACRA: ACRA caught a NullPointerException for com.mypackageName
    java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference

问题在于此方法从未被调用:

@Override
public void send(@NonNull Context context, @NonNull CrashReportData errorContent) {
    Timber.e("============== Crash report "+ errorContent.toString());
}

有人知道为什么吗?

提前谢谢!

0 个答案:

没有答案