diff --git a/.github/workflows/Build-Apk.yml b/.github/workflows/Build-Apk.yml index 6f3df6d94..de079986e 100644 --- a/.github/workflows/Build-Apk.yml +++ b/.github/workflows/Build-Apk.yml @@ -7,6 +7,9 @@ on: branches: - '**' +env: + BUGLY_TOKEN: ${{ secrets.BUGLY_TOKEN }} + jobs: build: if: ${{ !startsWith(github.event.head_commit.message, 'chore:') }} diff --git a/.github/workflows/Build-Release.yml b/.github/workflows/Build-Release.yml index 939fe5280..14c7ff5bb 100644 --- a/.github/workflows/Build-Release.yml +++ b/.github/workflows/Build-Release.yml @@ -5,6 +5,9 @@ on: tags: - v* +env: + BUGLY_TOKEN: ${{ secrets.BUGLY_TOKEN }} + jobs: build: runs-on: ubuntu-latest diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 982f3fdb3..1511544cc 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -44,6 +44,9 @@ android { ).format(nowTime) ) ) + buildConfigField( + "String", "BUGLY_TOKEN", jsonStringOf(System.getenv("BUGLY_TOKEN")) + ) resourceConfigurations.addAll(listOf("zh", "en")) ndk { diff --git a/app/src/main/java/li/songe/gkd/App.kt b/app/src/main/java/li/songe/gkd/App.kt index 33acf60a2..24b9f6270 100644 --- a/app/src/main/java/li/songe/gkd/App.kt +++ b/app/src/main/java/li/songe/gkd/App.kt @@ -9,6 +9,7 @@ import com.tencent.mmkv.MMKV import dagger.hilt.android.HiltAndroidApp import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.MainScope +import li.songe.gkd.data.DeviceInfo import li.songe.gkd.debug.clearHttpSubs import li.songe.gkd.notif.initChannel import li.songe.gkd.util.initAppState @@ -37,7 +38,27 @@ class App : Application() { super.onCreate() _app = this - CrashReport.initCrashReport(applicationContext, "d0ce46b353", false) + @Suppress("SENSELESS_COMPARISON") if (BuildConfig.BUGLY_TOKEN != null) { + CrashReport.setDeviceModel(this, DeviceInfo.instance.model) + CrashReport.setIsDevelopmentDevice(this, BuildConfig.DEBUG) + CrashReport.initCrashReport(applicationContext, + BuildConfig.BUGLY_TOKEN, + BuildConfig.DEBUG, + CrashReport.UserStrategy(this).apply { + setCrashHandleCallback(object : CrashReport.CrashHandleCallback() { + override fun onCrashHandleStart( + p0: Int, + p1: String?, + p2: String?, + p3: String?, + ): MutableMap { + LogUtils.d(p0, p1, p2, p3) // 将报错日志输出到本地 + return super.onCrashHandleStart(p0, p1, p2, p3) + } + }) + }) + } + MMKV.initialize(this) LogUtils.getConfig().apply { setConsoleSwitch(BuildConfig.DEBUG) diff --git a/settings.gradle.kts b/settings.gradle.kts index 074315e3a..2c6dec598 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -80,7 +80,7 @@ dependencyResolutionManagement { // https://github.com/Tencent/MMKV/blob/master/README_CN.md library("tencent.mmkv", "com.tencent:mmkv:1.3.1") // https://bugly.qq.com/docs/user-guide/instruction-manual-android/ - library("tencent.bugly", "com.tencent.bugly:crashreport:4.1.9.2") + library("tencent.bugly", "com.tencent.bugly:crashreport:4.1.9.3") // https://github.com/RikkaApps/HiddenApiRefinePlugin val rikkaVersion = "4.4.0"