Simple PHP based server side component for ACRA (crash reporting library for Android apps) which forwards all incoming crash reports to a defined mail address. The stack trace is additionally attached as an TXT file to allow easier retracing of ProGuard obfuscated source code.
- A web server with PHP support
- ACRA added to your Android app
- Edit the configuration at the top of the
acra.php
file. Set appropriate mail addresses there.
// Configuration
$to = '[email protected]';
$from = '[email protected]';
- Upload the
acra.php
file to your PHP supporting web server.
To prevent unauthorized access to the acra.php
file you should password protect it, e.g. by using a .htaccess
file if supported by your web server.
- Edit the
.htpasswd
file and replace the username/password combination with your secret credentials. The username/password combination can be generated e.g. on this website. You can also re-use an existing.htpasswd
file if available. - Upload the
.htpasswd
file to your web server.
WARNING: For security reasons you should never upload a
.htpasswd
file to a folder accessible from the Internet!
- Edit the
.htaccess
file and set the correct path to the.htpasswd
file above.
AuthUserFile /path/to/your/.htpasswd
- Upload the
.htaccess
file to the same folder as theacra.php
file.
The full documentation of ACRA is available on www.acra.ch, the following section is just a quick start to use ACRA together with the ACRA PHP Mailer.
- Add ACRA as dependency to your app module Gradle file:
dependencies {
... your other dependencies...
compile "ch.acra:acra:4.7.0"
}
- Create or update an Application subclass and add ACRA to it:
@ReportsCrashes(
formUri = "http://www.your.url/acra.php",
formUriBasicAuthLogin = "your username", // optional
formUriBasicAuthPassword = "your password", // optional
reportType = org.acra.sender.HttpSender.Type.JSON,
sendReportsAtShutdown = false
)
public class MyApplication extends Application {
@Override
public void onCreate() {
ACRA.init(this);
super.onCreate();
}
}
- Reference the new Application class in your Android Manifest:
<application
android:name=".MyApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
[...]
- Obviously, your app will need the INTERNET permission:
<uses-permission android:name="android.permission.INTERNET"/>
- Update your ProGuard file to keep ACRA classes, all details can be found here:
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keep class org.acra.** { *; }
- Done, from now on you should receive a mail every time your app crashes!