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
RxJava1からRxJava2へ
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yasuhiro Shimizu
October 03, 2017
Programming
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RxJava1からRxJava2へ
Yasuhiro Shimizu
October 03, 2017
More Decks by Yasuhiro Shimizu
See All by Yasuhiro Shimizu
Jetpack Composeから始める、頑張らないVRT
yshrsmz
0
1.3k
Kotlin Multiplatform Projectを導入してみて
yshrsmz
1
1.2k
BIP39について
yshrsmz
0
200
Android Fireside Chatまとめ
yshrsmz
3
2.3k
Other Decks in Programming
See All in Programming
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
210
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
120
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.6k
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
210
Vite+ Unified Toolchain for the Web
naokihaba
0
220
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
250
AIとRubyの静的型付け
ukin0k0
0
560
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
160
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
530
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
270
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
120
CLIであることを活かしたGitHub Copilot CLI活用術 / GitHub Copilot CLI Pro Tips & Tricks
nao_mk2
1
1.2k
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
330
40k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Embracing the Ebb and Flow
colly
88
5.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Agile that works and the tools we love
rasmusluckow
331
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
250
Evolving SEO for Evolving Search Engines
ryanjones
0
210
The browser strikes back
jonoalderson
0
1.2k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
290
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
200
Transcript
RxJava1 -> RxJava2 CA.APK - YASUHIRO SHIMIZU
ABOUT ME 清水泰博(Yasuhiro Shimizu) ▸ Android Engineer @AWA Co. Ltd.
▸ GitHub: yshrsmz ▸ Twitter: _yshrsmz Omnitweety Monotweety
MIGRATING TO RXJAVA2 今日話すこと ▸ 開発を止めずRxJava2に 徐々に移行するにはどうしたらいいか ▸ AWAの場合
MIGRATING TO RXJAVA2 今日話さないこと ▸ RxJavaとは何か ▸ RxJava1とRxJava2の違い
MIGRATING TO RXJAVA2 バージョンアップどうやる? dependencies { compile: "io.reactivex:rxjava:1.3.2" } dependencies
{ compile: "io.reactivex.rxjava2:rxjava:2.1.4" }
これはやめた方がいい
MIGRATING TO RXJAVA2 RxJava1への依存を削除するのはやめた方がいい ▸ RxJava1とRxJava2では変更点が多く、作業にも確認にも時 間がかかる ▸ つまり何度も何度もmasterの変更を取り込まなければなら ない
▸ RxJava1で書いたコードがmasterにどんどん追加されていく
RxJava2Interop を使って、 少しずつRxJava2に移行しよう
MIGRATING TO RXJAVA2 What is RxJava2Interop? ▸ https://github.com/akarnokd/RxJava2Interop ▸ RxJava1とRxJava2のReactive
Typeを相互に変換 ▸ 作: David Karnok(RxJavaのmain commiter) ▸ このライブラリを使うとステップ・バイ・ステップで RxJava2に移行できる
MIGRATING TO RXJAVA2 Usage // app/build.gradle android.packagingOptions { exclude 'META-INF/rxjava.properties'
} dependencies { compile: "io.reactivex:rxjava:1.3.2" compile: "io.reactivex.rxjava2:rxjava:2.1.4" compile: "com.github.akarnokd:rxjava2-interop:0.10.6 }
MIGRATING TO RXJAVA2 使い方(in java) RxJavaInterop.toV2Flowable(v1Observable); RxJavaInterop.toV2Maybe(v1Single); RxJavaInterop.toV1Observable(v2Publisher); // etc...
MIGRATING TO RXJAVA2 使い方(in Kotlin) fun <T> rx.Observable<T>.toV2Observable() = RxJavaInterop.toV2Observable(this)
fun <T> io.reactivex.Observable<T>.toV1Observable() = RxJavaInterop.toV1Observable(this, BackpressureStrategy.LATEST) // v1Observable.toV2Observable() // v2Observable.toV1Observable() 拡張関数を定義すると捗る
ANY REAL-LIFE EXAMPLE?
テキスト 移行の手順 ▸ 各種ライブラリの移行方法検討(Realm, SQLite, Retrofit) ▸ nullを流してるストリームをOptionalに書き換える ▸ ひたすらやっていき
MIGRATING TO RXJAVA2 Realm ▸ Realm v4.0はRxJava2をサポートする(未リリース) ▸ v3.xでは2つ選択肢がある ▸
RxJava2Interopを使う ▸ v4.0の実装を参考に自分で作る ▸ https://github.com/realm/realm-java/pull/4991 ▸ Kotlinの拡張関数使うと
テキスト SQLite ▸ 特にライブラリは使わずに実装しているので、地道に書き換 える ▸ Roomへの置き換えも進行中
MITRATING TO RXJAVA2 Retrofit ▸ RxJava2CallAdapterFactoryを使う ▸ RxJava1とRxJava2のCallAdapterは共存できる Retrofit.Builder() .baseUrl("https://api.example.com")
.addCallAdapterFactory( RxJavaCallAdapterFactory.create()) .addCallAdapterFactory( RxJava2CallAdapterFactory.create()) .build()
MIGRATING TO RXJAVA2 Architecture of AWA DbClient DbClient DbClient DbClient
DbClient ApiClient SharedPreferences Realm SQLite API Server DbClient DbClient Model DbClient DbClient UseCase DBCLIENT DBCLIENT Activity/Fragment View Domain Data
MIGRATING TO RXJAVA2 Architecture of AWA DbClient DbClient DbClient DbClient
DbClient ApiClient SharedPreferences Realm SQLite API Server DbClient DbClient Model DbClient DbClient UseCase DBCLIENT DBCLIENT Activity/Fragment View Domain Data DbClientをRxJava2化 RxJava2Interop でRxJava1に変換 Domainより上の レイヤは変更不要
MIGRATING TO RXJAVA2 Some random tips ▸ doOnDisposeではなくdoFinallyを使う ▸ https://github.com/ReactiveX/RxJava/wiki/What's-
different-in-2.0 ▸ Reactive Typeで「値がない状態」を通知したい時はOptionalを 使う ▸ Kotlinだとgojuno/koptionalがミニマムでよさそう ▸ Singleで↑の場合はMaybeを使いましょう
THANK YOU!