9

Android アプリで ACRA 4.4.0 を使用して、ユーザーからクラッシュ レポートを受け取ります。私の IDE は ADT Build: v22.2.1-833290 です。数日前、Google Play で公開する予定のアプリに ProGuard の使用を開始しました。エクスポートされた署名付き apk をインストールして開始すると、ACRA レポートで使用されるフィールドで NoSuchFieldError が発生します。私のコードは次のとおりです。

@ReportsCrashes(formKey = <my_key>,
                mailTo = <my_email>,
                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 MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ACRA.init(this);
    }
}

proguard-project.txt に「-keep public class org.acra.*」を含めても効果はありません。GoogleDocs でわかるように、考えられる理由は、Proguard が動的に参照されるフィールドとメソッドで正しく機能しないことです。最適化された APK (ACRA なし) はうまく機能します。この問題を解決する方法はありますか? 前もって感謝します。マイケル。

4

1 に答える 1

11

こちらのドキュメントを使用して ACRA の構成を試すことができます: https://github.com/ACRA/acra/wiki/Proguardこれを proguard 構成ファイルに含めます。

#ACRA specifics
# Restore some Source file names and restore approximate line numbers in the stack traces,
# otherwise the stack traces are pretty useless
-keepattributes SourceFile,LineNumberTable

# ACRA needs "annotations" so add this... 
# Note: This may already be defined in the default "proguard-android-optimize.txt"
# file in the SDK. If it is, then you don't need to duplicate it. See your
# "project.properties" file to get the path to the default "proguard-android-optimize.txt".
-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);
}
于 2014-04-28T12:48:38.597 に答える