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
Yasuhiro Shimizu
October 03, 2017
Programming
0
100
RxJava1からRxJava2へ
Yasuhiro Shimizu
October 03, 2017
Tweet
Share
More Decks by Yasuhiro Shimizu
See All by Yasuhiro Shimizu
Jetpack Composeから始める、頑張らないVRT
yshrsmz
0
1.1k
Kotlin Multiplatform Projectを導入してみて
yshrsmz
1
1.1k
BIP39について
yshrsmz
0
170
Android Fireside Chatまとめ
yshrsmz
3
2.2k
Other Decks in Programming
See All in Programming
Agentic Coding: The Future of Software Development with Agents
mitsuhiko
0
110
AI時代のソフトウェア開発を考える(2025/07版) / Agentic Software Engineering Findy 2025-07 Edition
twada
PRO
93
31k
オンコール⼊⾨〜ページャーが鳴る前に、あなたが備えられること〜 / Before The Pager Rings
yktakaha4
0
130
Webの外へ飛び出せ NativePHPが切り拓くPHPの未来
takuyakatsusa
2
560
ニーリーにおけるプロダクトエンジニア
nealle
0
870
チームで開発し事業を加速するための"良い"設計の考え方 @ サポーターズCoLab 2025-07-08
agatan
1
440
Systèmes distribués, pour le meilleur et pour le pire - BreizhCamp 2025 - Conférence
slecache
0
120
RailsGirls IZUMO スポンサーLT
16bitidol
0
190
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
230
코딩 에이전트 체크리스트: Claude Code ver.
nacyot
0
690
初学者でも今すぐできる、Claude Codeの生産性を10倍上げるTips
s4yuba
16
12k
MCPを使ってイベントソーシングのAIコーディングを効率化する / Streamlining Event Sourcing AI Coding with MCP
tomohisa
0
110
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
Producing Creativity
orderedlist
PRO
346
40k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
Testing 201, or: Great Expectations
jmmastey
43
7.6k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
We Have a Design System, Now What?
morganepeng
53
7.7k
How to Think Like a Performance Engineer
csswizardry
25
1.7k
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!