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.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
golang-bob.pdf
iwatsukayura
0
130
ActionController meets Protocol Buffers
sorah
0
650
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
34k
AIに “答え“を書かせるのを やめてみた
___akari11
0
130
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
Event is what happens
moro
2
1.1k
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
340
ChromeでローカルLLM
ryu1013
0
160
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.2k
Workers Cache を知る
syumai
0
370
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
160
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
Featured
See All Featured
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
The Curse of the Amulet
leimatthew05
3
16k
Everyday Curiosity
cassininazir
0
360
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1k
We Have a Design System, Now What?
morganepeng
55
8.4k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
410
A better future with KSS
kneath
240
18k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
370
Thoughts on Productivity
jonyablonski
76
5.4k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
260
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!