Skip to content

Commit

Permalink
add XCrash
Browse files Browse the repository at this point in the history
Signed-off-by: HaleyDu <[email protected]>
  • Loading branch information
Haleydu committed Apr 25, 2021
1 parent 911ca11 commit 01af692
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ dependencies {
implementation 'com.google.firebase:firebase-ads:19.5.0'
implementation 'com.king.app:app-updater:1.0.8-androidx'
implementation 'com.king.app:app-dialog:1.0.8-androidx'
implementation 'com.iqiyi.xcrash:xcrash-android-lib:3.0.0'

}
repositories {
mavenCentral()
Expand Down
19 changes: 18 additions & 1 deletion app/src/main/java/com/hiroshi/cimoc/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;

import androidx.multidex.MultiDex;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Environment;
import android.util.DisplayMetrics;
import android.view.WindowManager;

Expand Down Expand Up @@ -41,6 +44,8 @@
import javax.net.ssl.X509TrustManager;

import okhttp3.OkHttpClient;
import xcrash.XCrash;

import androidx.multidex.MultiDexApplication;

/**
Expand Down Expand Up @@ -71,10 +76,12 @@ public class App extends MultiDexApplication implements AppGetter, Thread.Uncaug

// 默认Github源
private static String UPDATE_CURRENT_URL = "https://api.github.com/repos/Haleydu/Cimoc/releases/latest";
private static final String CRASH_FILE_PATH = "/Cimoc/Log/crash";

@Override
public void onCreate() {
super.onCreate();
initXCrash();
Thread.setDefaultUncaughtExceptionHandler(this);
mActivityLifecycle = new ActivityLifecycle();
registerActivityLifecycleCallbacks(mActivityLifecycle);
Expand Down Expand Up @@ -291,5 +298,15 @@ private static SSLSocketFactory createSSLSocketFactory() {
return ssfFactory;
}


private void initXCrash(){
//异常捕捉框架,xcrash的native捕捉会导致系统死机,将之去掉不使用20200817
XCrash.InitParameters initParameters = new XCrash.InitParameters();
//不处理native层的崩溃异常
initParameters.setLogDir(Environment.getExternalStorageDirectory().getAbsolutePath()+CRASH_FILE_PATH);
initParameters.disableNativeCrashHandler();
//java崩溃异常文件的最大数量
initParameters.setJavaLogCountMax(200);
initParameters.setJavaDumpAllThreadsCountMax(25);
XCrash.init(this, initParameters);
}
}

0 comments on commit 01af692

Please sign in to comment.