Skip to content

Commit a75cba8

Browse files
authored
iOS project sample with Xcodegen (#44)
1 parent 66a0742 commit a75cba8

File tree

12 files changed

+134
-87
lines changed

12 files changed

+134
-87
lines changed

buildSrc/src/main/kotlin/Setup.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ private fun BaseExtension.android() {
2020

2121
fun Project.kotlinMultiplatform(
2222
withKotlinExplicitMode: Boolean = true,
23-
iosPrefixName: String = "ios", // only used in ios sample
2423
) {
2524
plugins.withType<org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper> {
2625
extensions.configure<KotlinMultiplatformExtension> {
@@ -44,8 +43,8 @@ fun Project.kotlinMultiplatform(
4443
}
4544
macosX64()
4645
macosArm64()
47-
ios(iosPrefixName)
48-
iosSimulatorArm64("${iosPrefixName}SimulatorArm64")
46+
ios()
47+
iosSimulatorArm64()
4948

5049
sourceSets {
5150
/* Source sets structure
@@ -86,10 +85,10 @@ fun Project.kotlinMultiplatform(
8685
val macosArm64Main by getting {
8786
dependsOn(macosMain)
8887
}
89-
val iosMain = getByName(iosPrefixName + "Main").apply {
88+
val iosMain by getting {
9089
dependsOn(nativeMain)
9190
}
92-
val iosSimulatorArm64Main = getByName(iosPrefixName + "SimulatorArm64Main").apply {
91+
val iosSimulatorArm64Main by getting {
9392
dependsOn(iosMain)
9493
}
9594
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LyricistSample.xcodeproj

sample-multiplatform-ios/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# sample-multiplatform-ios
2+
3+
## Running
4+
- Generate the xcodeproj by using [Xcodegen](https://github.com/yonaskolb/XcodeGen)
5+
- Open the project (or run `xed .`)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
<?xml version="1.0" encoding="UTF-8"?>
3+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4+
<plist version="1.0">
5+
<dict>
6+
<key>CFBundleDevelopmentRegion</key>
7+
<string>$(DEVELOPMENT_LANGUAGE)</string>
8+
<key>CFBundleExecutable</key>
9+
<string>$(EXECUTABLE_NAME)</string>
10+
<key>CFBundleIdentifier</key>
11+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
12+
<key>CFBundleInfoDictionaryVersion</key>
13+
<string>6.0</string>
14+
<key>CFBundleName</key>
15+
<string>$(PRODUCT_NAME)</string>
16+
<key>CFBundlePackageType</key>
17+
<string>APPL</string>
18+
<key>CFBundleShortVersionString</key>
19+
<string>1.0</string>
20+
<key>CFBundleVersion</key>
21+
<string>1</string>
22+
<key>UILaunchStoryboardName</key>
23+
<string>ComposeSample</string>
24+
</dict>
25+
</plist>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
<key>UILaunchStoryboardName</key>
22+
<string>LyricistSample</string>
23+
</dict>
24+
</plist>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: LyricistSample
2+
options:
3+
bundleIdPrefix: cafe.adriel.lyricist.sample
4+
settings:
5+
6+
CODE_SIGN_IDENTITY: "iPhone Developer"
7+
CODE_SIGN_STYLE: Automatic
8+
MARKETING_VERSION: "1.0"
9+
CURRENT_PROJECT_VERSION: "4"
10+
SDKROOT: iphoneos
11+
targets:
12+
LyricistSample:
13+
type: application
14+
platform: iOS
15+
deploymentTarget: "14.0"
16+
info:
17+
path: plists/Ios/Info.plist
18+
properties:
19+
UILaunchStoryboardName: LyricistSample
20+
settings:
21+
LIBRARY_SEARCH_PATHS: "$(inherited)"
22+
ENABLE_BITCODE: "YES"
23+
ONLY_ACTIVE_ARCH: "NO"
24+
VALID_ARCHS: "arm64"
25+
sources:
26+
- path: src
27+
excludes:
28+
- "**/.gitkeep"
29+
preBuildScripts:
30+
- name: Build KMP
31+
script: |
32+
cd ../
33+
./gradlew :sample-multiplatform:embedAndSignAppleFrameworkForXcode
34+
dependencies:
35+
- framework: "../sample-multiplatform/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)/ComposeShared.framework"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import UIKit
2+
import SwiftUI
3+
import ComposeShared
4+
5+
struct ComposeView: UIViewControllerRepresentable {
6+
func makeUIViewController(context: Context) -> UIViewController {
7+
MainViewControllerKt.MainViewController()
8+
}
9+
10+
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
11+
}
12+
13+
struct ContentView: View {
14+
var body: some View {
15+
ComposeView()
16+
.ignoresSafeArea(.keyboard) // Compose has own keyboard handler
17+
}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import SwiftUI
2+
3+
@main
4+
struct iOSApp: App {
5+
var body: some Scene {
6+
WindowGroup {
7+
ContentView()
8+
}
9+
}
10+
}

sample-multiplatform/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# multiplatform sample
22

3-
### Running iOS
4-
- IPhone: `./gradlew :sample-multiplatform:iosDeployIPhone8Debug`
5-
- IPad: `./gradlew :sample-multiplatform:iosDeployIPadDebug`
6-
73
### Running MacOS Native app (Desktop using Kotlin Native)
84
```shell
95
./gradlew :sample-multiplatform:runNativeDebug

sample-multiplatform/build.gradle.kts

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat.Deb
33
import org.jetbrains.compose.desktop.application.dsl.TargetFormat.Dmg
44
import org.jetbrains.compose.desktop.application.dsl.TargetFormat.Msi
55
import org.jetbrains.compose.desktop.application.tasks.AbstractNativeMacApplicationPackageTask
6-
// import org.jetbrains.compose.experimental.dsl.IOSDevices
76
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
87
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
98

@@ -16,8 +15,6 @@ plugins {
1615

1716
kotlinMultiplatform(
1817
withKotlinExplicitMode = false,
19-
// this is required for the Compose iOS Application DSL expect a `uikit` target name.
20-
iosPrefixName = "uikit",
2118
)
2219

2320
android {
@@ -40,21 +37,16 @@ kotlin {
4037
}
4138
macosX64(macOsConfiguation)
4239
macosArm64(macOsConfiguation)
43-
val uikitConfiguration: KotlinNativeTarget.() -> Unit = {
44-
binaries {
45-
executable() {
46-
entryPoint = "main"
47-
freeCompilerArgs += listOf(
48-
"-linker-option", "-framework", "-linker-option", "Metal",
49-
"-linker-option", "-framework", "-linker-option", "CoreText",
50-
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
51-
)
52-
}
40+
listOf(
41+
iosX64(),
42+
iosArm64(),
43+
iosSimulatorArm64()
44+
).forEach { iosTarget ->
45+
iosTarget.binaries.framework {
46+
baseName = "ComposeShared"
47+
isStatic = true
5348
}
5449
}
55-
iosX64("uikitX64", uikitConfiguration)
56-
iosArm64("uikitArm64", uikitConfiguration)
57-
iosSimulatorArm64("uikitSimulatorArm64", uikitConfiguration)
5850

5951
js(IR) {
6052
browser()
@@ -161,17 +153,5 @@ afterEvaluate {
161153
}
162154

163155
compose.experimental {
164-
// uikit.application {
165-
// bundleIdPrefix = "cafe.adriel.lyricist"
166-
// projectName = "MultiplatformSample"
167-
// /*deployConfigurations {
168-
// simulator("IPhone8") {
169-
// device = IOSDevices.IPHONE_8
170-
// }
171-
// simulator("IPad") {
172-
// device = IOSDevices.IPAD_MINI_6th_Gen
173-
// }
174-
// }*/
175-
// }
176156
web.application {}
177157
}

0 commit comments

Comments
 (0)