mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 03:32:38 +08:00
feat: productFlavors
This commit is contained in:
parent
1aae5025fa
commit
1e7b409b6e
19
.github/workflows/Build-Apk.yml
vendored
19
.github/workflows/Build-Apk.yml
vendored
|
@ -18,7 +18,7 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-java@v3
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: '17'
|
||||
|
@ -41,15 +41,20 @@ jobs:
|
|||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release
|
||||
path: app/build/outputs/apk/release
|
||||
name: default-debug
|
||||
path: app/build/outputs/apk/default/debug
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: releaseNoMinify
|
||||
path: app/build/outputs/apk/releaseNoMinify
|
||||
name: default-release
|
||||
path: app/build/outputs/apk/default/release
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: debug
|
||||
path: app/build/outputs/apk/debug
|
||||
name: fdroid-debug
|
||||
path: app/build/outputs/apk/fdroid/debug
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: fdroid-release
|
||||
path: app/build/outputs/apk/fdroid/release
|
||||
|
|
28
.github/workflows/Build-Release.yml
vendored
28
.github/workflows/Build-Release.yml
vendored
|
@ -34,18 +34,23 @@ jobs:
|
|||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release
|
||||
path: app/build/outputs/apk/release
|
||||
name: default-debug
|
||||
path: app/build/outputs/apk/default/debug
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: releaseNoMinify
|
||||
path: app/build/outputs/apk/releaseNoMinify
|
||||
name: default-release
|
||||
path: app/build/outputs/apk/default/release
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: debug
|
||||
path: app/build/outputs/apk/debug
|
||||
name: fdroid-debug
|
||||
path: app/build/outputs/apk/fdroid/debug
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: fdroid-release
|
||||
path: app/build/outputs/apk/fdroid/release
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
|
@ -82,10 +87,19 @@ jobs:
|
|||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: outputs/apk/release/app-release.apk
|
||||
asset_path: outputs/apk/default/release/app-default-release.apk
|
||||
asset_name: gkd-${{ github.ref_name }}.apk
|
||||
asset_content_type: application/vnd.android.package-archive
|
||||
|
||||
- uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: outputs/apk/fdroid/release/app-fdroid-release.apk
|
||||
asset_name: gkd-fdroid-${{ github.ref_name }}.apk
|
||||
asset_content_type: application/vnd.android.package-archive
|
||||
|
||||
- run: zip -r outputs.zip outputs
|
||||
|
||||
- uses: actions/upload-release-asset@v1
|
||||
|
|
|
@ -36,6 +36,7 @@ val vnSuffix = "-${gitInfo?.commitId?.substring(0, 7) ?: "unknown"}"
|
|||
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.androidx.room)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
alias(libs.plugins.kotlin.parcelize)
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
|
@ -70,6 +71,7 @@ android {
|
|||
"GIT_COMMIT_ID",
|
||||
jsonStringOf(gitInfo?.commitId)
|
||||
)
|
||||
buildConfigField("Boolean", "ENABLED_UPDATE", jsonStringOf(true))
|
||||
resourceConfigurations.addAll(listOf("zh", "en"))
|
||||
ndk {
|
||||
// noinspection ChromeOsAbiSupport
|
||||
|
@ -79,6 +81,12 @@ android {
|
|||
|
||||
lint {}
|
||||
|
||||
buildFeatures {
|
||||
buildConfig = true
|
||||
compose = true
|
||||
aidl = true
|
||||
}
|
||||
|
||||
val currentSigning = if (project.hasProperty("GKD_STORE_FILE")) {
|
||||
signingConfigs.create("release") {
|
||||
storeFile = file(project.properties["GKD_STORE_FILE"] as String)
|
||||
|
@ -107,11 +115,6 @@ android {
|
|||
)
|
||||
)
|
||||
}
|
||||
create("releaseNoMinify") {
|
||||
initWith(getByName("release"))
|
||||
isMinifyEnabled = false
|
||||
isShrinkResources = false
|
||||
}
|
||||
debug {
|
||||
versionNameSuffix = vnSuffix
|
||||
applicationIdSuffix = ".debug"
|
||||
|
@ -120,10 +123,23 @@ android {
|
|||
resValue("string", "import_desc", "GKD-debug-导入数据")
|
||||
}
|
||||
}
|
||||
productFlavors {
|
||||
flavorDimensions += "channel"
|
||||
val defaultName = "default"
|
||||
create(defaultName) {
|
||||
isDefault = true
|
||||
}
|
||||
create("fdroid") {
|
||||
buildConfigField("Boolean", "ENABLED_UPDATE", jsonStringOf(false))
|
||||
}
|
||||
all {
|
||||
dimension = flavorDimensionList.first()
|
||||
manifestPlaceholders["channel"] = name
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_17.majorVersion
|
||||
|
@ -133,11 +149,7 @@ android {
|
|||
freeCompilerArgs += "-opt-in=androidx.compose.material3.ExperimentalMaterial3Api"
|
||||
freeCompilerArgs += "-opt-in=androidx.compose.foundation.ExperimentalFoundationApi"
|
||||
}
|
||||
buildFeatures {
|
||||
buildConfig = true
|
||||
compose = true
|
||||
aidl = true
|
||||
}
|
||||
dependenciesInfo.includeInApk = false
|
||||
packagingOptions.resources.excludes += setOf(
|
||||
// https://github.com/Kotlin/kotlinx.coroutines/issues/2023
|
||||
"META-INF/**", "**/attach_hotspot_windows.dll",
|
||||
|
@ -149,9 +161,14 @@ android {
|
|||
"**/custom.config.conf",
|
||||
"**/custom.config.yaml",
|
||||
)
|
||||
sourceSets.configureEach {
|
||||
kotlin.srcDir("${layout.buildDirectory.asFile.get()}/generated/ksp/$name/kotlin/")
|
||||
}
|
||||
}
|
||||
|
||||
// https://developer.android.com/jetpack/androidx/releases/room?hl=zh-cn#compiler-options
|
||||
room {
|
||||
schemaDirectory("$projectDir/schemas")
|
||||
}
|
||||
ksp {
|
||||
arg("room.generateKotlin", "true")
|
||||
}
|
||||
|
||||
configurations.configureEach {
|
||||
|
@ -159,12 +176,6 @@ configurations.configureEach {
|
|||
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-debug")
|
||||
}
|
||||
|
||||
ksp {
|
||||
arg("room.schemaLocation", "$projectDir/schemas")
|
||||
arg("room.incremental", "true")
|
||||
arg("room.generateKotlin", "true")
|
||||
}
|
||||
|
||||
composeCompiler {
|
||||
// https://developer.android.com/develop/ui/compose/performance/stability/strongskipping?hl=zh-cn
|
||||
enableStrongSkippingMode = true
|
||||
|
|
|
@ -42,6 +42,10 @@
|
|||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true">
|
||||
|
||||
<meta-data
|
||||
android:name="channel"
|
||||
android:value="${channel}" />
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
|
|
|
@ -2,6 +2,7 @@ package li.songe.gkd
|
|||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import com.blankj.utilcode.util.LogUtils
|
||||
import com.hjq.toast.Toaster
|
||||
|
@ -26,6 +27,14 @@ private lateinit var innerApp: Application
|
|||
val app: Application
|
||||
get() = innerApp
|
||||
|
||||
val applicationInfo by lazy {
|
||||
app.packageManager.getApplicationInfo(
|
||||
app.packageName,
|
||||
PackageManager.GET_META_DATA
|
||||
)
|
||||
}
|
||||
|
||||
val channel by lazy { applicationInfo.metaData.getString("channel") }
|
||||
|
||||
@HiltAndroidApp
|
||||
class App : Application() {
|
||||
|
@ -56,6 +65,7 @@ class App : Application() {
|
|||
"GIT_COMMIT_URL: $GIT_COMMIT_URL",
|
||||
"VERSION_CODE: ${BuildConfig.VERSION_CODE}",
|
||||
"VERSION_NAME: ${BuildConfig.VERSION_NAME}",
|
||||
"CHANNEL: $channel"
|
||||
)
|
||||
|
||||
initFolder()
|
||||
|
|
|
@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.debounce
|
|||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
import li.songe.gkd.BuildConfig.ENABLED_UPDATE
|
||||
import li.songe.gkd.data.RawSubscription
|
||||
import li.songe.gkd.data.SubsItem
|
||||
import li.songe.gkd.db.DbSet
|
||||
|
@ -47,8 +48,8 @@ class MainViewModel : ViewModel() {
|
|||
clearCache()
|
||||
}
|
||||
|
||||
if (storeFlow.value.autoCheckAppUpdate) {
|
||||
appScope.launch {
|
||||
if (ENABLED_UPDATE && storeFlow.value.autoCheckAppUpdate) {
|
||||
appScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
checkUpdate()
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import androidx.compose.ui.unit.dp
|
|||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.annotation.RootNavGraph
|
||||
import li.songe.gkd.BuildConfig
|
||||
import li.songe.gkd.channel
|
||||
import li.songe.gkd.ui.style.itemPadding
|
||||
import li.songe.gkd.util.GIT_COMMIT_URL
|
||||
import li.songe.gkd.util.LocalNavController
|
||||
|
@ -40,6 +41,7 @@ fun AboutPage() {
|
|||
val navController = LocalNavController.current
|
||||
val context = LocalContext.current
|
||||
|
||||
val buildName = channel?.let { "$it-" } + BuildConfig.BUILD_TYPE
|
||||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
|
||||
Scaffold(
|
||||
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||
|
@ -149,6 +151,7 @@ fun AboutPage() {
|
|||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
@ -159,7 +162,7 @@ fun AboutPage() {
|
|||
style = MaterialTheme.typography.bodyLarge,
|
||||
)
|
||||
Text(
|
||||
text = BuildConfig.BUILD_TYPE,
|
||||
text = buildName,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
|
|
|
@ -43,6 +43,7 @@ import com.blankj.utilcode.util.LogUtils
|
|||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.update
|
||||
import li.songe.gkd.BuildConfig.ENABLED_UPDATE
|
||||
import li.songe.gkd.MainActivity
|
||||
import li.songe.gkd.appScope
|
||||
import li.songe.gkd.ui.component.RotatingLoadingIcon
|
||||
|
@ -324,37 +325,40 @@ fun useSettingsPage(): ScaffoldExt {
|
|||
storeFlow.update { s -> s.copy(updateSubsInterval = it.value) }
|
||||
}
|
||||
|
||||
TextSwitch(
|
||||
name = "自动更新",
|
||||
desc = "打开应用时检测新版本",
|
||||
checked = store.autoCheckAppUpdate,
|
||||
onCheckedChange = {
|
||||
storeFlow.value = store.copy(
|
||||
autoCheckAppUpdate = it
|
||||
)
|
||||
})
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable(
|
||||
onClick = appScope.launchAsFn {
|
||||
if (checkUpdatingFlow.value) return@launchAsFn
|
||||
val newVersion = checkUpdate()
|
||||
if (newVersion == null) {
|
||||
toast("暂无更新")
|
||||
}
|
||||
}
|
||||
)
|
||||
.fillMaxWidth()
|
||||
.itemPadding(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = "检查更新",
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
if (ENABLED_UPDATE) {
|
||||
TextSwitch(
|
||||
name = "自动更新",
|
||||
desc = "打开应用时检测新版本",
|
||||
checked = store.autoCheckAppUpdate,
|
||||
onCheckedChange = {
|
||||
storeFlow.value = store.copy(
|
||||
autoCheckAppUpdate = it
|
||||
)
|
||||
}
|
||||
)
|
||||
RotatingLoadingIcon(loading = checkUpdating)
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable(
|
||||
onClick = appScope.launchAsFn {
|
||||
if (checkUpdatingFlow.value) return@launchAsFn
|
||||
val newVersion = checkUpdate()
|
||||
if (newVersion == null) {
|
||||
toast("暂无更新")
|
||||
}
|
||||
}
|
||||
)
|
||||
.fillMaxWidth()
|
||||
.itemPadding(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = "检查更新",
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
)
|
||||
RotatingLoadingIcon(loading = checkUpdating)
|
||||
}
|
||||
}
|
||||
|
||||
Text(
|
||||
|
|
|
@ -9,6 +9,7 @@ import kotlinx.coroutines.launch
|
|||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.encodeToString
|
||||
import li.songe.gkd.BuildConfig.ENABLED_UPDATE
|
||||
import li.songe.gkd.appScope
|
||||
|
||||
private inline fun <reified T> createStorageFlow(
|
||||
|
@ -47,7 +48,7 @@ data class Store(
|
|||
val httpServerPort: Int = 8888,
|
||||
val updateSubsInterval: Long = UpdateTimeOption.Everyday.value,
|
||||
val captureVolumeChange: Boolean = false,
|
||||
val autoCheckAppUpdate: Boolean = true,
|
||||
val autoCheckAppUpdate: Boolean = ENABLED_UPDATE,
|
||||
val toastWhenClick: Boolean = true,
|
||||
val clickToast: String = "GKD",
|
||||
val autoClearMemorySubs: Boolean = true,
|
||||
|
|
|
@ -19,6 +19,7 @@ plugins {
|
|||
|
||||
alias(libs.plugins.android.library) apply false
|
||||
alias(libs.plugins.android.application) apply false
|
||||
alias(libs.plugins.androidx.room) apply false
|
||||
|
||||
alias(libs.plugins.kotlin.serialization) apply false
|
||||
alias(libs.plugins.kotlin.parcelize) apply false
|
||||
|
|
|
@ -83,3 +83,4 @@ kotlin_compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "ko
|
|||
rikka_refine = { id = "dev.rikka.tools.refine", version.ref = "rikka" }
|
||||
google_ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
|
||||
google_hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
|
||||
androidx_room = { id = "androidx.room", version.ref = "room" }
|
||||
|
|
|
@ -12,10 +12,7 @@ android {
|
|||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
}
|
||||
create("releaseNoMinify") {
|
||||
all {
|
||||
isMinifyEnabled = false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user