[CrashFix]修正LeakCanary数据库由于多次close导致的崩溃

[CrashFix]修正LeakCanary数据库由于多次close导致的崩溃
This commit is contained in:
renwj
2022-10-21 10:50:37 +08:00
parent 5c14cd6531
commit abbe06e8c4
2 changed files with 63 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'android-aspectjx'
apply plugin: 'bugly'
def isReleaseBuild = isReleaseBuild()
//apply ByteX宿主
if (!isAndroidTestBuild()) {
apply plugin: 'bytex'
@@ -51,8 +52,8 @@ if (!isAndroidTestBuild()) {
enableInDebug true
weaveGroup {
crash_fix {
enable true
leak_canary_crash_fix {
enable !isReleaseBuild
}
}
}
@@ -383,3 +384,12 @@ boolean isAndroidTestBuild() {
}
return false
}
boolean isReleaseBuild() {
for (String s : gradle.startParameter.taskNames) {
if (s.contains("Release") | s.contains("release")) {
return true
}
}
return false
}

View File

@@ -0,0 +1,51 @@
package com.mogo.launcher.lancet
import android.database.sqlite.*
import androidx.annotation.*
import com.knightboost.lancet.api.*
import com.knightboost.lancet.api.annotations.*
import com.knightboost.lancet.api.annotations.Weaver
/**
* 此类主要用来修正三方库引起的崩溃
*/
@Keep
@Weaver
@Group("leak_canary_crash_fix")
class LeakCanaryCrashFix {
@Insert
@TargetClass("leakcanary.internal.activity.db.ScopedLeaksDb\$DbOpener")
@TargetMethod(methodName = "getReadableDatabase")
fun proxyGetReadableSQLiteDb(): SQLiteDatabase? {
try {
return Origin.call() as SQLiteDatabase?
} catch (t: Throwable) {
t.printStackTrace()
}
return null
}
@Insert
@TargetClass("leakcanary.internal.activity.db.ScopedLeaksDb\$DbOpener")
@TargetMethod(methodName = "getWritableDatabase")
fun proxyGetWritableSQLiteDb(): SQLiteDatabase? {
try {
return Origin.call() as SQLiteDatabase?
} catch (t: Throwable) {
t.printStackTrace()
}
return null
}
@Insert
@TargetClass("leakcanary.internal.activity.db.ScopedLeaksDb\$DbOpener")
@TargetMethod(methodName = "close")
fun proxyClose() {
try {
Origin.callVoid()
} catch (t: Throwable) {
t.printStackTrace()
}
}
}