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
An Android Dev start to Kotlin MPP
Search
Roberto Orgiu
November 16, 2020
Programming
220
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
An Android Dev start to Kotlin MPP
Roberto Orgiu
November 16, 2020
More Decks by Roberto Orgiu
See All by Roberto Orgiu
Wellness & Droid
tiwiz
0
140
Behind the curtains
tiwiz
0
99
The Importance of Being Tested
tiwiz
0
460
Fantastic API and where to find them
tiwiz
0
120
Flipping the Koin @ GDG Dev Party
tiwiz
1
84
Flipping the Koin
tiwiz
2
190
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
140
Trip into the async world
tiwiz
1
170
GraphQL IRL (Android Makers)
tiwiz
0
170
Other Decks in Programming
See All in Programming
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
910
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
120
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
110
Next.js: The final boss of Web Performance
guaca
0
320
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
190
残高管理から台帳サービスへの進化
artoy
1
210
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
130
JIS keyboard support in Omarchy
lef237
0
160
Vue Fes Japan の “作る側”に関わってみて
naokihaba
1
180
No More NoSuchMethodError
exoego
1
110
GraphQL の onError と Nullability のこれから
quramy
0
180
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
270
Featured
See All Featured
New Earth Scene 8
popppiees
4
2.7k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
960
The agentic SEO stack - context over prompts
schlessera
0
970
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
So, you think you're a good person
axbom
PRO
2
2.2k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Building an army of robots
kneath
307
47k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Git: the NoSQL Database
bkeepers
PRO
433
67k
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
Transcript
An Android Dev start to Kotlin MPP
Premises I want to reuse my knowledge I am an
Android Dev I don’t want to be x-plat
What about languages?
Or actually any other example Empire State Building Lights Calendar
App
Architecture Activity ViewModel Repository
Libraries Repository Retrofit Gson / Moshi
Libraries Repository Retrofit Gson / Moshi Ktor kotlinx.serializer
Modularization Activity ViewModel Repository Native module Shared module
Modularization Repository Shared module
None
There is an app a plugin for that. PROJECT SETUP
1
Install & Profit
Create the project
Create the project
WRITE SOME CODE 2
expect actual IDE only helps after the directories have been
created.
@Serializable data class DayLight( val image: String, val color: String,
val reason: String, val date: String ) @Serializable data class Lights( val todayColor: String, val picture: String, val calendar: List<DayLight> ) :shared
class LightRepository { private val httpClient = HttpClient { install(JsonFeature)
{ val json = Json { ignoreUnknownKeys = true } serializer = KotlinxSerializer(json) } } suspend fun getLights() : Lights = httpClient.get(LIGHTS_ENDPOINT) } :shared
:android class LightsViewModel : ViewModel() { private val repository by
lazy { LightRepository() } private val _state : MutableLiveData<Lce<Lights>> = MutableLiveData() val state : LiveData<Lce<Lights>> get() = _state fun loadLights() { _state.postValue(Lce.Loading) viewModelScope.launch { try { val lights = repository.getLights() _state.postValue(Lce.Success(lights)) } catch(e: Exception) { _state.postValue(Lce.Error(e)) } } } }
val state : LiveData<Lce<Lights>> get() = _state fun loadLights() {
_state.postValue(Lce.Loading) viewModelScope.launch { try { val lights = repository.getLights() _state.postValue(Lce.Success(lights)) } catch(e: Exception) { _state.postValue(Lce.Error(e)) } }
They will happen WEIRD ERRORS 3
None
Delete all .iml files in the project Close project and
IDE Delete .idea directory Re-import the project
None
upgrade Gradle to 6.7 (KT-43039)
None
bit.ly/KMM-Codelab
USE COROUTINES 4
None
REMEMBER You cannot use extension functions
extension ContentView { enum LoadableLights { case loading case result(Lights)
case error(String) } class ViewModel: ObservableObject { let repo : LightRepository @Published var lights = LoadableLights.loading init(repo: LightRepository){ self.repo = repo self.loadLights() } func loadLights() { self.lights = .loading repo.getLights(completionHandler: { lights, error in if let lights = lights { self.lights = .result(lights) } else { self.lights = .error(error?.localizedDescription ?? "error") } }) } } }
self.repo = repo self.loadLights() } func loadLights() { self.lights =
.loading repo.getLights(completionHandler: { lights, error in if let lights = lights { self.lights = .result(lights) } else { self.lights = .error(error?.localizedDescription ?? "e } }) }
private func listView() -> AnyView { switch viewModel.lights { case
.loading: return AnyView(Text("Loading...").multilineTextAlignment(.center)) case .result(let lodableLights): return AnyView(LightsView(lights: lodableLights)) case .error(let description): return AnyView(Text(description).multilineTextAlignment(.center)) } }
None
None
Hello! I Am Rob Follow me at @_tiwiz
Q&A