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
Masaya Yashiro
March 27, 2019
Programming
4.2k
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
More Decks by Masaya Yashiro
See All by Masaya Yashiro
拡大期を迎えたプロダクトに起きたこと - Android編
yashims
0
630
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
140
Introduction of MaterialDesign for engineer
yashims
0
120
Other Decks in Programming
See All in Programming
Webの地図
yosuke_furukawa
PRO
6
5k
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
630
Verilogで学ぶCPU自作入門.pdf
uyuki234
7
3.9k
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
250
JRuby: Past, Present, and Future
headius
0
210
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
330
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
30
13k
一人だけ、Kiroが静止する日
hideg
0
140
The Rails Doctrine Decade
koic
2
430
App Intentsのビルドプロセスを支える技術
kntkymt
0
480
Heart of Swift Concurrency
koher
0
1.1k
Featured
See All Featured
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
30 Presentation Tips
portentint
PRO
1
410
How GitHub (no longer) Works
holman
316
150k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
540
The SEO identity crisis: Don't let AI make you average
varn
0
570
Balancing Empowerment & Direction
lara
6
1.3k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.1k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
Transcript
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!