Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up ACRA with email crash alerts #2107

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ android {
}

dependencies {

// AndroidX
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
Expand All @@ -108,6 +107,11 @@ dependencies {
implementation("com.jaredrummler:colorpicker:1.1.0")
implementation("net.lingala.zip4j:zip4j:2.11.5")

// Crash reporting
val acraVersion = "5.11.4"
implementation("ch.acra:acra-mail:$acraVersion")
implementation("ch.acra:acra-dialog:$acraVersion")

// SpotBugs
implementation("io.wcm.tooling.spotbugs:io.wcm.tooling.spotbugs.annotations:1.0.0")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

import androidx.appcompat.app.AppCompatDelegate;

import org.acra.ACRA;
import org.acra.config.CoreConfigurationBuilder;
import org.acra.config.DialogConfigurationBuilder;
import org.acra.config.MailSenderConfigurationBuilder;
import org.acra.data.StringFormat;

import protect.card_locker.preferences.Settings;

public class LoyaltyCardLockerApplication extends Application {
Expand All @@ -12,6 +18,26 @@ public class LoyaltyCardLockerApplication extends Application {
public void onCreate() {
super.onCreate();

// Initialize crash reporter
ACRA.init(this, new CoreConfigurationBuilder()
//core configuration:
.withBuildConfigClass(BuildConfig.class)
.withReportFormat(StringFormat.KEY_VALUE_LIST)
.withPluginConfigurations(
new DialogConfigurationBuilder()
.withText(String.format(getString(R.string.acra_catima_has_crashed), getString(R.string.app_name)))
.withCommentPrompt(getString(R.string.acra_explain_crash))
.withResTheme(R.style.AppTheme)
.build(),
new MailSenderConfigurationBuilder()
.withMailTo("[email protected]")
.withSubject(String.format(getString(R.string.acra_crash_email_subject), getString(R.string.app_name)))
.withReportAsFile(false)
.build()
)
);

// Set theme
Settings settings = new Settings(this);
AppCompatDelegate.setDefaultNightMode(settings.getTheme());
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,7 @@
<string name="exportCancelled">Export cancelled</string>
<string name="useFrontImage">Use front image</string>
<string name="useBackImage">Use back image</string>
<string name="acra_catima_has_crashed">We\'re sorry, but <xliff:g id="app_name">%s</xliff:g> has crashed. Please help us fix this issue by sending us an error report.</string>
<string name="acra_explain_crash">If possible, please add more details on what you were doing here:</string>
<string name="acra_crash_email_subject"><xliff:g id="app_name">%s</xliff:g> crash report</string>
</resources>