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
500
コードレビューで開発を加速させるAIコードレビュー
akkie76
1
740
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
しくみを学んで使いこなそう GitHub Copilot app
torumakabe
2
290
アップデートで何が変わった?デモで学んで使いこなすIBM Bob2.0
muehara
0
130
AI Driven AI Governance
pict3
0
490
AI時代の開発生産性は、個人技からチーム設計へ
moongift
PRO
4
2.4k
ヘルスケア領域における AI 活用と その安全性担保のための取り組み (Leveraging AI in Healthcare and Our Efforts to Ensure Its Safety) - Google I/O Extended Tokyo 2026, July 11, 2026
zettaittenani
0
430
型は壁、Rustでもバグを直すな、表現できなくせよ
nwiizo
14
2.1k
CSに"SLO"は要らない、経営層に"99.9%"は伝わらない - SREを全社に"翻訳"する3原則
cscengineer
PRO
1
5.1k
個人開発で育てる「大規模設計の苗床」 - AI時代の1人開発から始める業務への知識接続 / The Seedbed for Large-Scale Design - From AI-Era Solo Projects to Professional Knowledge
bitkey
PRO
1
280
タスクの複雑さでモデルを選ぶ ── Thompson Samplingで動かす“トークン/コスト最適化
satohy0323
0
570
AIコード生成×サプライチェーン攻撃 — PHPが直面する“二重の信頼問題
shinyasaita
0
210
プロダクト開発組織の現在地(Ver.2026/07) / product-organization
kaonavi
0
110
OPENLOGI Company Profile for engineer
hr01
1
74k
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5.1k
Faster Mobile Websites
deanohume
310
32k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
410
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.2k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
630
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
450
Odyssey Design
rkendrick25
PRO
2
730
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 ご静聴ありがとうございました