diff --git a/build.gradle.kts b/build.gradle.kts index ee4a7838..aacfdc60 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,4 +8,5 @@ plugins { alias(libs.plugins.kotlinMultiplatform) apply false alias(libs.plugins.cocoapods) apply false alias(libs.plugins.ktlint) apply false -} \ No newline at end of file + alias(libs.plugins.buildKonfig) apply false +} diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index cb16a249..f5b74db1 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -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) @@ -9,6 +10,7 @@ plugins { alias(libs.plugins.cocoapods) alias(libs.plugins.kotlinSerialization) alias(libs.plugins.ktlint) + alias(libs.plugins.buildKonfig) } kotlin { @@ -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 diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/main/MainScreen.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/main/MainScreen.kt index 548804d7..08a3b3e0 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/main/MainScreen.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/main/MainScreen.kt @@ -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) { @@ -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( diff --git a/gradle.properties b/gradle.properties index 5db355f8..7b56a336 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,4 +9,7 @@ android.useAndroidX=true #MPP kotlin.mpp.androidSourceSetLayoutVersion=2 -kotlin.mpp.enableCInteropCommonization=true \ No newline at end of file +kotlin.mpp.enableCInteropCommonization=true + +# BuildKonfig +buildkonfig.flavor=ooniprobe diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 34f548b2..a28a5b5e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } \ No newline at end of file +ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "12.1.1" } +buildKonfig = { id = "com.codingfeline.buildkonfig", version = "0.13.3" }