diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39fb081 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..5d6f65c --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml new file mode 100644 index 0000000..9dd7106 --- /dev/null +++ b/.idea/markdown-navigator.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml new file mode 100644 index 0000000..57927c5 --- /dev/null +++ b/.idea/markdown-navigator/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..aeca25b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + Android + + + Android > Lint > Correctness + + + Java + + + Java language level migration aidsJava + + + + + Android + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ffc370a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..23d2b30 --- /dev/null +++ b/README.md @@ -0,0 +1,84 @@ +# NeverCrash +[![Download](https://img.shields.io/badge/download-App-blue.svg)](https://raw.githubusercontent.com/jenly1314/NeverCrash/master/app/app-release.apk) +[![](https://jitpack.io/v/jenly1314/NeverCrash.svg)](https://jitpack.io/#jenly1314/NeverCrash) +[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/mit-license.php) +[![Blog](https://img.shields.io/badge/blog-Jenly-9933CC.svg)](http://blog.csdn.net/jenly121) + +NeverCrash for Android 一个全局捕获Crash的库。信NeverCrash,永不Crash,。 + +## Gif 展示 +![Image](GIF.gif) + +## 引入 + +### Maven: +``` + + com.king.thread + nevercrash + 1.0.0 + pom + +``` +### Gradle: +``` +compile 'com.king.thread:nevercrash:1.0.0' +``` +### Lvy: +``` + + + +``` + +## 示例 + +核心代码(大道至简) +```Java +NeverCrash.init(CrashHandler); +``` + +代码示例 +```Java +public class App extends Application { + + @Override + public void onCreate() { + super.onCreate(); + NeverCrash.init(new NeverCrash.CrashHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + Log.d("Jenly", Log.getStackTraceString(e)); +// e.printStackTrace(); + showToast(e.getMessage()); + + + } + }); + } + + private void showToast(final String text){ + + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + Toast.makeText(getApplicationContext(),text,Toast.LENGTH_SHORT).show(); + } + }); + } + +} +``` + +## 关于我 + Name: Jenly + + Email: jenly1314@gmail.com / jenly1314@vip.qq.com + + CSDN: http://www.csdn.net/jenly121 + + Github: https://github.com/jenly1314 + + 微信公众号: + + ![公众号](http://olambmg9j.bkt.clouddn.com/jenly666.jpg) \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app-release.apk b/app/app-release.apk new file mode 100644 index 0000000..984ef66 Binary files /dev/null and b/app/app-release.apk differ diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..e84f29d --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.2" + defaultConfig { + applicationId "com.king.nevercrash" + minSdkVersion 15 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:25.3.0' + compile 'com.android.support.constraint:constraint-layout:1.0.2' + testCompile 'junit:junit:4.12' + compile project(':lib') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..e0476cf --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in D:\Android\SDK/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/king/nevercrash/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/king/nevercrash/ExampleInstrumentedTest.java new file mode 100644 index 0000000..90eefe3 --- /dev/null +++ b/app/src/androidTest/java/com/king/nevercrash/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.king.nevercrash; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.king.nevercrash", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ce91e2d --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/king/nevercrash/App.java b/app/src/main/java/com/king/nevercrash/App.java new file mode 100644 index 0000000..373d69a --- /dev/null +++ b/app/src/main/java/com/king/nevercrash/App.java @@ -0,0 +1,43 @@ +package com.king.nevercrash; + +import android.app.Application; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; +import android.widget.Toast; + +import com.king.thread.nevercrash.NeverCrash; + +/** + * @author Jenly Jenly + * @since 2017/4/12 + */ + +public class App extends Application { + + @Override + public void onCreate() { + super.onCreate(); + NeverCrash.init(new NeverCrash.CrashHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + Log.d("Jenly", Log.getStackTraceString(e)); +// e.printStackTrace(); + showToast(e.getMessage()); + + + } + }); + } + + private void showToast(final String text){ + + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + Toast.makeText(getApplicationContext(),text,Toast.LENGTH_SHORT).show(); + } + }); + } + +} diff --git a/app/src/main/java/com/king/nevercrash/MainActivity.java b/app/src/main/java/com/king/nevercrash/MainActivity.java new file mode 100644 index 0000000..55ceb38 --- /dev/null +++ b/app/src/main/java/com/king/nevercrash/MainActivity.java @@ -0,0 +1,47 @@ +package com.king.nevercrash; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Toast; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } + + public void asyncThread(Runnable runnable){ + new Thread(runnable).start(); + } + + public void OnClick(View v){ + switch (v.getId()){ + case R.id.btn1: + Toast.makeText(this,"正常点击",Toast.LENGTH_SHORT).show(); + break; + case R.id.btn2: + throw new RuntimeException("RuntimeException"); + case R.id.btn3: + throw new Error("Error"); + case R.id.btn4: + asyncThread(new Runnable() { + @Override + public void run() { + throw new IllegalArgumentException("IllegalArgumentException"); + } + }); + break; + case R.id.btn5: + asyncThread(new Runnable() { + @Override + public void run() { + throw new RuntimeException("RuntimeException"); + } + }); + break; + } + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..b8dc52f --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,71 @@ + + + +