2012-10-21 16 views
7

ACRA自体が奇妙な問題をクラッシュさ:図書館プロジェクトでACRAを使用できますか?

IllegalStateException: Cannot access ErrorReporter before ACRA#init

私は完璧に動作ACRA 4.3.0でアプリを持っています。私はライブラリ全体にアプリを変更したので、私は小さなバリエーションを作ることができます。マニフェストとこの新しいライブラリへのリンク以外は全く空白の新しいプロジェクトを作成しました。 AcraApplication.javaでこれを試してみる人は、 "resToastText = R.string.crash_toast_text"行を削除し、Acra.init(これ)の下に新しい行を追加する必要があります。

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

プロジェクトは、罰金のビルドとデバッグに私はACRA.init(これを)確認しました。私の主なプログラムコードの前で、エラーが発生する前に実行されます。メインプログラムでは、我々はいくつかのカスタムデータを設定する時点で:

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

それはクラッシュの原因となる(またはより正確に、ACRA自体はエラーが発生)と全くACRAレポートが生成されません。

次に試してみるべきアイディアや見た目はどこですか? ACRAはライブラリと互換性がないかもしれません。もしそうであれば、別の方法でそれを取り出すことができますが、ライブラリの目的を捨てることができます。


ソリューション:

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

ACRA.init(this); 

(注)こののみv4.3.0で動作し、以降:代わりにAcra.init(this);以下の行を追加することのInit行する前にこれらの3行を追加します。

答えて

1

私は同じ問題を抱えていました。これは、プロガード難読化によって引き起こされました。

溶液(ACRAのwikiページhereから取られた)ファイルをproguard.cfgするには、以下のカスタマイズを追加することです:

注意ACRA.init()は最初にとどまるべきであること:

@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

こんにちは動作します私のproguard.cfgでは、私はまだ私のリリースで "NoSuchFieldError:SILENT"を取得します。私はそれを理解することはできません – Arnaud

1

は、マニフェストファイルに

が追加されていることを確認してください
<application 
    android:name="com.test.MyApp" 

、あなたは私が@ReportCrashesの設定がありませんでした私の場合は

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

を次の操作を行い、アプリケーションのクラスを持っている...希望は、このさえこれらの行で、

@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 

) 
関連する問題