From 8399f98d755c99847595e84daf684a0f370dd1a2 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Wed, 21 Aug 2024 17:03:52 +0200 Subject: [PATCH] Improvements try to make it run on Android (still unsuccessful) --- commonUI/build.gradle.kts | 82 +++++++++---------- domain/build.gradle.kts | 47 +++++------ .../kotlin/ch/dissem/yaep/domain/GameTest.kt | 35 ++++---- gradle/libs.versions.toml | 16 ++-- 4 files changed, 90 insertions(+), 90 deletions(-) diff --git a/commonUI/build.gradle.kts b/commonUI/build.gradle.kts index 89e3f1a..d7d8e47 100644 --- a/commonUI/build.gradle.kts +++ b/commonUI/build.gradle.kts @@ -1,59 +1,57 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile - plugins { - alias(libs.plugins.android.library) alias(libs.plugins.kotlin.multiplatform) - alias(libs.plugins.compose.compiler) + alias(libs.plugins.android.library) alias(libs.plugins.compose) + alias(libs.plugins.compose.compiler) } kotlin { - jvm { - tasks.withType().configureEach { - compilerOptions { - jvmTarget.set(JvmTarget.JVM_17) - } - } - } + jvmToolchain(libs.versions.jdk.get().toInt()) - androidTarget { - tasks.withType().configureEach { - compilerOptions { - jvmTarget.set(JvmTarget.JVM_11) - } - } + jvm("desktop") + androidTarget() - android.apply { - compileSdk = libs.versions.android.compileSdk.get().toInt() - namespace = "ch.dissem.yaep.common.ui" - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - } - } +// @OptIn(ExperimentalWasmDsl::class) +// wasmJs { +// moduleName = "yaep-commonUI" +// browser() +// binaries.executable() +// } sourceSets { - commonMain { - dependencies { - api(projects.domain) + val androidMain by getting + val commonTest by getting - implementation(compose.components.resources) - implementation(compose.runtime) - implementation(compose.foundation) - implementation(compose.material3) - implementation(compose.ui) - implementation(compose.components.uiToolingPreview) + commonMain.dependencies { + api(projects.domain) + + implementation(compose.components.resources) + implementation(compose.runtime) + implementation(compose.foundation) + implementation(compose.material3) + implementation(compose.ui) + implementation(compose.components.uiToolingPreview) // implementation(libs.compose.ui.text.googlefonts) - } + + implementation(libs.logging) } - val commonTest by getting { - dependencies { - implementation(libs.kotlin.test) - implementation(libs.atrium) - } + androidMain.dependencies { + implementation(libs.androidx.compose.foundation) } + + commonTest.dependencies { + implementation(libs.kotlin.test) + implementation(libs.atrium) + } + } +} + +android { + compileSdk = libs.versions.android.compileSdk.get().toInt() + namespace = "ch.dissem.yaep.common.ui" + + buildFeatures { + compose = true } } diff --git a/domain/build.gradle.kts b/domain/build.gradle.kts index 0174034..8c1b8b0 100644 --- a/domain/build.gradle.kts +++ b/domain/build.gradle.kts @@ -1,43 +1,38 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile - plugins { alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.android.library) } kotlin { - jvm{ - tasks.withType().configureEach { - compilerOptions { - jvmTarget.set(JvmTarget.JVM_17) - } - } - } + jvmToolchain(libs.versions.jdk.get().toInt()) - androidTarget{ - tasks.withType().configureEach { - compilerOptions { - jvmTarget.set(JvmTarget.JVM_11) - } - } - } + jvm() + androidTarget() - android.apply { - compileSdk = libs.versions.android.compileSdk.get().toInt() - namespace = "ch.dissem.yaep.domain" - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - } +// @OptIn(ExperimentalWasmDsl::class) +// wasmJs { +// moduleName = "yaep-commonUI" +// browser() +// binaries.executable() +// } sourceSets { - val commonTest by getting { + commonMain { + dependencies { + implementation(libs.logging) + } + } + + commonTest { dependencies { implementation(libs.kotlin.test) implementation(libs.atrium) } } } +} + +android { + compileSdk = libs.versions.android.compileSdk.get().toInt() + namespace = "ch.dissem.yaep.domain" } \ No newline at end of file diff --git a/domain/src/commonTest/kotlin/ch/dissem/yaep/domain/GameTest.kt b/domain/src/commonTest/kotlin/ch/dissem/yaep/domain/GameTest.kt index 2f4bb0d..270382e 100644 --- a/domain/src/commonTest/kotlin/ch/dissem/yaep/domain/GameTest.kt +++ b/domain/src/commonTest/kotlin/ch/dissem/yaep/domain/GameTest.kt @@ -9,6 +9,7 @@ import ch.tutteli.atrium.api.fluent.en_GB.toBeGreaterThan import ch.tutteli.atrium.api.fluent.en_GB.toBeLessThan import ch.tutteli.atrium.api.fluent.en_GB.toEqual import ch.tutteli.atrium.api.verbs.expect +import co.touchlab.kermit.Logger import kotlin.test.Test import kotlin.time.Duration.Companion.milliseconds import kotlin.time.measureTime @@ -17,7 +18,7 @@ class GameTest { @Test fun `ensure generated games are solvable`() { - val tries = 2000 + val tries = 1000 var fastest = 500.milliseconds var slowest = 0.milliseconds var total = 0.milliseconds @@ -29,10 +30,10 @@ class GameTest { val time = measureTime { game = generateGame() } - println("Generated game #$i in ${time.inWholeMilliseconds}ms") + Logger.i { "Generated game #$i in ${time.inWholeMilliseconds}ms" } val solvable = solve(game.grid, game.clues) if (solvable != SOLVABLE) { - println("Puzzle:\n$game") + Logger.i { "Puzzle:\n$game" } } expect(solvable).toEqual(SOLVABLE) expect(time).toBeLessThan(500.milliseconds) @@ -43,22 +44,22 @@ class GameTest { slowest = time } total += time - if (game.clues.size > most){ + if (game.clues.size > most) { most = game.clues.size } - if (game.clues.size < least){ + if (game.clues.size < least) { least = game.clues.size } totalClues += game.clues.size } - println("Slowest: $slowest") - println("Fastest: $fastest") - println("Average: ${total / tries}") - println("Clues:") - println("Most: $most") - println("Least: $least") - println("Average: ${totalClues / tries}") + Logger.i { "Slowest: $slowest" } + Logger.i { "Fastest: $fastest" } + Logger.i { "Average: ${total / tries}" } + Logger.i { "Clues:" } + Logger.i { "Most: $most" } + Logger.i { "Least: $least" } + Logger.i { "Average: ${totalClues / tries}" } } @Test @@ -75,8 +76,8 @@ class GameTest { feature(Collection::size).toBeLessThan(30) } } - println("Clues: ${game.clues.size}") - println("Time: $time") + Logger.i{"Clues: ${game.clues.size}"} + Logger.i{"Time: $time"} expect(solve(game.grid, game.clues)).toEqual(SOLVABLE) expect(time).toBeLessThan(500.milliseconds) } @@ -130,7 +131,8 @@ class GameTest { @Test fun `ensure specific game is solvable`() { - val game = Game.parse(""" + val game = Game.parse( + """ 👩🏿‍⚕️👨🏽‍🎤👩🏿‍⚕️ 👩🏾‍🚀🧑🏿‍🏫 🐜🐕 🐐 🐐 🍉🥭🍐🍇🍍 @@ -162,7 +164,8 @@ class GameTest { * ROCK_STAR and UNITED_KINGDOM are in the same column * ROCK_STAR is next to DOUGHNUT * PINEAPPLE is between the neighbours TEACHER and GRAPES to both sides - """.trimIndent()) + """.trimIndent() + ) expect(solve(game.grid, game.clues)).toEqual(SOLVABLE) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a2328cf..6e2522c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,21 +1,25 @@ [versions] -agp = "8.5.2" +agp = "8.3.2" +jdk = "11" android-compileSdk = "34" android-minSdk = "24" android-targetSdk = "34" androidx-activityCompose = "1.9.1" -androidx-compose = "1.6.8" +androidx-compose = "1.6.7" compose-plugin = "1.6.11" kotlin = "2.0.0" -kotlinVersion = "2.0.0" coreKtx = "1.13.1" +atrium = "1.2.0" [libraries] androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } androidx-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "androidx-compose" } +androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose" } kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } -atrium = { module = "ch.tutteli.atrium:atrium-fluent", version = "1.2.0" } -androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } +atrium = { module = "ch.tutteli.atrium:atrium-fluent", version.ref = "atrium" } +atrium-js = { module = "ch.tutteli.atrium:atrium-fluent-js", version.ref = "atrium" } +androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" } +logging = { module = "co.touchlab:kermit", version = "2.0.4" } [plugins] versions = { id = "com.github.ben-manes.versions", version = "0.51.0" } @@ -25,4 +29,4 @@ kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } compose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" } -jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlinVersion" } +jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }