Initial commit

This commit is contained in:
2024-02-14 15:55:36 -03:00
commit 25858413c5
30 changed files with 1209 additions and 0 deletions

42
shared/build.gradle.kts Normal file
View File

@@ -0,0 +1,42 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
}
kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "shared"
isStatic = true
}
}
sourceSets {
commonMain.dependencies {
//put your multiplatform dependencies here
}
commonTest.dependencies {
implementation(libs.kotlin.test)
}
}
}
android {
namespace = "cl.carlost.kmpexcercises"
compileSdk = 34
defaultConfig {
minSdk = 24
}
}

View File

@@ -0,0 +1,7 @@
package cl.carlost.kmpexcercises
class AndroidPlatform : Platform {
override val name: String = "Android ${android.os.Build.VERSION.SDK_INT}"
}
actual fun getPlatform(): Platform = AndroidPlatform()

View File

@@ -0,0 +1,12 @@
package cl.carlost.kmpexcercises
import org.junit.Assert.assertTrue
import org.junit.Test
class AndroidGreetingTest {
@Test
fun testExample() {
assertTrue("Check Android is mentioned", Greeting().greet().contains("Android"))
}
}

View File

@@ -0,0 +1,9 @@
package cl.carlost.kmpexcercises
class Greeting {
private val platform: Platform = getPlatform()
fun greet(): String {
return "Hello, ${platform.name}!"
}
}

View File

@@ -0,0 +1,7 @@
package cl.carlost.kmpexcercises
interface Platform {
val name: String
}
expect fun getPlatform(): Platform

View File

@@ -0,0 +1,12 @@
package cl.carlost.kmpexcercises
import kotlin.test.Test
import kotlin.test.assertTrue
class CommonGreetingTest {
@Test
fun testExample() {
assertTrue(Greeting().greet().contains("Hello"), "Check 'Hello' is mentioned")
}
}

View File

@@ -0,0 +1,9 @@
package cl.carlost.kmpexcercises
import platform.UIKit.UIDevice
class IOSPlatform: Platform {
override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
}
actual fun getPlatform(): Platform = IOSPlatform()

View File

@@ -0,0 +1,12 @@
package cl.carlost.kmpexcercises
import kotlin.test.Test
import kotlin.test.assertTrue
class IosGreetingTest {
@Test
fun testExample() {
assertTrue(Greeting().greet().contains("iOS"), "Check iOS is mentioned")
}
}