[2.13.2]修正Android8.0及以后,后台开启Service引起的崩溃
This commit is contained in:
@@ -52,13 +52,12 @@ if (!isAndroidTestBuild()) {
|
||||
enableInDebug true
|
||||
|
||||
weaveGroup {
|
||||
leak_canary_crash_fix {
|
||||
enable !isReleaseBuild
|
||||
}
|
||||
|
||||
anr_fix {
|
||||
enable true
|
||||
}
|
||||
crash_fix {
|
||||
enable true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
* <p>
|
||||
* 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;
|
||||
32
app/src/main/java/com/mogo/launcher/lancet/CrashFix.kt
Normal file
32
app/src/main/java/com/mogo/launcher/lancet/CrashFix.kt
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user