Compose Multiplatform Mobile project template
This commit is contained in:
76
shared/build.gradle.kts
Normal file
76
shared/build.gradle.kts
Normal file
@@ -0,0 +1,76 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
kotlin("native.cocoapods")
|
||||
id("com.android.library")
|
||||
id("org.jetbrains.compose")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
android()
|
||||
|
||||
iosX64()
|
||||
iosArm64()
|
||||
iosSimulatorArm64()
|
||||
|
||||
cocoapods {
|
||||
version = "1.0.0"
|
||||
summary = "Some description for the Shared Module"
|
||||
homepage = "Link to the Shared Module homepage"
|
||||
ios.deploymentTarget = "14.1"
|
||||
podfile = project.file("../iosApp/Podfile")
|
||||
framework {
|
||||
baseName = "shared"
|
||||
isStatic = true
|
||||
}
|
||||
extraSpecAttributes["resources"] = "['src/commonMain/resources/**', 'src/iosMain/resources/**']"
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation(compose.runtime)
|
||||
implementation(compose.foundation)
|
||||
implementation(compose.material)
|
||||
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
|
||||
implementation(compose.components.resources)
|
||||
}
|
||||
}
|
||||
val androidMain by getting {
|
||||
dependencies {
|
||||
api("androidx.activity:activity-compose:1.6.1")
|
||||
api("androidx.appcompat:appcompat:1.6.1")
|
||||
api("androidx.core:core-ktx:1.9.0")
|
||||
}
|
||||
}
|
||||
val iosX64Main by getting
|
||||
val iosArm64Main by getting
|
||||
val iosSimulatorArm64Main by getting
|
||||
val iosMain by creating {
|
||||
dependsOn(commonMain)
|
||||
iosX64Main.dependsOn(this)
|
||||
iosArm64Main.dependsOn(this)
|
||||
iosSimulatorArm64Main.dependsOn(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdk = (findProperty("android.compileSdk") as String).toInt()
|
||||
namespace = "com.myapplication.common"
|
||||
|
||||
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
|
||||
sourceSets["main"].res.srcDirs("src/androidMain/res")
|
||||
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
|
||||
|
||||
defaultConfig {
|
||||
minSdk = (findProperty("android.minSdk") as String).toInt()
|
||||
targetSdk = (findProperty("android.targetSdk") as String).toInt()
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
kotlin {
|
||||
jvmToolchain(11)
|
||||
}
|
||||
}
|
2
shared/src/androidMain/AndroidManifest.xml
Normal file
2
shared/src/androidMain/AndroidManifest.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest />
|
5
shared/src/androidMain/kotlin/main.android.kt
Normal file
5
shared/src/androidMain/kotlin/main.android.kt
Normal file
@@ -0,0 +1,5 @@
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
actual fun getPlatformName(): String = "Android"
|
||||
|
||||
@Composable fun MainView() = App()
|
23
shared/src/commonMain/kotlin/App.kt
Normal file
23
shared/src/commonMain/kotlin/App.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
|
||||
@Composable
|
||||
internal fun App() {
|
||||
MaterialTheme {
|
||||
var text by remember { mutableStateOf("Hello, World!") }
|
||||
|
||||
Button(onClick = {
|
||||
text = "Hello, ${getPlatformName()}"
|
||||
}) {
|
||||
Text(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect fun getPlatformName(): String
|
5
shared/src/iosMain/kotlin/main.ios.kt
Normal file
5
shared/src/iosMain/kotlin/main.ios.kt
Normal file
@@ -0,0 +1,5 @@
|
||||
import androidx.compose.ui.window.ComposeUIViewController
|
||||
|
||||
actual fun getPlatformName(): String = "iOS"
|
||||
|
||||
fun MainViewController() = ComposeUIViewController { App() }
|
Reference in New Issue
Block a user