diff --git a/app/build.gradle b/app/build.gradle index 0b5f1cb500..9470c7c56c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -52,13 +52,12 @@ if (!isAndroidTestBuild()) { enableInDebug true weaveGroup { - leak_canary_crash_fix { - enable !isReleaseBuild - } - anr_fix { enable true } + crash_fix { + enable true + } } } } diff --git a/app/src/main/java/com/mogo/launcher/MogoApplication.java b/app/src/main/java/com/mogo/launcher/MogoApplication.java index 8f87eca0de..c0ce3cb4d2 100644 --- a/app/src/main/java/com/mogo/launcher/MogoApplication.java +++ b/app/src/main/java/com/mogo/launcher/MogoApplication.java @@ -1,29 +1 @@ -package com.mogo.launcher; - -import com.mogo.eagle.core.function.main.MainMoGoApplication; -import com.mogo.eagle.core.utilcode.mogo.logger.LogLevel; -import com.mogo.eagle.core.utilcode.mogo.logger.Logger; -import com.mogo.launcher.crash.CrashSystem; - -/** - * @author congtaowang - * @since 2019-12-18 - *
- * Launcher application - */ -public class MogoApplication extends MainMoGoApplication { - - @Override - protected void initCrashConfig() { - CrashSystem crashSystem = CrashSystem.getInstance(this); - crashSystem.init(); - //设置debug模式,日志不上传 - crashSystem.setDebug(BuildConfig.DEBUG); - } - - @Override - protected void initLogConfig() { - super.initLogConfig(); - Logger.init(BuildConfig.DEBUG ? LogLevel.DEBUG : LogLevel.OFF); - } -} +package com.mogo.launcher; import com.mogo.eagle.core.function.main.MainMoGoApplication; import com.mogo.eagle.core.utilcode.mogo.logger.LogLevel; import com.mogo.eagle.core.utilcode.mogo.logger.Logger; import com.mogo.launcher.crash.CrashSystem; /** * @author congtaowang * @since 2019-12-18 *
* Launcher application */ public class MogoApplication extends MainMoGoApplication { @Override protected void initCrashConfig() { CrashSystem crashSystem = CrashSystem.getInstance(this); crashSystem.init(); //设置debug模式,日志不上传 crashSystem.setDebug(BuildConfig.DEBUG); } @Override protected void initLogConfig() { super.initLogConfig(); Logger.init(BuildConfig.DEBUG ? LogLevel.DEBUG : LogLevel.OFF); } } \ No newline at end of file diff --git a/app/src/main/java/com/mogo/launcher/lancet/CrashFix.kt b/app/src/main/java/com/mogo/launcher/lancet/CrashFix.kt new file mode 100644 index 0000000000..09ae7d1c42 --- /dev/null +++ b/app/src/main/java/com/mogo/launcher/lancet/CrashFix.kt @@ -0,0 +1,32 @@ +package com.mogo.launcher.lancet + +import android.content.ComponentName +import android.content.Intent +import androidx.annotation.* +import com.knightboost.lancet.api.Origin +import com.knightboost.lancet.api.Scope.ALL +import com.knightboost.lancet.api.Scope.LEAF +import com.knightboost.lancet.api.annotations.* + +@Keep +@Weaver +@Group("crash_fix") +class CrashFix { + + /** + * 修正Android8.0及之后,后台启动Service引起的崩溃 + * java.lang.IllegalStateException: Not allowed to start service Intent { + * act=com.zhidao.cosupload.service.UPLOAD_ACTION cmp=com.mogo.launcher.f/com.zhidao.cosupload.service.UploadService }: app is in background uid UidRecord{6443b7b u0a404 LAST bg:+1m15s362ms idle change:idle procs:1 seq(0,0,0)} + */ + @Insert(mayCreateSuper = true) + @TargetClass("android.content.Context", scope = LEAF) + @TargetMethod(methodName = "startService") + fun fixStartServiceCrash(intent: Intent): ComponentName? { + return try { + Origin.call() as ComponentName? + } catch (t: Throwable) { + t.printStackTrace() + null + } + } +} \ No newline at end of file