Skip to content

Commit

Permalink
UPDATED DEPENDENCIES
Browse files Browse the repository at this point in the history
  • Loading branch information
TutorialsAndroid committed May 22, 2020
1 parent 9c72429 commit 69f3131
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 137 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/android.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![](https://github.com/TutorialsAndroid/crashx/blob/master/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png)

# CrashX [![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21) [![Known Vulnerabilities](https://snyk.io/test/github/TutorialsAndroid/CrashX/badge.svg?targetFile=library%2Fbuild.gradle)](https://snyk.io/test/github/TutorialsAndroid/CrashX?targetFile=library%2Fbuild.gradle) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-CrashX-red.svg?style=flat-square)](https://android-arsenal.com/details/1/7581) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/TutorialsAndroid/crashx)
# CrashX [![API](https://img.shields.io/badge/API-15%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=15) [![Known Vulnerabilities](https://snyk.io/test/github/TutorialsAndroid/CrashX/badge.svg?targetFile=library%2Fbuild.gradle)](https://snyk.io/test/github/TutorialsAndroid/CrashX?targetFile=library%2Fbuild.gradle) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-CrashX-red.svg?style=flat-square)](https://android-arsenal.com/details/1/7581) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/TutorialsAndroid/crashx)

This library allows launching a crash activity when the app crashes, instead of showing the hated "Unfortunately, X has stopped" dialog.

Expand Down Expand Up @@ -32,7 +32,7 @@ Add it in your root build.gradle at the end of repositories:
Step 2. Add the dependency

dependencies {
implementation 'com.github.TutorialsAndroid:crashx:v4.0.19'
implementation 'com.github.TutorialsAndroid:crashx:v5.0.19'
}

...and you are done!
Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
Expand All @@ -13,6 +13,10 @@ allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven {
url 'https://jitpack.io'
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Nov 13 17:16:27 CET 2017
#Sat Jan 20 01:13:22 IRST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
20 changes: 12 additions & 8 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,31 @@ android {
resourcePrefix 'crash_'

defaultConfig {
minSdkVersion 21
minSdkVersion 15
targetSdkVersion 29
versionCode 7
versionName "4.0.19"
versionCode 8
versionName "5.0.19"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

//ANDROID SUPPORT LIBRARIES
implementation 'androidx.appcompat:appcompat:1.0.2'
//ANDROIDX JETPACK LIBRARIES
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.preference:preference:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
119 changes: 58 additions & 61 deletions library/src/main/java/com/developer/crashx/CrashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.developer.crashx.config.CrashConfig;

/**
* @author akshay sunil masram
* @author tkdco , TutorialsAndroid
*/
public final class CrashActivity {

Expand Down Expand Up @@ -81,81 +81,78 @@ public static void install(@Nullable final Context context) {

application = (Application) context.getApplicationContext();

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, final Throwable throwable) {
if (config.isEnabled()) {
Log.e(TAG, "App has crashed, executing CrashActivity's UncaughtExceptionHandler", throwable);
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
if (config.isEnabled()) {
Log.e(TAG, "App has crashed, executing CrashActivity's UncaughtExceptionHandler", throwable);

if (hasCrashedInTheLastSeconds(application)) {
Log.e(TAG, "App already crashed recently, not starting custom error activity because we could enter a restart loop. Are you sure that your app does not crash directly on init?", throwable);
if (oldHandler != null) {
oldHandler.uncaughtException(thread, throwable);
return;
}
} else {
setLastCrashTimestamp(application, new Date().getTime());

Class<? extends Activity> errorActivityClass = config.getErrorActivityClass();

if (errorActivityClass == null) {
errorActivityClass = guessErrorActivityClass(application);
}

if (hasCrashedInTheLastSeconds(application)) {
Log.e(TAG, "App already crashed recently, not starting custom error activity because we could enter a restart loop. Are you sure that your app does not crash directly on init?", throwable);
if (isStackTraceLikelyConflictive(throwable, errorActivityClass)) {
Log.e(TAG, "Your application class or your error activity have crashed, the custom activity will not be launched!");
if (oldHandler != null) {
oldHandler.uncaughtException(thread, throwable);
return;
}
} else {
setLastCrashTimestamp(application, new Date().getTime());
} else if (config.getBackgroundMode() == CrashConfig.BACKGROUND_MODE_SHOW_CUSTOM || !isInBackground) {

Class<? extends Activity> errorActivityClass = config.getErrorActivityClass();
final Intent intent = new Intent(application, errorActivityClass);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
String stackTraceString = sw.toString();

if (errorActivityClass == null) {
errorActivityClass = guessErrorActivityClass(application);
if (stackTraceString.length() > MAX_STACK_TRACE_SIZE) {
String disclaimer = " [stack trace too large]";
stackTraceString = stackTraceString.substring(0, MAX_STACK_TRACE_SIZE - disclaimer.length()) + disclaimer;
}
intent.putExtra(EXTRA_STACK_TRACE, stackTraceString);

if (isStackTraceLikelyConflictive(throwable, errorActivityClass)) {
Log.e(TAG, "Your application class or your error activity have crashed, the custom activity will not be launched!");
if (oldHandler != null) {
oldHandler.uncaughtException(thread, throwable);
return;
}
} else if (config.getBackgroundMode() == CrashConfig.BACKGROUND_MODE_SHOW_CUSTOM || !isInBackground) {

final Intent intent = new Intent(application, errorActivityClass);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
String stackTraceString = sw.toString();

if (stackTraceString.length() > MAX_STACK_TRACE_SIZE) {
String disclaimer = " [stack trace too large]";
stackTraceString = stackTraceString.substring(0, MAX_STACK_TRACE_SIZE - disclaimer.length()) + disclaimer;
}
intent.putExtra(EXTRA_STACK_TRACE, stackTraceString);

if (config.isTrackActivities()) {
StringBuilder activityLogStringBuilder = new StringBuilder();
while (!activityLog.isEmpty()) {
activityLogStringBuilder.append(activityLog.poll());
}
intent.putExtra(EXTRA_ACTIVITY_LOG, activityLogStringBuilder.toString());
if (config.isTrackActivities()) {
StringBuilder activityLogStringBuilder = new StringBuilder();
while (!activityLog.isEmpty()) {
activityLogStringBuilder.append(activityLog.poll());
}
intent.putExtra(EXTRA_ACTIVITY_LOG, activityLogStringBuilder.toString());
}

if (config.isShowRestartButton() && config.getRestartActivityClass() == null) {
config.setRestartActivityClass(guessRestartActivityClass(application));
}
if (config.isShowRestartButton() && config.getRestartActivityClass() == null) {
config.setRestartActivityClass(guessRestartActivityClass(application));
}

intent.putExtra(EXTRA_CONFIG, config);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
if (config.getEventListener() != null) {
config.getEventListener().onLaunchErrorActivity();
}
application.startActivity(intent);
} else if (config.getBackgroundMode() == CrashConfig.BACKGROUND_MODE_CRASH) {
if (oldHandler != null) {
oldHandler.uncaughtException(thread, throwable);
return;
}
intent.putExtra(EXTRA_CONFIG, config);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
if (config.getEventListener() != null) {
config.getEventListener().onLaunchErrorActivity();
}
application.startActivity(intent);
} else if (config.getBackgroundMode() == CrashConfig.BACKGROUND_MODE_CRASH) {
if (oldHandler != null) {
oldHandler.uncaughtException(thread, throwable);
return;
}
}
final Activity lastActivity = lastActivityCreated.get();
if (lastActivity != null) {
lastActivity.finish();
lastActivityCreated.clear();
}
killCurrentProcess();
} else if (oldHandler != null) {
oldHandler.uncaughtException(thread, throwable);
}
final Activity lastActivity = lastActivityCreated.get();
if (lastActivity != null) {
lastActivity.finish();
lastActivityCreated.clear();
}
killCurrentProcess();
} else if (oldHandler != null) {
oldHandler.uncaughtException(thread, throwable);
}
});
application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Bundle;
Expand All @@ -25,7 +24,7 @@
import com.developer.crashx.config.CrashConfig;

/**
* @author akshay sunil masram
* @author tkdco , TutorialsAndroid
*/
public final class DefaultErrorActivity extends AppCompatActivity {

Expand Down Expand Up @@ -60,43 +59,25 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

if (config.isShowRestartButton() && config.getRestartActivityClass() != null) {
restartButton.setText(R.string.customactivityoncrash_error_activity_restart_app);
restartButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CrashActivity.restartApplication(DefaultErrorActivity.this, config);
}
});
restartButton.setOnClickListener(v -> CrashActivity.restartApplication(DefaultErrorActivity.this, config));
} else {
restartButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CrashActivity.closeApplication(DefaultErrorActivity.this, config);
}
});
restartButton.setOnClickListener(v -> CrashActivity.closeApplication(DefaultErrorActivity.this, config));
}

Button moreInfoButton = findViewById(R.id.crash_error_activity_more_info_button);

if (config.isShowErrorDetails()) {
moreInfoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog dialog = new AlertDialog.Builder(DefaultErrorActivity.this)
.setTitle(R.string.customactivityoncrash_error_activity_error_details_title)
.setMessage(CrashActivity.getAllErrorDetailsFromIntent(DefaultErrorActivity.this, getIntent()))
.setPositiveButton(R.string.customactivityoncrash_error_activity_error_details_close, null)
.setNeutralButton(R.string.customactivityoncrash_error_activity_error_details_copy,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
copyErrorToClipboard();
}
})
.show();
TextView textView = dialog.findViewById(android.R.id.message);
if (textView != null) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.customactivityoncrash_error_activity_error_details_text_size));
}
moreInfoButton.setOnClickListener(v -> {
AlertDialog dialog = new AlertDialog.Builder(DefaultErrorActivity.this)
.setTitle(R.string.customactivityoncrash_error_activity_error_details_title)
.setMessage(CrashActivity.getAllErrorDetailsFromIntent(DefaultErrorActivity.this, getIntent()))
.setPositiveButton(R.string.customactivityoncrash_error_activity_error_details_close, null)
.setNeutralButton(R.string.customactivityoncrash_error_activity_error_details_copy,
(dialog1, which) -> copyErrorToClipboard())
.show();
TextView textView = dialog.findViewById(android.R.id.message);
if (textView != null) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.customactivityoncrash_error_activity_error_details_text_size));
}
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
import com.developer.crashx.CrashActivity;

/**
* @author akshay sunil masram
* @author tkdco , TutorialsAndroid
*/
public class CrashConfig implements Serializable {

@IntDef({BACKGROUND_MODE_CRASH, BACKGROUND_MODE_SHOW_CUSTOM, BACKGROUND_MODE_SILENT})
@Retention(RetentionPolicy.SOURCE)
private @interface BackgroundMode {
//I hate empty blocks
}
private @interface BackgroundMode { }

static final int BACKGROUND_MODE_SILENT = 0;
public static final int BACKGROUND_MODE_SHOW_CUSTOM = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.developer.crashx.CrashActivity;

/**
* @author akshay sunil masram
* @author tkdco , TutorialsAndroid
*/
public class CrashInitProvider extends ContentProvider {

Expand Down
Loading

0 comments on commit 69f3131

Please sign in to comment.