Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Kotlin/MPP getting started and troubles
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Masaya Yashiro
March 27, 2019
Programming
4.3k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kotlin/MPP getting started and troubles
Masaya Yashiro
March 27, 2019
Transcript
52 slides
Kotlin/MPPでX-PF 事始めのつまづきポイント 2019-03-27 どこでもKotlin #7 @yashims85
誰? 名前: 屋代昌也 会社: 株式会社モバイルファクトリー Twitter: @yashims85 Github: yashims
None
Mobile Factoryではエンジニアを募集し ています。 位置ゲーやBlockChainにご興味のある かたはぜひお声がけください!
そもそもなんでKotlin/MPP触りだ したのか?
それはね、 READMEにこう記されてい るわ
遥か悠久の昔、cocos2dxのプロジェクトがあった。 cocos2dxのプロジェクトはたいそう荒ぶり、ついには android-Appとios-Appという2 つのリポジトリを生み眠りについた。 cocos2dxより生まれし2つのリポジトリは数刻の後に空を作り海を作り大地を作っ た。 やがて人々が生まれ、彼らはこの厳しくも儚い大地に根を下ろしその繁栄を謳歌した のである。 時は今、天は唸り、地は裂け、この厳しくも儚い世界はまさに終わりを迎えようとして いた。
人々は思い出したのである。彼らが在る天地は荒ぶる cocos2dxの仔によって 創造されたことを。 そして人々はついに決意する。彼らを育てた天地を離れ、安住の地へ旅立つことを。
いい感じにクライアントサイドをリプレイスし たい! 現在絶賛リプレイス中ですが、今回はその中で得られ た気づきや知見を共有します。
Kotlin/MPP 構成がわからない問題
今Kotlin/MPPでやっている事 • Android/iOSのクライアントアプリ開発 • Kotlin/MPPでつかえるプレゼンテーションルーター ライブラリ開発
クライアントアプリ • 長期運用タイトルのクライアントサイドのリプレース • Kotlin/MPPを使用してクライアントのビジネスロジック を共通化する
クライアントアー キテクチャ
KoRouter • Kotlin/MPPで書かれたクライアントサイドのプレゼン テーションルーター • VueRouterみたいなものを作りたい • 現在絶賛開発中 • https://github.com/yashims/kotlin-router
KoRouterの使い方 private val router: KoRouter = KoRouter { route("") {
name = "" component = this@MainActivity children { route("/") { name = "top" component = TopFragment() } route("gallery") { name = "gallery" component = GalleryFragment() children { route(":detail") { name = "detail" component = GalleryDialogFragment() } } } } } }
KoRouterの使い方 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) router.push("/") }
KoRouterの構成 • commonMain • jvmMain • iosMain の3つからなる
KoRouterの構成 - 共通部分 commonMain • 共通コード • 成果物はmetadata • metadataだけでは何もできず、IDEなどがシンボルを追
うために使うはず。
KoRouterの構成 - Android部分 jvmMain • JVM向けコード • 成果物が.jarなのでAndroidはこれを使う
KoRouterの構成 - iOS部分 iosMain • Native向けコード • .frameworkが成果物なのでiOSではこれをつかう
ではクライアントアプリも同じ構成で 作れるのか
答えはNO
AndroidのPFに依存するコードが 出てくるので、.jarでの提供では役 不足になってくる
クライアントアプリの構成 • commonMain • jvmMain -> androidMain ◦ JVM向けのサブセットと考えて良い •
iosMain • main
mainとは?
クライアントアプリの構成 - main • Androidの依存を使うためにcom.android.libraryの pluginを使用する • Androidのbuildには、何もしなければsrc/mainの中に AndroidManifest.xmlを置く必要がある •
.aarの成果物ができる • ごにょってandroidMainに統合するのが妥当
構成比較 KoRouter • commonMain • jvmMain • isoMain クライアントアプリ •
commonMain • androidMain • iosMain • main -> androidMainへ混入
目的によってプロジェクトの構成 が変わる!
dependenciesわからない問題
さて、今から皆さんにcoroutines 関連のライブラリ名の一覧をお見 せします。 それぞれ何をするライブラリかわかりますでしょうか?
coroutine関連のライブラリ • kotlinx-coroutines-core-common • kotlinx-coroutines-core • kotlinx-coroutines-android • kotlinx-coroutines-core-native •
kotlinx-coroutines-core-js
答え:
common用 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.1.1'
jvm用 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
android用 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
ios用 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.1.1'
js用 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.1.1'
全部同じ事をするための ライブラリ
構成によってdependenciesが違う • 言語的に可能でも実行環境によって不可能だったり、よ り適切な処理があったりする • 例えばcoroutineはThreadProgrammingをサポートす るが、Androidの場合メインスレッドのとり方がAndroid 用のものになったり
そんな課題を乗り越えて CoroutineのGettingStartedを やっているとある問題に直面する
GettingStarted fun hoge() { runBlocking { delay(200L) } } commonMain/kotlin/Sample.kt
GettingStartedに記載されてる runBlockingが無い!
試しにこの状態でBuildを通してみると 通る!
jvmMainに移してみる fun hoge() { runBlocking { delay(200L) } } jvmMain/kotlin/Sample.kt
通る!
最初はdependenciesを疑ったが… • commonで通らないのは、なにか別のdependenciesを 入れる必要があるのではと考えた • でも実際はそういう仕様だった • runBlockingの動作がjsで実現出来ないために commonで使えないようになっている •
あくまでmetadataにリファレンスが無いだけなので、書 いておけばjvmやnativeでbuildすることはできる
kotlinxわからない問題
たとえばcoroutineなら、 GettingStartedをやれば、なん やかんやでcoroutineを完全理解 した状態になれる
KotlinのCoroutine完全に理解した • CoroutineScope <- 見ないようにしてる • チャネル <- 見ないようにしている •
kotlinx-coroutines-reactive <- 見ないようにしてる • kotlinx-coroutines-reactor <- 見ないようにしてる
KotlinのCoroutineがちょっとできるよ うになるためには、何をみたら良いか知見 がある人教えてください… Goroutineのドキュメントあたり参考になるのか?とは考えて る。
コードのエントロピーが増大する問 題
コードのエントロピー増大問題 • イレギュラーな事態になってもKotlinはなんとか出来てし まうパワフルさがある • そのパワフルさに依存するとエントロピーが増大していく • 結局適切な抽象化ときれいな設計を行うことに尽きる • きれいな設計を行うと、イレギュラーに遭遇すること事態
が少なくなる • 今回挙げたような問題にも対処しやすくなる
まとめ
まとめ • 目的によって構成を変えよう • なにが同じライブラリかは何処かにまとめておこう • GettingStarted通りに出来なくても泣かない • kotlinxわからん •
設計大事
Thank You!
More Decks by Masaya Yashiro
See All by Masaya Yashiro
拡大期を迎えたプロダクトに起きたこと - Android編
yashims
0
640
How useful Kotlin/Native in Kotlin 1.3
yashims
0
470
UX design trend 2019
yashims
5
1.7k
C# code refactoring with Scope Functions
yashims
0
3k
ココがダメだよWebCamTexture
yashims
0
150
Introduction of MaterialDesign for engineer
yashims
0
130
Other Decks in Programming
See All in Programming
複数ドメインを一つのアプリに統合するFlutterの設計と運用_FlutterKaigi2026登壇資料(須永高弘)
takahirosunaga
0
180
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
170
SODA - FACT BOOK(JP)
sodainc
1
40k
Python Lambdaにおけるテストしやすい設計とAI支援の活用 / Designing Testable Python Lambda Functions with AI
kitano_yuichi
1
320
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
610
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
290
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
250
React Native에 현대적인 빌드 도구 더하기: Rollipop 구현기
leegeunhyeok
0
180
Claude Code ハーネスDeep Dive – 君はどこまで制御する? -
takateeen_knj
6
5.6k
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
180
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
210
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.3k
Featured
See All Featured
Designing Powerful Visuals for Engaging Learning
tmiket
1
650
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
30 Presentation Tips
portentint
PRO
1
470
Rails Girls Zürich Keynote
gr2m
96
14k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Crafting Experiences
bethany
1
440
The World Runs on Bad Software
bkeepers
PRO
72
12k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
310
How to build a perfect <img>
jonoalderson
1
6.2k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k