Skip to content

Commit

Permalink
feat: configure flavor and app name
Browse files Browse the repository at this point in the history
  • Loading branch information
aslansari committed Mar 21, 2024
1 parent 5ee5140 commit 5b914d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<resources>
<string name="app_name">template</string>
</resources>
25 changes: 18 additions & 7 deletions build-logic/convention/src/main/kotlin/template/Flavor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,43 @@ import com.android.build.api.dsl.ApplicationProductFlavor
import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project

@Suppress("EnumEntryName", "EnumNaming")
enum class FlavorDimension {
CONTENT_TYPE
contentType
}

// The content for the app can either come from local static data which is useful for demo
// purposes, or from a production backend server which supplies up-to-date, real content.
// These two product flavors reflect this behaviour.
enum class Flavor (val dimension : FlavorDimension, val applicationIdSuffix : String? = null) {
DEMO(FlavorDimension.CONTENT_TYPE),
PROD(FlavorDimension.CONTENT_TYPE, ".prod")
@Suppress("EnumEntryName", "EnumNaming")
enum class Flavor(val dimension: FlavorDimension, val applicationIdSuffix: String? = null) {
dev(FlavorDimension.contentType, ".dev"),
beta(FlavorDimension.contentType, ".beta"),
prod(FlavorDimension.contentType)
}

fun Project.configureFlavors(
commonExtension: CommonExtension<*, *, *, *, *>
commonExtension: CommonExtension<*, *, *, *, *>,
) {
commonExtension.apply {
flavorDimensions += FlavorDimension.CONTENT_TYPE.name
flavorDimensions += FlavorDimension.contentType.name
productFlavors {
Flavor.values().forEach{
Flavor.values().forEach {
create(it.name) {
dimension = it.dimension.name
if (this@apply is ApplicationExtension && this is ApplicationProductFlavor) {
if (it.applicationIdSuffix != null) {
this.applicationIdSuffix = it.applicationIdSuffix
}
}
val appName = buildString {
append("template")
if (it.applicationIdSuffix != null) {
append(" - ")
append(it.applicationIdSuffix.uppercase())
}
}
resValue("string", "app_name", appName)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions buildscripts/setup.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ task replaceTemplateReferences {
)

replaceTextInFile(
"${rootDir}/app/src/main/res/values/strings.xml",
"<string name=\"app_name\">${renameConfig.templateName}</string>",
"<string name=\"app_name\">${renameConfig.newProjectName}</string>",
"${rootDir}/build-logic/convention/src/main/kotlin/template/Flavor.kt",
"append\\(\"${renameConfig.templateName}\"",
"append\\(\"${renameConfig.newProjectName}\"",
)

replaceTextInFile(
Expand Down

0 comments on commit 5b914d0

Please sign in to comment.