Skip to content

Commit

Permalink
feat: add support for flavors
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Jul 29, 2024
1 parent fa8885e commit ed77dab
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ plugins {
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.cocoapods) apply false
alias(libs.plugins.ktlint) apply false
}
alias(libs.plugins.buildKonfig) apply false
}
49 changes: 48 additions & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING

plugins {
alias(libs.plugins.kotlinMultiplatform)
Expand All @@ -9,6 +10,7 @@ plugins {
alias(libs.plugins.cocoapods)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.ktlint)
alias(libs.plugins.buildKonfig)
}

kotlin {
Expand Down Expand Up @@ -71,12 +73,57 @@ kotlin {
}
}


buildkonfig {
packageName = "org.ooni.ooniprobe"

// default config is required
defaultConfigs {
buildConfigField(STRING, "BASE_SOFTWARE_NAME", "ooniprobe")
buildConfigField(STRING, "APP_ID", "org.ooni.ooniprobe")
}

defaultConfigs("ooniprobe") {
buildConfigField(STRING, "APP_ID", "org.ooni.ooniprobe")
}

defaultConfigs("nms") {
buildConfigField(STRING, "APP_ID", "org.dw.ooniprobe")
}

targetConfigs("ooniprobe") {
// names in create should be the same as target names you specified
create("android") {
buildConfigField(STRING, "APP_ID", "org.ooni.ooniprobe")
buildConfigField(STRING, "BASE_SOFTWARE_NAME", "ooniprobe-android")
}

create("ios") {
buildConfigField(STRING, "BASE_SOFTWARE_NAME", "ooniprobe-ios")
}
}

targetConfigs("nms") {
// names in create should be the same as target names you specified
create("android") {
buildConfigField(STRING, "APP_ID", "org.dw.ooniprobe")
buildConfigField(STRING, "BASE_SOFTWARE_NAME", "news-media-scan-android")
}

create("ios") {
buildConfigField(STRING, "BASE_SOFTWARE_NAME", "news-media-scan-ios")
}
}
}

android {
namespace = "org.ooni.probe"
compileSdk = libs.versions.android.compileSdk.get().toInt()

defaultConfig {
applicationId = "org.ooni.probe"
val targetConfigs = buildkonfig.targetConfigs[properties["buildkonfig.flavor"]]!!
applicationId = targetConfigs.asMap["android"]!!.toTargetConfig().fieldSpecs["APP_ID"]!!.value

minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import org.ooni.ooniprobe.BuildKonfig

@Composable
fun MainScreen(viewModel: MainViewModel) {
Expand All @@ -20,7 +21,7 @@ fun MainScreen(viewModel: MainViewModel) {
onClick = { viewModel.onEvent(MainViewModel.Event.StartClick) },
enabled = !state.isRunning,
) {
Text("Run Test")
Text("Run Test ${BuildKonfig.BASE_SOFTWARE_NAME}")
}

Text(
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ android.useAndroidX=true

#MPP
kotlin.mpp.androidSourceSetLayoutVersion=2
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.enableCInteropCommonization=true

# BuildKonfig
buildkonfig.flavor=ooniprobe
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ jetbrainsComposeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "12.1.1" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "12.1.1" }
buildKonfig = { id = "com.codingfeline.buildkonfig", version = "0.13.3" }

0 comments on commit ed77dab

Please sign in to comment.