Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Compose MutiPlatformで始めるクロスプラットフォーム開発(ライブラリ編)
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
akkiee76
July 15, 2023
Technology
1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Compose MutiPlatformで始めるクロスプラットフォーム開発(ライブラリ編)
Shibuya.apk #43 で発表した資料になります。
https://shibuya-apk.connpass.com/event/288211/
akkiee76
July 15, 2023
More Decks by akkiee76
See All by akkiee76
Graph Art with Charts API – Beyond Data Visualization
akkie76
0
240
Meet the Translation API
akkie76
0
490
コードレビューで開発を加速させるAIコードレビュー
akkie76
1
730
Android Target SDK 35 (Android 15) 対応の概要
akkie76
0
6.2k
コードレビューを支援するAI技術の応用
akkie76
5
1.3k
オブジェクト指向コードレビューの新しいアプローチ
akkie76
3
9.9k
Jetpack Compose で Adaptive Layout に対応しよう
akkie76
0
1.2k
Observationではじめる値監視
akkie76
4
4.9k
TextField 表示スタイル変更の 有効活用例 5 選
akkie76
0
780
Other Decks in Technology
See All in Technology
気づかぬうちにセキュリティ負債を生むAPIキー運用
sgwrmctk
0
180
【NRUG vol.18】なぜ多くのオブザーバビリティ導入は失敗するのか
nrug_member
0
190
小さく始める AI 活用推進 ― 日経電子版 Web チームの事例/nikkei-tech-talk47
nikkei_engineer_recruiting
0
300
[チョークトーク資料]AWS DevOps Agent を使いこなす / AWS Dev Ops Agent Chalk Talk AWS Summit Japan 2026
kinunori
2
510
失敗を資産に変えるClaude Code
shinyasaita
0
710
白金鉱業Meetup_Vol.24_「AIエージェントは分けるほど良い」は本当か? / Is it true that “the more you divide AI agents, the better”?
brainpadpr
1
410
エラーバジェットのアラートのタイミングを考える.pdf
kairim0
0
170
いまさら聞けない「仕様駆動開発入門」 〜AI活用時代の開発プロセスを考える〜
findy_eventslides
2
160
自宅LLMの話
jacopen
1
610
【セミナー資料】Claude Code をセキュアに使うための考え方と設定の勘どころ / Claude Code Webinar 20260616
masahirokawahara
2
410
ザ・データベース、MySQL ~ OSC 2026 Sendai ~
sakaik
0
130
Oracle AI Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
6
1.5k
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
37
7.3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
BBQ
matthewcrist
89
10k
The Curse of the Amulet
leimatthew05
1
13k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
150
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Code Review Best Practice
trishagee
74
20k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
From π to Pie charts
rasagy
0
210
GraphQLとの向き合い方2022年版
quramy
50
15k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
480
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Transcript
Shibuya.apk #43 ©2023 RAKUS Co., Ltd. Compose MultiPlatformで 始めるクロスプラットフォーム開発 ライブラリ編
@akkiee76 Shibuya.apk #43
Shibuya.apk #43 Akihiko Sato / 株式会社ラクス Lead Engineer / @akkiee76
SaaS 開発 (Backend, Frontend) / Mobile 開発 (iOS, Android) 上流工程、コードレビュー、チームの課題改善など コールドブリューコーヒー☕ / パン作り🍞 / あんバターフランス🥐 自己紹介
Shibuya.apk #43 今日伝えたいこと Compose MultiPlatform で開発で主軸となる ライブラリの紹介
Shibuya.apk #43 Kotlin Multiplatform for Mobile (KMM) JetBrainsが開発したKotlinベースのクロスプラットフォーム 開発フレームワーク。1つの共通のKotlinコードベースを使用して、 iOSとAndroidの両方のプラットフォーム向けにネイティブアプリを
開発することができる点が特徴。
Shibuya.apk #43 Kotlin Multiplatform for Mobile (KMM) フレームワークイメージ
Shibuya.apk #43 Kotlin Multiplatform for Mobile (KMM) アーキテクチャイメージ Compose Multiplatform
Shibuya.apk #43 Compose MultiPlatform Compose Multiplatformは、Kotlinを使用して複数のプラットフォーム間でUI を共有するための宣言的なフレームワークです。JetBrainsとオープンソースの貢献 者によって開発され、Jetpack Composeに基づいています。 https://github.com/JetBrains/compose-multiplatform
Shibuya.apk #43 ここからは導入手順を紹介します
Shibuya.apk #43 開発に必要な環境 ・ macOS ・ Android Studio ・ Xcode
・ JDK ・ Kotlin Multiplatform Mobile plugin ・ Kotlin plugin ・ CocoaPods dependency manager あとは brew install kdoctor を実行するだけ
Shibuya.apk #43 プロジェクト作成 * Desktop版はIntelliJから作成可能
Shibuya.apk #43 プロジェクト作成(Compose Multiplatform Wizard) https://terrakok.github.io/Compose-Multiplatform-Wizard/
Shibuya.apk #43 プロジェクトビルド androidx.compose.material3 に対応
Shibuya.apk #43 基本的なライブラリ選定 16種類のライブラリが選択可能
Shibuya.apk #43 開発の主軸になるライブラリの紹介 ・ Voyager (navigation) ・ Ktrofit (HTTP client)
・ Koin (dependency injection) ・ SQLDelight (SQL)
Shibuya.apk #43 navigation 事情 navigation-composeはサポートされていなかった。。 https://github.com/JetBrains/compose-multiplatform/tree/master/tutorials/Navigation
Shibuya.apk #43 Voyager Screen クラスを継承して Content を作成します。 class PostListScreen :
Screen { @Composable override fun Content() { // ... } } data class PostDetailsScreen(val postId: Long) : Screen { @Composable override fun Content() { // ... } }
Shibuya.apk #43 Voyager LocalNavigator.currentOrThrow を使用して画面遷移することが可能。 class PostListScreen : Screen {
@Composable override fun Content() { // ... } @Composable private fun PostCard(post: Post) { val navigator = LocalNavigator.currentOrThrow Card( modifier = Modifier.clickable { navigator.push(PostDetailsScreen(post.id)) // Also works: } ) { // ... } } }
Shibuya.apk #43 Voyager TopAppBar、BottomNavigationにも対応しており、 navigation-composeのように実装することで実現可能。 @Composable override fun Content() {
Navigator(HomeScreen) { navigator -> Scaffold( topBar = { /* ... */ }, content = { CurrentScreen() }, bottomBar = { /* ... */ } ) } }
Shibuya.apk #43 Ktrofit RetrofitのようなAPIで 実装することが可能。 https://foso.github.io/Ktorfit/ interface UnsplashService { @GET("search/photos")
suspend fun searchPhotos( @Query("query") query: String, @Query("page") page: Int = 1, @Query("per_page") perPage: Int = 1, @Query("client_id") clientId: String = "clientId" ): UnsplashSearchResponse companion object { private const val BASE_URL = "https://api.unsplash.com/" fun create(): UnsplashService { return ktorfit { baseUrl(BASE_URL) httpClient(HttpClient { install(ContentNegotiation) { json(Json { isLenient = true; ignoreUnknownKeys = true }) } }) converterFactories( FlowConverterFactory(), CallConverterFactory() ) }.create() } } }
Shibuya.apk #43 Ktrofit (serialization) レスポンスをserializeするため、 kotlinx-serializationも同時に導入します。 https://github.com/Kotlin/kotlinx.serialization import kotlinx.serialization.SerialName import
kotlinx.serialization.Serializable @Serializable data class UnsplashUser( val id: String, val name: String, val username: String, val bio: String?, @SerialName("profile_image") val profileImage: UnsplashProfileImage?, )
Shibuya.apk #43 Koin (dependency injection) injectionするmoduleを定義します。 iOSとAndroidのそれぞれで定義する必要があります。 https://insert-koin.io/docs/reference/koin-mp/kmp/ private val
searchViewModel = module { singleOf(::SearchViewModel) } private val searchRepository = module { singleOf(::SearchRepository) } fun appModule() = listOf(searchViewModel, searchRepository) // for iOS fun initKoin() { startKoin { modules(appModule()) } } // for Android fun initKoin(appDeclaration: KoinAppDeclaration = {}) = startKoin { appDeclaration() modules(appModule()) }
Shibuya.apk #43 Koin (dependency injection) Android Applicationクラスに初期化実装を行います。 https://insert-koin.io/docs/reference/koin-mp/kmp/ class MainApplication:
Application(), KoinComponent { override fun onCreate() { super.onCreate() initKoin { androidContext(this@MainApplication) } } } class MainActivity : AppCompatActivity() { private val searchViewModel: SearchViewModel by inject() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MainView(searchViewModel) } } }
Shibuya.apk #43 Koin (dependency injection) iOS Appクラスに初期化実装を行います。 https://insert-koin.io/docs/reference/koin-mp/kmp/ @main struct
iOSApp: App { init() { AppModuleKt.initKoin() } var body: some Scene { WindowGroup { // content } } } struct ContentView: View { private let searchViewModel = AppModule().getSearchViewModel() var body: some View { // content } }
Shibuya.apk #43 .sqファイルでクエリを定義することで、 実装コードからSQLが実行可能になります。 SQLDelight (SQL) selectAll: SELECT * FROM
hockeyPlayer; insert: INSERT INTO hockeyPlayer(player_number, full_name) VALUES (?, ?); insertFullPlayerObject: INSERT INTO hockeyPlayer(player_number, full_name) VALUES ?; val database = Database(driver) val playerQueries: PlayerQueries = database.playerQueries println(playerQueries.selectAll().executeAsList()) // Prints [HockeyPlayer(15, "Ryan Getzlaf")] playerQueries.insert(player_number = 10, full_name = "Corey Perry") println(playerQueries.selectAll().executeAsList()) // Prints [HockeyPlayer(15, "Ryan Getzlaf"), HockeyPlayer(10, "Corey Perry")] val player = HockeyPlayer(10, "Ronald McDonald") playerQueries.insertFullPlayerObject(player)
Shibuya.apk #43 まとめ ・ Compose Multiplatform Wizard を利用することで、 簡単にライブラリ設定ができる! ・
まだまだ使い勝手が悪い点もあるが今後のアップデートに期待!
Shibuya.apk #43 ご静聴ありがとうございました