├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── GIF.gif ├── LICENSE ├── README.md ├── app ├── .gitignore ├── app-release.apk ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── king │ │ └── nevercrash │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── king │ │ │ └── nevercrash │ │ │ ├── App.java │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── king │ └── nevercrash │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── king │ │ └── thread │ │ └── nevercrash │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── king │ │ │ └── thread │ │ │ └── nevercrash │ │ │ └── NeverCrash.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── king │ └── thread │ └── nevercrash │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 34 | 35 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Android 39 | 40 | 41 | Android > Lint > Correctness 42 | 43 | 44 | Java 45 | 46 | 47 | Java language level migration aidsJava 48 | 49 | 50 | 51 | 52 | Android 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 74 | 75 | 76 | 77 | 78 | 1.8 79 | 80 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /GIF.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/NeverCrash/203ec7cc4448aa48051fa73ea5f0f3c4717c8035/GIF.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jenly 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NeverCrash 2 | 3 | [![JitPack](https://img.shields.io/jitpack/v/github/jenly1314/NeverCrash?logo=jitpack)](https://jitpack.io/#jenly1314/NeverCrash) 4 | [![Download](https://img.shields.io/badge/download-APK-brightgreen?logo=github)](https://raw.githubusercontent.com/jenly1314/NeverCrash/master/app/app-release.apk) 5 | [![API](https://img.shields.io/badge/API-15%2B-brightgreen?logo=android)](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) 6 | [![License](https://img.shields.io/github/license/jenly1314/NeverCrash?logo=open-source-initiative)](https://opensource.org/licenses/mit) 7 | 8 | 9 | NeverCrash for Android 一个用于App全局捕获Crash的库。信NeverCrash,永不Crash。 10 | 11 | ## 效果展示 12 | ![Image](GIF.gif) 13 | 14 | > 你也可以直接下载 [演示App](https://raw.githubusercontent.com/jenly1314/NeverCrash/master/app/app-release.apk) 体验效果 15 | > 16 | ## 引入 17 | 18 | ### Gradle: 19 | 20 | 1. 在Project的 **build.gradle** 或 **setting.gradle** 中添加远程仓库 21 | 22 | ```gradle 23 | repositories { 24 | //... 25 | mavenCentral() 26 | maven { url 'https://jitpack.io' } 27 | } 28 | ``` 29 | 30 | 2. 在Module的 **build.gradle** 中添加依赖项 31 | 32 | ```gradle 33 | implementation 'com.github.jenly1314:NeverCrash:1.0.0' 34 | ``` 35 | 36 | ## 使用 37 | 38 | ### 初始化 39 | 40 | 核心代码 (大道至简) 41 | ```Java 42 | NeverCrash.init(CrashHandler); 43 | ``` 44 | 45 | ### 完整代码示例 46 | 47 | 在Application的`onCreate`方法中进行初始化`NeverCrash`来全局捕获异常 48 | ```Java 49 | public class App extends Application { 50 | 51 | @Override 52 | public void onCreate() { 53 | super.onCreate(); 54 | NeverCrash.init(new NeverCrash.CrashHandler() { 55 | @Override 56 | public void uncaughtException(Thread t, Throwable e) { 57 | if(BuildConfig.debug) { 58 | Log.e("Jenly", Log.getStackTraceString(e)); 59 | } else { 60 | // TODO 上报异常 61 | } 62 | } 63 | }); 64 | } 65 | } 66 | ``` 67 | 68 | ## 相关推荐 69 | - [AppMonitor](https://github.com/jenly1314/AppMonitor) 可以轻松的监听App的前后台状态变化;Activity的活跃状态变化;设备的开关屏状态变化。 70 | 71 | --- 72 | 73 | ![footer](https://jenly1314.github.io/page/footer.svg) 74 | 75 | 76 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenly1314/NeverCrash/203ec7cc4448aa48051fa73ea5f0f3c4717c8035/app/app-release.apk -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.king.nevercrash" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.0' 28 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 29 | testCompile 'junit:junit:4.12' 30 | compile project(':lib') 31 | } 32 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Android\SDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/king/nevercrash/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.king.nevercrash; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.king.nevercrash", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/king/nevercrash/App.java: -------------------------------------------------------------------------------- 1 | package com.king.nevercrash; 2 | 3 | import android.app.Application; 4 | import android.os.Handler; 5 | import android.os.Looper; 6 | import android.util.Log; 7 | import android.widget.Toast; 8 | 9 | import com.king.thread.nevercrash.NeverCrash; 10 | 11 | /** 12 | * @author Jenly Jenly 13 | * @since 2017/4/12 14 | */ 15 | 16 | public class App extends Application { 17 | 18 | @Override 19 | public void onCreate() { 20 | super.onCreate(); 21 | NeverCrash.init(new NeverCrash.CrashHandler() { 22 | @Override 23 | public void uncaughtException(Thread t, Throwable e) { 24 | Log.d("Jenly", Log.getStackTraceString(e)); 25 | // e.printStackTrace(); 26 | showToast(e.getMessage()); 27 | 28 | 29 | } 30 | }); 31 | } 32 | 33 | private void showToast(final String text){ 34 | 35 | new Handler(Looper.getMainLooper()).post(new Runnable() { 36 | @Override 37 | public void run() { 38 | Toast.makeText(getApplicationContext(),text,Toast.LENGTH_SHORT).show(); 39 | } 40 | }); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/king/nevercrash/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.king.nevercrash; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | public class MainActivity extends AppCompatActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_main); 14 | } 15 | 16 | public void asyncThread(Runnable runnable){ 17 | new Thread(runnable).start(); 18 | } 19 | 20 | public void OnClick(View v){ 21 | switch (v.getId()){ 22 | case R.id.btn1: 23 | Toast.makeText(this,"正常点击",Toast.LENGTH_SHORT).show(); 24 | break; 25 | case R.id.btn2: 26 | throw new RuntimeException("RuntimeException"); 27 | case R.id.btn3: 28 | throw new Error("Error"); 29 | case R.id.btn4: 30 | asyncThread(new Runnable() { 31 | @Override 32 | public void run() { 33 | throw new IllegalArgumentException("IllegalArgumentException"); 34 | } 35 | }); 36 | break; 37 | case R.id.btn5: 38 | asyncThread(new Runnable() { 39 | @Override 40 | public void run() { 41 | throw new RuntimeException("RuntimeException"); 42 | } 43 | }); 44 | break; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |