簡體   English   中英

使用ProGuard會導致ACRA的NoSuchFieldError

[英]Using ProGuard causes NoSuchFieldError for ACRA

我在我的Android應用程序中使用ACRA 4.4.0來接收用戶的崩潰報告。 我的IDE是ADT Build:v22.2.1-833290。 幾天前,我開始將ProGuard用於我要在Google Play上發布的應用。 當我安裝並啟動導出的簽名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)效果很好。 有沒有辦法解決這個問題? 提前致謝。 邁克爾。

你可以嘗試使用它的doc來配置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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM