2012-10-21 37 views
7

ACRA chính nó là đâm với một vấn đề lẻ:ACRA có thể được sử dụng trong một dự án thư viện không?

IllegalStateException: Cannot access ErrorReporter before ACRA#init

Tôi có một ứng dụng với ACRA 4.3.0 mà làm việc một cách hoàn hảo. Tôi đã thay đổi toàn bộ ứng dụng thành một thư viện, vì vậy tôi có thể tạo ra các biến thể nhỏ. Tôi đã tạo một dự án mới hoàn toàn trống không phải là tệp kê khai và liên kết đến thư viện mới này. Đối với bất kỳ ai khác cố gắng điều này, trong AcraApplication.java bạn phải loại bỏ dòng "resToastText = R.string.crash_toast_text" và thêm một dòng mới bên dưới Acra.init (điều này);

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

Dự án xây dựng tốt và trong debug Tôi đã xác nhận ACRA.init (this); được chạy trước mã chương trình chính của tôi và trước khi xảy ra lỗi. Trong chương trình chính, tại điểm mà chúng tôi thiết lập một số dữ liệu tùy chỉnh:

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

Nó gây ra sự sụp đổ (hay chính xác hơn, ACRA bản thân gây ra lỗi) và không có báo cáo ACRA được tạo ra.

Bất kỳ ý tưởng nào cần thử tiếp theo hoặc con trỏ ở đâu để tìm? Nó có thể là ACRA không tương thích với các thư viện, mà nếu đây là trường hợp, tôi có thể kéo nó ra một xử lý nó một cách khác nhau, nhưng loại thất bại mục đích của thư viện.


Giải pháp: Thay vì thêm dòng dưới đây Acra.init(this); thêm ba dòng trước dòng init:

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

ACRA.init(this); 

Chú giải này chỉ hoạt động trong v4.3.0 và sau đó.

Trả lời

1

Tôi gặp vấn đề tương tự, nguyên nhân là do sự che khuất của proguard.

Giải pháp là để thêm các tùy chỉnh dưới đây để proguard.cfg tập tin (lấy từ trang wiki ACRA here):

Lưu ý rằng ACRA.init() nên ở phần đầu:

@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); 
} 
+0

Hi, ngay cả với những dòng trong proguard.cfg của tôi, tôi vẫn nhận được một "NoSuchFieldError: SILENT" trong bản phát hành của mình. Tôi không thể hình dung ra – Arnaud

1

Hãy chắc chắn rằng bạn đã thêm trong file manifest

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

và bạn có lớp ứng dụng mà sau

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); 
     } 
    } 
1

Trong trường hợp của tôi, tôi đã mất tích @ReportCrashes cấu hình ... Hy vọng điều này sẽ làm việc

@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 

) 
Các vấn đề liên quan