Refactor: Convert build configuration to Gradle plugin pattern

- Migrate ProjectConfig from static object to proper Gradle plugin
- Add version type support (beta/rc) to version.properties
- Clean up legacy fastlane changelogs
- Update release script to support version types
- Remove automatic fastlane changelog generation from release script
- Add BuildConfig field injection for version info
This commit is contained in:
darken
2025-10-07 13:54:24 +02:00
committed by Matthias Urhahn
parent 12f0662146
commit 221f3ccbed
52 changed files with 179 additions and 241 deletions
@@ -1,20 +1,22 @@
package eu.darken.capod.common
import eu.darken.capod.BuildConfig
import android.util.Log
import androidx.annotation.Keep
import java.lang.reflect.Field
// Can't be const because that prevents them from being mocked in tests
@Suppress("MayBeConstant")
@Keep
object BuildConfigWrap {
val DEBUG: Boolean = BuildConfig.DEBUG
val BUILD_TYPE: BuildType = when (val typ = BuildConfig.BUILD_TYPE) {
val APPLICATION_ID = getBuildConfigValue("PACKAGENAME") as String
val DEBUG: Boolean = getBuildConfigValue("DEBUG") as Boolean
val BUILD_TYPE: BuildType = when (val typ = getBuildConfigValue("BUILD_TYPE") as String) {
"debug" -> BuildType.DEV
"beta" -> BuildType.BETA
"release" -> BuildType.RELEASE
else -> throw IllegalArgumentException("Unknown buildtype: $typ")
}
@Keep
enum class BuildType {
DEV,
BETA,
@@ -22,24 +24,36 @@ object BuildConfigWrap {
;
}
val FLAVOR: Flavor = when (val flav = BuildConfig.FLAVOR) {
val FLAVOR: Flavor = when (val flav = getBuildConfigValue("FLAVOR") as String?) {
"gplay" -> Flavor.GPLAY
"foss" -> Flavor.FOSS
null -> Flavor.NONE
else -> throw IllegalStateException("Unknown flavor: $flav")
}
enum class Flavor {
GPLAY,
FOSS,
NONE,
;
}
val APPLICATION_ID: String = BuildConfig.APPLICATION_ID
val VERSION_CODE: Long = (getBuildConfigValue("VERSION_CODE") as String).toLong()
val VERSION_NAME: String = getBuildConfigValue("VERSION_NAME") as String
val VERSION_CODE: Long = BuildConfig.VERSION_CODE.toLong()
val VERSION_NAME: String = BuildConfig.VERSION_NAME
val VERSION_DESCRIPTION_LONG: String = "v$VERSION_NAME ($VERSION_CODE) ${FLAVOR}_$BUILD_TYPE"
val VERSION_DESCRIPTION_SHORT: String = "v$VERSION_NAME $FLAVOR"
val VERSION_DESCRIPTION: String = "v$VERSION_NAME ($VERSION_CODE) ~ $FLAVOR/$BUILD_TYPE"
val VERSION_DESCRIPTION_SHORT: String = "v$VERSION_NAME ~ $FLAVOR"
val VERSION_DESCRIPTION_TINY: String = "v$VERSION_NAME"
private fun getBuildConfigValue(fieldName: String): Any? = try {
val c = Class.forName("eu.darken.capod.BuildConfig")
val f: Field = c.getField(fieldName).apply {
isAccessible = true
}
f.get(null)
} catch (e: Exception) {
e.printStackTrace()
Log.e("getBuildConfigValue", "fieldName: $fieldName")
null
}
}
@@ -59,7 +59,7 @@ class RecorderModule @Inject constructor(
triggerFile.createNewFile()
log(TAG, INFO) { "Build.Fingerprint: ${Build.FINGERPRINT}" }
log(TAG, INFO) { "BuildConfig.Versions: ${BuildConfigWrap.VERSION_DESCRIPTION_LONG}" }
log(TAG, INFO) { "BuildConfig.Versions: ${BuildConfigWrap.VERSION_DESCRIPTION}" }
copy(
recorder = newRecorder
@@ -74,7 +74,7 @@ class RecorderActivityVM @Inject constructor(
}
fun share() = launch {
val (path, size) = resultCacheCompressedObs.first()
val (path, _) = resultCacheCompressedObs.first()
val intent = Intent(Intent.ACTION_SEND).apply {
val uri = FileProvider.getUriForFile(
@@ -89,7 +89,7 @@ class RecorderActivityVM @Inject constructor(
type = "application/zip"
addCategory(Intent.CATEGORY_DEFAULT)
putExtra(Intent.EXTRA_SUBJECT, "CAPod DebugLog - ${BuildConfigWrap.VERSION_DESCRIPTION_LONG})")
putExtra(Intent.EXTRA_SUBJECT, "CAPod DebugLog - ${BuildConfigWrap.VERSION_DESCRIPTION})")
putExtra(Intent.EXTRA_TEXT, "Your text here.")
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
@@ -40,7 +40,7 @@ class SettingsIndexFragment : PreferenceFragment2() {
}
override fun onPreferencesCreated() {
findPreference<Preference>("core.changelog")!!.summary = BuildConfigWrap.VERSION_DESCRIPTION_LONG
findPreference<Preference>("core.changelog")!!.summary = BuildConfigWrap.VERSION_DESCRIPTION
findPreference<Preference>("core.privacy")!!.setOnPreferenceClickListener {
webpageTool.open(PrivacyPolicy.URL)
true