Skip to content

Commit f335054

Browse files
authored
Merge pull request #243 from Henry-ZHR/master
Better flavors & Room Gradle Plugin (trying to fix CI)
2 parents d8777b1 + 2fe6efb commit f335054

File tree

10 files changed

+35
-274
lines changed

10 files changed

+35
-274
lines changed

Diff for: app/build.gradle.kts

+30-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.kotlin)
77
alias(libs.plugins.kotlin.parcelize)
88
alias(libs.plugins.ksp)
9+
alias(libs.plugins.room)
910
}
1011

1112
fun readProperties(file: File): Properties {
@@ -46,10 +47,6 @@ android {
4647
vectorDrawables.useSupportLibrary = true
4748
multiDexEnabled = true
4849

49-
ksp {
50-
arg("room.schemaLocation", "$projectDir/schemas")
51-
}
52-
5350
buildConfigField(
5451
"String",
5552
"LASTFM_API_KEY",
@@ -151,17 +148,24 @@ android {
151148
}
152149
}
153150

154-
flavorDimensions += "channel"
151+
flavorDimensions += listOf("channel", "updater")
155152
productFlavors {
156-
create("nongoogle") {
153+
create("nonGoogle") {
157154
dimension = "channel"
158155
isDefault = true
159156
}
160157
create("google") {
161158
dimension = "channel"
162159
}
163-
create("noupdater") {
164-
dimension = "channel"
160+
161+
create("withUpdater") {
162+
dimension = "updater"
163+
isDefault = true
164+
buildConfigField("boolean", "ENABLE_UPDATER", "true")
165+
}
166+
create("withoutUpdater") {
167+
dimension = "updater"
168+
buildConfigField("boolean", "ENABLE_UPDATER", "false")
165169
}
166170
}
167171

@@ -188,6 +192,24 @@ android {
188192
dependenciesInfo {
189193
includeInApk = false
190194
}
195+
196+
room {
197+
schemaDirectory("$projectDir/schemas")
198+
}
199+
}
200+
201+
androidComponents {
202+
beforeVariants { variantBuilder ->
203+
if (variantBuilder.productFlavors.containsAll(
204+
listOf(
205+
"channel" to "google",
206+
"updater" to "withUpdater"
207+
)
208+
)
209+
) {
210+
variantBuilder.enable = false
211+
}
212+
}
191213
}
192214

193215
dependencies {
@@ -241,7 +263,4 @@ dependencies {
241263

242264
val googleImplementation by configurations
243265
googleImplementation(libs.billingclient)
244-
245-
val noupdaterImplementation by configurations
246-
noupdaterImplementation(libs.billingclient)
247266
}

Diff for: app/src/main/java/remix/myplayer/App.kt

-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,5 @@ class App : MultiDexApplication() {
154154
//是否是googlePlay版本
155155
val IS_GOOGLEPLAY =
156156
!BuildConfig.DEBUG && BuildConfig.FLAVOR == "google"
157-
158-
val ENABLE_UPDATER = BuildConfig.FLAVOR == "nonGoogle"
159157
}
160158
}

Diff for: app/src/main/java/remix/myplayer/ui/activity/MainActivity.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import com.google.gson.Gson
2828
import com.google.gson.reflect.TypeToken
2929
import com.soundcloud.android.crop.Crop
3030
import remix.myplayer.App
31-
import remix.myplayer.App.Companion.ENABLE_UPDATER
31+
import remix.myplayer.BuildConfig
3232
import remix.myplayer.R
3333
import remix.myplayer.bean.misc.CustomCover
3434
import remix.myplayer.bean.misc.Library
@@ -699,7 +699,7 @@ class MainActivity : MenuActivity(), View.OnClickListener {
699699
}
700700

701701
private fun checkUpdate() {
702-
if (ENABLE_UPDATER && !alreadyCheck) {
702+
if (BuildConfig.ENABLE_UPDATER && !alreadyCheck) {
703703
UpdateAgent.forceCheck = false
704704
UpdateAgent.listener = UpdateListener(this)
705705
alreadyCheck = true

Diff for: app/src/main/java/remix/myplayer/ui/activity/SettingActivity.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import io.reactivex.disposables.Disposable
3232
import io.reactivex.schedulers.Schedulers
3333
import kotlinx.coroutines.Dispatchers
3434
import kotlinx.coroutines.withContext
35-
import remix.myplayer.App.Companion.ENABLE_UPDATER
3635
import remix.myplayer.App.Companion.IS_GOOGLEPLAY
3736
import remix.myplayer.BuildConfig
3837
import remix.myplayer.R
@@ -407,7 +406,7 @@ class SettingActivity : ToolbarActivity(), ColorChooserDialog.ColorCallback,
407406
}
408407
}.start()
409408

410-
if (!ENABLE_UPDATER) {
409+
if (!BuildConfig.ENABLE_UPDATER) {
411410
binding.settingUpdateContainer.visibility = View.GONE
412411
}
413412

File renamed without changes.

Diff for: app/src/noupdater/AndroidManifest.xml

-13
This file was deleted.

Diff for: app/src/noupdater/kotlin/remix/myplayer/ui/activity/SupportActivity.kt

-244
This file was deleted.

Diff for: build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ plugins {
44
alias(libs.plugins.kotlin) apply false
55
alias(libs.plugins.kotlin.parcelize) apply false
66
alias(libs.plugins.ksp) apply false
7+
alias(libs.plugins.room) apply false
78
}

Diff for: gradle/libs.versions.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ application = { id = "com.android.application", version.ref = "agp" }
1313
kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
1414
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
1515
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
16+
room = { id = "androidx.room", version.ref = "room" }
1617

1718

1819
[libraries]

0 commit comments

Comments
 (0)