¿Se puede utilizar ACRA en un proyecto de biblioteca?

ACRA se está estrellando con un problema extraño:

IllegalStateException: Cannot access ErrorReporter before ACRA#init

Tengo una aplicación con ACRA 4.3.0 que funciona perfectamente. Cambié la aplicación completa a una biblioteca, así que puedo hacer variantes menores. He creado un nuevo proyecto que está completamente en blanco, aparte de un manifiesto y enlaces a esta nueva biblioteca. Para cualquier otro intento esto, en AcraApplication.java usted tiene que quitar la línea "resToastText = R.string.crash_toast_text" y agregar una nueva línea debajo de Acra.init (this);

ACRA.getConfig().setResToastText(R.string.crash_toast_text);

El proyecto se desarrolla bien y en depuración he confirmado ACRA.init (this); Se ejecuta antes del código del programa principal y antes de que se produzca el error. En el programa principal, en el punto donde establecemos algunos datos personalizados:

ACRA.getErrorReporter().putCustomData("Orientation", "L");

Causa el bloqueo (o con mayor precisión, ACRA mismo provoca el error) y no se genera ningún informe ACRA.

¿Ideas qué probar a continuación o punteros dónde buscar? Puede ser ACRA es incompatible con las bibliotecas, que si este es el caso, puedo sacarlo de un manejar de manera diferente, pero una especie de derrota el propósito de la biblioteca.


Solución: En lugar de añadir la línea debajo de Acra.init(this); Agregue estas tres líneas antes de la línea de inicio:

 ACRAConfiguration config = ACRA.getNewDefaultConfig(this); config.setResToastText(R.string.crash_toast_text); ACRA.setConfig(config); ACRA.init(this); 

Tenga en cuenta que esto sólo funciona en v4.3.0 y posterior.

Tuve el mismo problema, fue causado por proguard obfuscation.

La solución es agregar las siguientes personalizaciones al archivo proguard.cfg (tomado de la página wiki de ACRA aquí ):

Tenga en cuenta que el ACRA.init () debe permanecer al principio:

 @Override public void onCreate() { ACRA.init(this); ACRA.getErrorReporter().setReportSender(new MySender()); super.onCreate(); } 

Proguard.cfg:

 #ACRA specifics # we need line numbers in our stack traces otherwise they are pretty useless -renamesourcefileattribute SourceFile -keepattributes SourceFile,LineNumberTable # ACRA needs "annotations" so add this... -keepattributes *Annotation* # keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'. # Note: if you are removing log messages elsewhere in this file then this isn't necessary -keep class org.acra.ACRA { *; } # keep this around for some enums that ACRA needs -keep class org.acra.ReportingInteractionMode { *; } -keepnames class org.acra.sender.HttpSender$** { *; } -keepnames class org.acra.ReportField { *; } # keep this otherwise it is removed by ProGuard -keep public class org.acra.ErrorReporter { public void addCustomData(java.lang.String,java.lang.String); public void putCustomData(java.lang.String,java.lang.String); public void removeCustomData(java.lang.String); } # keep this otherwise it is removed by ProGuard -keep public class org.acra.ErrorReporter { public void handleSilentException(java.lang.Throwable); } 

Asegúrese de que ha agregado en el archivo de manifiesto

 <application android:name="com.test.MyApp" 

Y tienes una clase de aplicación que hace lo siguiente

 import org.acra.ACRA; import org.acra.ReportField; import org.acra.ReportingInteractionMode; import org.acra.annotation.ReportsCrashes; import android.app.Application; @ReportsCrashes(formKey = "", mailTo = "your_email_address", customReportContent = { ReportField.APP_VERSION_CODE, ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL, ReportField.CUSTOM_DATA, ReportField.STACK_TRACE, ReportField.LOGCAT }, mode = ReportingInteractionMode.TOAST, resToastText = R.string.crash_toast_text) public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); ACRA.init(this); } } 

En mi caso me faltaba @ReportCrashes config … Espero que esto funcione

 @ReportsCrashes( formUri = "uploadurl", reportType = HttpSender.Type.JSON, httpMethod = HttpSender.Method.POST, formUriBasicAuthLogin = "llenigingeneyederrownlys", formUriBasicAuthPassword = "1a35b13f9f54271d23a9aed988451182e5b97211", formKey = "", // This is required for backward compatibility but not used customReportContent = { ReportField.APP_VERSION_CODE, ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.PACKAGE_NAME, ReportField.REPORT_ID, ReportField.BUILD, ReportField.STACK_TRACE }, mode = ReportingInteractionMode.TOAST, resToastText =R.string.msg ) 
FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.