项目作者: xuuhaoo

项目描述 :
Android runtime crash controller. defense java crash keep your application safety
高级语言: Java
项目地址: git://github.com/xuuhaoo/Android-DefenseCrash.git
创建时间: 2020-12-08T09:33:09Z
项目社区:https://github.com/xuuhaoo/Android-DefenseCrash

开源协议:

下载


Android Defense Crash


TonyStark

为了方便中国同学,提供了翻译文档如下:中文文档

What’s this

This’s a Crash Defense library in Android to help you catch the Java exceptions which you don’t expected.

Integration

  • Step 1 Find the build.gradle file in your project and add the code into it as follow.
  1. allprojects {
  2. repositories {
  3. //other mavens
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }
  • Step 2 Find the build.gradle file in the module that you want to integration
  1. dependencies {
  2. implementation 'com.github.xuuhaoo:Android-DefenseCrash:last.version’
  3. }

Attentions: last.versionis a substitute word, the real version will be found in

Use

  • Initialize should be more earlier in application create, we suggest you put the init code in Application attachBaseContext(base:Context)

    • Sample

      1. override fun attachBaseContext(base: Context) {
      2. super.attachBaseContext(base)
      3. DefenseCrash.initialize(this)
      4. ...
      5. }
  • Install Defense library after initialize.

    • Sample

      1. override fun attachBaseContext(base: Context) {
      2. super.attachBaseContext(base)
      3. DefenseCrash.initialize(this)
      4. DefenseCrash.install { thread, throwable, isSafeMode, isCrashInChoreographer ->
      5. //thread: The crash happened’s thread.
      6. //throwable: The Exception exactly is.
      7. //isSafeMode: If application is allready crashed and we saved it that is mean you are in safe mode,
      8. //that happens most of the time is your Main Looper is compromised by some errors and not going to normal,and we keep it runing that’s called safe mode.
      9. //isCrashInChoreographer: If crash happend in OnMeasure/OnLayout/OnDraw it will case screen blank or some view not draw successfully
      10. //If you got this true, we suggest you restart or finish the current Activity for good
      11. //You can throw some throwables here and if you do that, will case VM got this throwable and shutdown your process.
      12. //And you should do somting here such as:
      13. Log.i("Exceptionhandler",
      14. "thread:${thread.name} " +
      15. "exception:${throwable.message} " +
      16. "isCrashInChoreographer:$isCrashInChoreographer " +
      17. "isSafeMode:$isSafeMode")
      18. throwable.printStackTrace()
      19. FirebaseCrashlytics.getInstance().recordException(throwable);
      20. }
      21. }
  • Uninstall Defense library if you don’t need this.

    • Sample

      1. DefenseCrash.unInstall()