Upgrade to Pro — share decks privately, control downloads, hide ads and more …

KMMでマルチプラットフォーム開発を始めよう

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

 KMMでマルチプラットフォーム開発を始めよう

Avatar for akkiee76

akkiee76

June 10, 2023
Tweet

More Decks by akkiee76

Other Decks in Technology

Transcript

  1. ランチタイムLT会 #1 Akihiko Sato / 株式会社ラクス Lead Engineer / @akkiee76

    SaaS 開発 (Backend, Frontend) / Mobile 開発 (iOS, Android) 上流工程、コードレビュー、チームの課題改善など コールドブリューコーヒー☕ / パン作り🍞 / あんバターフランス🥐 自己紹介
  2. ランチタイムLT会 #1 クロスプラットフォーム開発とは? メリット ・ 開発 / メンテコストの削減 👑 デメリット

    ・ ネイティブアプリ固有の機能が実装しにくい     ・ プラグインが必要だったり・・・    ・ UIがネイティブに劣る
  3. ランチタイムLT会 #1 KMM開発に必要な環境 ・ macOS ・ Android Studio ・ Xcode

    ・ JDK ・ Kotlin Multiplatform Mobile plugin ・ Kotlin plugin あとは brew install kdoctor を実行するだけ brew install kdoctor
  4. ランチタイムLT会 #1 KMMによって出力されたコード(Android) class MainActivity : ComponentActivity() { override fun

    onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MyApplicationTheme { Surface( modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background ) { GreetingView(Greeting().greet()) } } } } } @Composable fun GreetingView(text: String) { Text(text = text) } MainActivity.kt
  5. ランチタイムLT会 #1 KMMによって出力されたコード(iOS) ContentView.swift import SwiftUI import shared struct ContentView:

    View { let greet = Greeting().greet() var body: some View { Text(greet) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
  6. ランチタイムLT会 #1 KMMによって出力されたコード(iOS) Shared.h __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("Greeting"))) @interface SharedGreeting : SharedBase

    - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); - (NSString *)greet __attribute__((swift_name("greet()"))); @end
  7. ランチタイムLT会 #1 KMMによって出力されたコード(shared) /commonMain/kotlin class Greeting { private val platform:

    Platform = getPlatform() fun greet(): String { return "Hello, ${platform.name}!" } } interface Platform { val name: String } expect fun getPlatform(): Platform class IOSPlatform: Platform { override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion } actual fun getPlatform(): Platform = IOSPlatform() class AndroidPlatform : Platform { override val name: String = "Android ${android.os.Build.VERSION.SDK_INT}" } actual fun getPlatform(): Platform = AndroidPlatform() /iosMain/kotlin /kotlin
  8. ランチタイムLT会 #1 個人的な初感 ・ Jetpack Compose、Swift UI といったモダンフレームワークが採用 ・ Kotlinで実装する共通ロジックは、柔軟に設計ができる

    ・ Android、iOS 両方のアーキテクチャの知見が必要 ・ これまでのマルチプラットフォーム開発より難易度高い印象 ・ 使いこなせたら生産性が爆上がりしそう