From f10a3fcfad27a35864d9e7d02634d3627953e681 Mon Sep 17 00:00:00 2001 From: DatLag Date: Thu, 11 Apr 2024 19:44:40 +0200 Subject: [PATCH] added multiplatform buildkonfig --- build.gradle.kts | 1 + composeApp/build.gradle.kts | 10 +++++++++ .../dev/datlag/aniflow/PackageName.android.kt | 5 ----- .../aniflow/module/PlatformModule.android.kt | 12 +++++----- .../kotlin/dev/datlag/aniflow/PackageName.kt | 3 --- .../dev/datlag/aniflow/PackageName.ios.kt | 22 ------------------- .../aniflow/module/PlatformModule.ios.kt | 10 ++++----- gradle/libs.versions.toml | 6 +++-- 8 files changed, 26 insertions(+), 43 deletions(-) delete mode 100644 composeApp/src/androidMain/kotlin/dev/datlag/aniflow/PackageName.android.kt delete mode 100644 composeApp/src/commonMain/kotlin/dev/datlag/aniflow/PackageName.kt delete mode 100644 composeApp/src/iosMain/kotlin/dev/datlag/aniflow/PackageName.ios.kt diff --git a/build.gradle.kts b/build.gradle.kts index adbee71..12fa7e2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,6 +12,7 @@ plugins { alias(libs.plugins.cocoapods) apply false alias(libs.plugins.compose) apply false alias(libs.plugins.crashlytics) apply false + alias(libs.plugins.konfig) apply false alias(libs.plugins.multiplatform) apply false alias(libs.plugins.moko.resources) apply false alias(libs.plugins.sekret) apply false diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 1e8b98c..e51d7e8 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -1,3 +1,4 @@ +import com.codingfeline.buildkonfig.compiler.FieldSpec import com.mikepenz.aboutlibraries.plugin.DuplicateMode import com.mikepenz.aboutlibraries.plugin.DuplicateRule import org.jetbrains.compose.ExperimentalComposeLibrary @@ -9,6 +10,7 @@ plugins { alias(libs.plugins.multiplatform) alias(libs.plugins.android.application) alias(libs.plugins.compose) + alias(libs.plugins.konfig) alias(libs.plugins.moko.resources) alias(libs.plugins.sekret) alias(libs.plugins.serialization) @@ -32,6 +34,14 @@ aboutLibraries { excludeFields = arrayOf("generated") } +buildkonfig { + packageName = artifact + + defaultConfigs { + buildConfigField(FieldSpec.Type.STRING, "packageName", artifact) + } +} + sekret { properties { enabled.set(true) diff --git a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/PackageName.android.kt b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/PackageName.android.kt deleted file mode 100644 index 8afbf04..0000000 --- a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/PackageName.android.kt +++ /dev/null @@ -1,5 +0,0 @@ -package dev.datlag.aniflow - -actual fun getPackageName(): String { - return BuildConfig.APPLICATION_ID -} \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/module/PlatformModule.android.kt b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/module/PlatformModule.android.kt index d48c6a5..15a75dc 100644 --- a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/module/PlatformModule.android.kt +++ b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/module/PlatformModule.android.kt @@ -6,10 +6,10 @@ import androidx.datastore.core.DataStoreFactory import androidx.datastore.core.okio.OkioStorage import coil3.ImageLoader import coil3.request.allowHardware +import dev.datlag.aniflow.BuildKonfig import dev.datlag.aniflow.Sekret import dev.datlag.aniflow.firebase.FirebaseFactory import dev.datlag.aniflow.firebase.initialize -import dev.datlag.aniflow.getPackageName import dev.datlag.aniflow.other.Constants import dev.datlag.aniflow.other.StateSaver import dev.datlag.aniflow.settings.DataStoreUserSettings @@ -65,9 +65,9 @@ actual object PlatformModule { if (StateSaver.sekretLibraryLoaded) { FirebaseFactory.initialize( context = instance(), - projectId = Sekret.firebaseProject(getPackageName()), - applicationId = Sekret.firebaseAndroidApplication(getPackageName())!!, - apiKey = Sekret.firebaseAndroidApiKey(getPackageName())!!, + projectId = Sekret.firebaseProject(BuildKonfig.packageName), + applicationId = Sekret.firebaseAndroidApplication(BuildKonfig.packageName)!!, + apiKey = Sekret.firebaseAndroidApiKey(BuildKonfig.packageName)!!, googleAuthProvider = instanceOrNull() ) } else { @@ -75,10 +75,10 @@ actual object PlatformModule { } } bindSingleton(Constants.Sekret.ANILIST_CLIENT_ID) { - Sekret.anilistClientId(getPackageName()) ?: "" + Sekret.anilistClientId(BuildKonfig.packageName) ?: "" } bindSingleton(Constants.Sekret.ANILIST_CLIENT_SECRET) { - Sekret.anilistClientSecret(getPackageName()) ?: "" + Sekret.anilistClientSecret(BuildKonfig.packageName) ?: "" } bindSingleton { val app: Context = instance() diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/PackageName.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/PackageName.kt deleted file mode 100644 index f87d150..0000000 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/PackageName.kt +++ /dev/null @@ -1,3 +0,0 @@ -package dev.datlag.aniflow - -expect fun getPackageName(): String \ No newline at end of file diff --git a/composeApp/src/iosMain/kotlin/dev/datlag/aniflow/PackageName.ios.kt b/composeApp/src/iosMain/kotlin/dev/datlag/aniflow/PackageName.ios.kt deleted file mode 100644 index 4816a4c..0000000 --- a/composeApp/src/iosMain/kotlin/dev/datlag/aniflow/PackageName.ios.kt +++ /dev/null @@ -1,22 +0,0 @@ -package dev.datlag.aniflow - -private object PackageName { } - -actual fun getPackageName(): String { - val clazz = PackageName::class - - return run { - var cutPackage = clazz.simpleName?.let { - clazz.qualifiedName!!.substringBeforeLast(it) - } ?: clazz.qualifiedName!! - - if (cutPackage.startsWith('.')) { - cutPackage = cutPackage.substring(1) - } - if (cutPackage.endsWith('.')) { - cutPackage = cutPackage.substringBeforeLast('.') - } - - cutPackage - }.trim() -} \ No newline at end of file diff --git a/composeApp/src/iosMain/kotlin/dev/datlag/aniflow/module/PlatformModule.ios.kt b/composeApp/src/iosMain/kotlin/dev/datlag/aniflow/module/PlatformModule.ios.kt index 3d679b8..fc4ce74 100644 --- a/composeApp/src/iosMain/kotlin/dev/datlag/aniflow/module/PlatformModule.ios.kt +++ b/composeApp/src/iosMain/kotlin/dev/datlag/aniflow/module/PlatformModule.ios.kt @@ -44,9 +44,9 @@ actual object PlatformModule { } bindSingleton { FirebaseFactory.initialize( - projectId = firebaseProject(getPackageName()), - applicationId = firebaseIosApplication(getPackageName()), - apiKey = firebaseIosApiKey(getPackageName()), + projectId = firebaseProject(BuildKonfig.packageName), + applicationId = firebaseIosApplication(BuildKonfig.packageName), + apiKey = firebaseIosApiKey(BuildKonfig.packageName), googleAuthProvider = instanceOrNull() ) } @@ -54,10 +54,10 @@ actual object PlatformModule { IosCodeAuthFlowFactory() } bindSingleton(Constants.Sekret.ANILIST_CLIENT_ID) { - anilistClientId(getPackageName()) + anilistClientId(BuildKonfig.packageName) } bindSingleton(Constants.Sekret.ANILIST_CLIENT_SECRET) { - anilistClientSecret(getPackageName()) + anilistClientSecret(BuildKonfig.packageName) } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6bffc47..2d9e747 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,7 +4,7 @@ aboutlibraries = "11.1.0" activity = "1.8.2" android = "8.2.2" android-core = "1.12.0" -android-credentials = "1.3.0-alpha01" +android-credentials = "1.3.0-alpha02" apollo = "4.0.0-beta.4" appcompat = "1.6.1" coil = "3.0.0-alpha06" @@ -12,7 +12,7 @@ compose = "1.6.1" complete-kotlin = "1.1.0" coroutines = "1.8.0" crashlytics-plugin = "2.9.9" -datastore = "1.1.0-beta02" +datastore = "1.1.0-rc01" datetime = "0.5.0" decompose = "3.0.0-alpha09" desugar = "2.0.4" @@ -30,6 +30,7 @@ kasechange = "1.4.1" kmpalette = "3.1.0" kodein = "7.21.2" kolor = "1.4.4" +konfig = "0.15.1" kotlin = "1.9.22" ksp = "1.9.22-1.0.17" ktor = "2.3.9" @@ -116,6 +117,7 @@ cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotli compose = { id = "org.jetbrains.compose", version.ref = "compose" } complete-kotlin = { id = "com.louiscad.complete-kotlin", version.ref = "complete-kotlin" } crashlytics = { id = "com.google.firebase.crashlytics", version.ref = "crashlytics-plugin" } +konfig = { id = "com.codingfeline.buildkonfig", version.ref = "konfig" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } ktorfit = { id = "de.jensklingenberg.ktorfit", version.ref = "ktorfit" } moko-resources = { id = "dev.icerock.mobile.multiplatform-resources", version.ref = "moko-resources" }