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
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
250
Meet the Translation API
akkie76
0
500
コードレビューで開発を加速させるAIコードレビュー
akkie76
1
760
Android Target SDK 35 (Android 15) 対応の概要
akkie76
0
6.2k
コードレビューを支援するAI技術の応用
akkie76
5
1.3k
オブジェクト指向コードレビューの新しいアプローチ
akkie76
3
10k
Jetpack Compose で Adaptive Layout に対応しよう
akkie76
0
1.2k
Observationではじめる値監視
akkie76
4
4.9k
TextField 表示スタイル変更の 有効活用例 5 選
akkie76
0
790
Other Decks in Technology
See All in Technology
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
24k
今こそ聞きたいソフトウェア設計 ドメイン駆動設計再入門
masuda220
PRO
17
6.8k
Master Dataグループ紹介資料
sansan33
PRO
1
4.8k
Webアクセシビリティ入門 2026
recruitengineers
PRO
2
460
もう一度考える SRE チームの作り方・育て方 / Rethinking SRE #1: Building and Growing SRE Teams
rrreeeyyy
6
1k
つくって納得、つかって実感! 大規模言語モデルことはじめ ver2.0
recruitengineers
PRO
3
1.2k
【CEDEC2026】ゲームシナリオライターを支援するAIツール開発の実践 ― 設計とプロンプトの工夫 ―
cygames
PRO
1
770
20260807_第6回_関東kaggler会LT_claw系bot xangiと始める、"寂しくない" kaggle
sugupoko
0
200
クラウドセキュリティ入門 ~安全なクラウド利用のための基礎知識~
lhazy
12
8.4k
AI ネイティブな組織に Gemini Enterprise Agent Platform がなぜ必要なのか
asei
1
190
制約理論(ToC)入門 2026版
recruitengineers
PRO
6
2k
【CEDEC2026】専門性の高いデフォルメチームが挑んだ人材育成戦略 〜Cygames Academiaの企画から実施まで〜
cygames
PRO
0
530
Featured
See All Featured
Paper Plane
katiecoart
PRO
2
52k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
200
Un-Boring Meetings
codingconduct
0
380
The Art of Programming - Codeland 2020
erikaheidi
57
14k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
620
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
400
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
690
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
360
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
360
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
From π to Pie charts
rasagy
0
260
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 ご静聴ありがとうございました