Kotlin MP: Into the Multi-Verse
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Title of Series | ||
Number of Parts | 490 | |
Author | ||
License | CC Attribution 2.0 Belgium: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor. | |
Identifiers | 10.5446/47347 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
FOSDEM 2020458 / 490
4
7
9
10
14
15
16
25
26
29
31
33
34
35
37
40
41
42
43
45
46
47
50
51
52
53
54
58
60
64
65
66
67
70
71
72
74
75
76
77
78
82
83
84
86
89
90
93
94
95
96
98
100
101
105
106
109
110
116
118
123
124
130
135
137
141
142
144
146
151
154
157
159
164
166
167
169
172
174
178
182
184
185
186
187
189
190
191
192
193
194
195
200
202
203
204
205
206
207
208
211
212
214
218
222
225
228
230
232
233
235
236
240
242
244
249
250
251
253
254
258
261
262
266
267
268
271
273
274
275
278
280
281
282
283
284
285
286
288
289
290
291
293
295
296
297
298
301
302
303
305
306
307
310
311
315
317
318
319
328
333
350
353
354
356
359
360
361
370
372
373
374
375
379
380
381
383
385
386
387
388
391
393
394
395
397
398
399
401
409
410
411
414
420
421
422
423
424
425
427
429
430
434
438
439
444
449
450
454
457
458
459
460
461
464
465
466
468
469
470
471
472
480
484
486
487
489
490
00:00
MultiplicationMessage passingCartesian coordinate systemCross-platformAndroid (robot)outputComputer animation
01:37
Formal languageComputing platformCodeOpen sourceComputing platformReduction of orderRevision controlShared memoryComputing platformMobile appComputing platformCodeSoftware developerStatement (computer science)AeroelasticityRight angleFormal languageCross-platformPrisoner's dilemmaControl flowBytecodeSoftware frameworkChainSoftware maintenanceLevel (video gaming)Projective planeVirtual machineFlow separationCore dumpMultiplicationPoint (geometry)Domain-specific languageGUI widgetFunctional (mathematics)Multiplication signBuildingPattern languageLatent heatAxiom of choicePresentation of a groupProduct (business)TouchscreenCartesian coordinate systemOpen sourceQuicksortComputer animation
05:20
Computing platformComputing platformBootingAndroid (robot)Spring (hydrology)Java appletCodeOSI modelGame controllerRepository (publishing)Cache (computing)Computer networkDomain-specific languagePersonal digital assistantAeroelasticityInterface (computing)Inheritance (object-oriented programming)String (computer science)SoftwareEndliche ModelltheorieRevision controlGame controllerComputing platformRepository (publishing)SynchronizationCASE <Informatik>Android (robot)Presentation of a groupImplementationPoint (geometry)Core dumpMultiplication signCodeBitCross-platformString (computer science)Domain-specific languageComputer fileLogicProjective planeProcess (computing)Module (mathematics)MereologyFunctional (mathematics)ArmComputing platformInterface (computing)Right angleLetterpress printingBefehlsprozessorWebsiteSocial classWordEmulatorStandard deviationQuicksortoutputHydraulic jumpMobile appInternetworkingCartesian coordinate systemConstructor (object-oriented programming)Shared memoryCoroutineTime zoneJava appletLatent heatWeb 2.0WindowTouchscreenMessage passingGoogolSpring (hydrology)Sheaf (mathematics)BootingDifferent (Kate Ryan album)System callView (database)Computer animation
14:02
Android (robot)CodeShared memoryProjective planeoutputRevision controlCodeMobile appSampling (statistics)Android (robot)Module (mathematics)Multiplication signSource code
14:53
TorusAndroid (robot)CodeComputing platformMobile appSynchronizationRight angleCodeModule (mathematics)Intrusion detection systemoutputDifferent (Kate Ryan album)Android (robot)Latent heatDampingProjective plane
15:52
Projective planePoint (geometry)CodeCross-platformSynchronizationBuildingMobile WebAndroid (robot)output
16:13
Android (robot)Category of beingDefault (computer science)Software development kit
16:33
Projective planePoint (geometry)Android (robot)Software development kitRevision controlData structureDefault (computer science)Module (mathematics)
17:04
CodeModule (mathematics)Revision controlImplementationAndroid (robot)Heegaard splittingFunctional (mathematics)Different (Kate Ryan album)Multiplication signProgram flowchart
17:35
Revision controlAndroid (robot)Binary fileSoftware frameworkSource codeSet (mathematics)Software testingImplementationPhysical systemSource codeProjective planeRevision controlComputing platformPlug-in (computing)Sheaf (mathematics)EmulatorMobile appStandard deviationComputer fileOpen setXML
18:14
Cartesian coordinate systemProjective planeMobile appCodeModule (mathematics)
18:35
Error messageRootoutputMobile appMereologyModule (mathematics)Projective planeSource code
19:04
Directory serviceVoltmeterCodeConvex hullError messageProjective planeWrapper (data mining)RootMobile appMultiplication signCodeFunctional (mathematics)outputAndroid (robot)ImplementationComputer file
19:41
Computing platformExecution unitBitLibrary (computing)AreaDatabaseWebsiteSlide ruleFunctional (mathematics)CodeComputing platformComputer fileCartesian coordinate systemInformation retrievalTouchscreenSpacetimeProduct (business)Message passingElectronic mailing listPhysical systemImplementationProjective planeLink (knot theory)CASE <Informatik>Repository (publishing)Computing platformCross-platformSheaf (mathematics)BlogComputer animation
22:18
MultiplicationFacebookPoint cloudOpen source
Transcript: English(auto-generated)
00:06
yep everyone again thank you for coming don't forget to yeah help your chair when you leave the room it's really noisy don't pass in front of the camera over there and we still have Japanese licenses
00:25
then I'm happy to introduce nation is going to talk about cuddling MP into
00:41
okay hello everyone you can all hear me right at the back also I hope okay great thank you all for coming to this talk so the idea about this talk basically came through because I was trying to like find out ways of working with cotton multi-platform it's like people been talking about it and a lot of things are going on this so I eventually started like trying out how I can get
01:05
this to work turns out it's not as easy as we think it is so that's how this talk came to be so what I'm gonna be doing here is I'm gonna try to at least convince you all to understand how cotton multi-platform in general is
01:20
working and what's doing and then I'm also gonna show you how you can actually get a working application for Android and iOS because it's not as simple as you think like you just fired up an ID and it works so it's not that that's what I will show you so let's start with that so I said Kotlin MP
01:41
what does that actually mean as you would have guessed it's basically Kotlin multi-platform there's no formal definition for this like what exactly it is so I came up with my own from what I understood basically we are utilizing Kotlin language to build for these multiple target platforms I'll get to what target platforms of are in a few minutes which enables code
02:02
sharing while being as flexible as you can be right so I'm gonna break this down because like a full statement okay there's a lot of things being said here in general Kotlin multi-platform is like an open source tool or I should say plug-in that's available it uses cotton as your common code here
02:22
also is targeting multiple platforms the core sharing is specifically happening for data domain and presentation layer the the the different thing about it is that it integrates with the existing native platforms so it leverages the native capabilities of the platform when it is required it's not that you
02:43
are you are specifically forced to use them it's more a choice on you when you need to use them you will go ahead and use them it's optional as it is not opinionated ties into the same point as above it will not ask you to specifically use a certain pattern it will not ask you to do some sort of
03:02
trickery or like use a different language to work with so it's basically trying to help you as much as it can while giving you all the choices but the question here is why why are we even trying to do this so from what I understand is that up till now there have been like all these different
03:23
possibilities that we could use Kotlin for you could use Kotlin for generating JavaScript code and then you could use Kotlin for generating the JVM base code the byte code right and then Kotlin native came into place and that allowed people or at least the Kotlin tool chain to generate more target platform specific code so you can think of something that's more near to
03:44
the machine level code here and the second point that's very important is that existing solutions are very opinionated I'm looking at a flutter react native and then you also have Xamarin obviously people have tried CC++ in the past too all of these are very opinionated in the sense that they
04:04
force you to use a certain pattern flutter would basically ask you to use first of all a different language so you will start from a different stack and a different language at the same time it tells you that you cannot use the platform widgets because it is going to be drawing all the widgets for you on the screen right so those kind of like opinionated versions exist and
04:24
that's why Kotlin native is or Kotlin multiplatform now is something that's more considered it's something like this like we have a situation where it's a dilemma of the mobile app development right now where if you want to develop a native app for each device and maintain several projects this is what it looks like on the on the right and then you use a unique
04:44
framework like say phone gap and then app accelerator like in the past or you could use flutter or even react native you end up building something that is limited in functionality why am I saying that because there have been companies who have tried this in the production like for example you know
05:00
Airbnb tried react native and then they pushed back to going to native again Dropbox tried CC plus us for their cross-platform capabilities in the application but they also went back to native because there's certain things that you cannot do when you're trying to share most of the code across platforms so let's dive into the multiverse of platforms here or target
05:24
platforms that's the technical word for it the way I understand target platform I think this was explained in the last talk a little bit but the point here is that I understand it as compiled artifacts to be consumed by specific platform so say for example when we are considering Kotlin JVM the
05:43
artifact that will be consumed by the platform would be jar and AR files right this can be consumed by Java by Android by Spring Boot if you have Kotlin JS is gonna be generating JavaScript code which you can bundle it up and push it with say JavaScript react or node and then there comes the
06:02
Kotlin native part which enabled more possibilities where you have ability to generate code that is native to the arm platform or CPU in general that you can push it with the Android and decay you have iOS version the is x64 by the way is the emulator similar you have for tvOS x64 is
06:22
again emulator version watch OS x86 is again for emulator and the other versions are when you want to run them on the device and then you have more where you have the Linux arm version the MIPS version for the same Mac OS x64 Ming W which is basically for Windows and then the WSM 32 which
06:41
is for web assembly that's what Kotlin native is allowing you to target now because it's generating artifacts that can be consumed by by code that's running on this platform so this brings me to the next part here because it's not just the target platform it's also about code sharing so when we say
07:02
code sharing we are actually talking about more related to the the data layer in general right where you can put your networking code that that can be shared across multiple platforms you can put caching you can put repositories you can even put like something like a bigger presentation layer with which is common in view on Android side you have view models and
07:21
presenters controllers and then there's the domain layer where you can put use cases entities and the interactors what is also important here is that we are not talking about the UI at all now why we are not talking about the UI because Kotlin native in general doesn't even care about UI each of these platform that exists have their own way of representing UI iOS has its
07:44
own version Android has its own version say example Linux has its own version and they all do their job pretty well so what Kotlin native is basically saying is that we're going to build an artifact for you you plug that into your application build the UI on your own and then use this whole
08:00
code right so this is the artifact that's being generated on all of these different platforms is what is shared but the UI is still native this is more or less on the side of just making sure that the UI gets updated pretty frequently right but your business logic anyway stays the same so you want to share your business logic mostly and not the UI UI can change whenever you
08:23
want based on whatever technology you'd use even say for example on iOS we were developing a lot of like UI with say view controllers and other stuff now you're using the sift UI same on the Android you could basically be using XML layouts now but now you have compost that's coming in now these technologies will change all the time but the core idea of
08:43
the platform here is that the business logic is getting shared across mind that I'm not saying this is cross-platform comes back to the same thing when we say cross-platform solutions we have basically solutions that are we they're asking you to write code in an opinionated manner right also they are doing some sort of like bridging to make things work for you magically
09:04
right when you say it's a Xamarin app I write code in C sharp and I write something up and say for example like an application in that and then I deploy it to say Android iOS and say some other platform maybe desktop in this case what they are doing is they are gonna compile your code put it
09:20
behind a bridging layer and then talk to the native site so there's still some sort of a dependency in between if this dependency is not updated you're already behind so what's the secret sauce here so from my understanding and this is what I am gonna maybe represent it and maybe you
09:42
can think through with me as I explained this is that there's a concept called expect an actual concept what I like to call as interfaces with superpowers and more and I'm gonna explain what that that turns out to be so this is a standard interface in Kotlin right you have an interface that a
10:01
function called platform name then I am using Android code right now you have a main activity where I'm kind of I'm not extending the activity here for some reason but I should have anyways consider it's a standard class that is implementing the interface and it overrides the the function here
10:20
platform name because I'm using the interface and then later on I use it inside the function called create application screen message I'm calling it hello from dollar and then the passing the function in them now notice here something the first section where the interface is declared or I should say defined actually or declared yeah that is the point where we are
10:41
expecting this to be implemented this is how we read it right and then eventually when we override it is the actual implementation that's how interfaces work now I'm going to map this back to how Kotlin multi-platform is going to be using this kind of a functionality so what you have is that on your safe you have multiple modules right now in a cartoon platform project
11:02
the common module here would basically say expect that's the keyword to use and then it will put it something similar to like how you use coroutines you put suspend and then the function name right you're gonna say expect the function name and then that's it then maybe you can use the same function call in the common code for create application screen message
11:22
and then eventually in the platform specific code version you will go and say the actual implementation for this by using the keyword actual is this function and what what is the implementation you want to define so in this case we are defining the string as Android for Android platform module and iOS for iOS module but that's not it and I said and more with the
11:47
superpower version is because it's not just limited to how it will work with functions you can use the same kind of a process when you are doing it with a class right so for example you have a class here greeting where you say I'm going to expect this class to have a function called greet in it
12:05
now the platform implementation for this will map into saying actual the class greeting and then notice I say actual constructor val name string why am I saying actual again because on the platform side this could have been say Swift and it would have said let name
12:22
string so this is also changing for me so that's why I have to say the actual implementation for the constructor is going to be something that's very specific to Android in in this case using Kotlin so val name string and then eventually I provide the actual implementation of the function here called greet where I say print ln hello name and then you can obviously
12:42
use it based on which platform you're using in this case we are considering Android so we'll create the class we'll call the function on it which will print hello foster so that said let's jump into trying to or or I'm gonna I'm gonna go through the steps that you require to start building Kotlin Multiplatform code now that we know the idea
13:03
of expect an actual but before we do that I want to mention something about sharing is caring so if you go on the internet right now and you try out like google searching this how do you get a Kotlin Multiplatform project to work you'll find many ways one of the ways of doing this this code sharing is that you put all your code in just one repository
13:23
right and then everyone just tries to work with that in that same repository that's okayish to work with but if you have many teams working across different time zones people are going to be committing code it's going to conflict and cause a lot of problems so that's not a good one the second one is that you put everything in its own repository in
13:44
its own project while the shared code that is going to be shared across multiple projects is going to live its own project it's a bit hard to maintain because you have to keep in sync with the shared code and the other platforms that you are sharing this against so you have to keep them in sync this is what it kind of looks like so imagine this being a
14:05
project in Intel J where I am basically creating a sample app called KMP here it has app as a module that is the Android app it has native slash Kotlin iOS slash Kotlin iOS as the iOS app module here and then you have a shared code as a full folder here inside which
14:26
lives something called Android main which is your Kotlin JVM code something that lives as common which is your shared code and then you have your iOS main which is your Kotlin native iOS shared code here this is basically living outside in a shared code folder so this is
14:46
something that you would do but it's really hard to maintain it at the same time because yes people would be doing a lot of things at the same time the third version of doing this is that you have one platform in sync with the common code while the other one lives on the
15:01
other side right so it's it's better it's easier to test with it is better to change things and this is what it looks like you have something like this you have Android app and the Kotlin JVM code and the iOS app as a different module right the shared code and Kotlin native iOS code
15:22
actually lives inside the app module as you can see it's called common main and iOS main this is just living inside the app module itself so we're going to actually start doing this like from scratch like how you would do this you would think the thing that it's very easy to work with but sadly there's no specific ID like Android studio but you we use kind of like
15:43
all three IDs here we'll use IntelliJ IDEA we'll use Android studio and we'll use Xcode all three of them together to get to get this project working and functional so you start with IntelliJ IDEA this is the latest one I took the screenshot last night you create a new project you say I'm gonna put a mobile multi-platform project with Android and iOS code in it using
16:04
gradle build tool define it a name give it something and then say finish at this point when you've hit finish your project would sync and you would ideally assume that it is functional turns out it's not because by default IntelliJ IDEA does not put the sdk path for your Android in the local dot properties file so that is a bit weird because they do that for Android
16:25
studio or maybe Android studio team does that specifically I'm not quite sure but in that sense you will have to actually provide the path here so I changed this path to something called users slash username and then I provide the Android sdk path here when you do this your project is
16:42
fully functional at this point what you do is that you need to also go into your project structure and set the default like the sdk for all the modules this is also something that I don't know why it doesn't work but ideally this should be supported from the IDEA itself they know there's other sdk but they don't choose the the default one is 1.8 java version
17:05
so I want to also highlight here when you do this the wizard version you actually see something like a common code the kotlin native is code the android and the kotlin jvm code and then there's a ispecific code which is all split into different modules right now the function
17:22
calls as you will define you will mention them as expect in the common code only in the kotlin native is code you will provide the actual implementation in the android and kotlin jvm code you will provide the actual implementation the magic behind how all of this is time together is is actually using this this plugin that you have you just need to just define in
17:44
your apps build.gradle file once you define it you all have functionalities open like these you can define the platforms you can target to under the section kotlin you can say isx64 which right now is targeting the is emulator I could just go ahead and do tv os x64 and that
18:01
would do the same thing but for the tv os operating system for the emulator version and then you define the source set basically defining your dependencies which you can totally do as you would do in a standard gradle project then because you now want to run your application you set up the project now you need to open up android studio and select the
18:22
app module the one that has your common code too you will select that run this through you as you can see there are different modules you're recognizing and then it will be able to execute the application surprisingly that's nice because now we are going to try doing the same with ios so with ios again you go and then you select the folder that is called ios app this is
18:44
outside your app module in your root project and this is the one you need to select when you do that you would assume everything would work but it does not again turns out that's because they use a relative path to reference something that doesn't exist which is also weird they should not do this it should come part of the wizard but it's not so you have this error this
19:04
error literally says that you have something that's missing and that's a gradle u file right that's not there so i need to put a gradle wrapper in the root project and i'm going to do that by calling gradle wrapper and it will create that for me that basically allows me to go back into xcode hit run and be able to run the app at the same time so now you have an app running
19:23
on android and ios both basically the whole project is functional you can go ahead and write code using android studio if you want or intel j idea you can just open up the cotton file provide the actual implementation or the more expected functions you would want so examples in the wild
19:43
i want to show this because there's a lot of questions going on do people use it in production or not like is this something that that we should not be tinkering with turns out a lot of companies are doing that yeah you can see a list of them all working with the links these all links to their blog post actually when you download these slides you can use them
20:01
and read what they have been working on jet brains has recently released spaces their whole this system here which allows to communicate with multiple teams so that is also working kotlin native scotland multi-platform and obviously touch lab is doing a lot of things in this area so you should totally follow them there are kotlin multi-platform libraries by the
20:24
way you can get a list of these but here's the caveat here is that the ecosystem is still evolving uh the bigger problem is that not many libraries are available at your disposal and a lot of people those who are jumping into building these libraries are actually not targeting all the platforms for example you wanted to use a multi-platform library right now
20:42
that targets say or kind of like does database saving and retrieval of data right but it does not target tv os but you wanted that functionality and be targeted to tv os well if the library doesn't support it it's useless for you right you can target for platforms but not tv os in general so that's why not all libraries are actually targeting
21:04
all the platform so that's a bit of a problem um that's most of the stuff there's a resource here this is like a um like a i would say a tutorial uh the first thing is more of tutorial on the official kotlin land site uh the second one is the example that i showed you
21:21
what i do want to also show you is the thing that i was talking about this is how all the files look like and the implementation this is the same project as i was talking about there is a section where i actually call this function create application screen message which was running there and i provide the actual functionality here but some people might even say like what if i wanted to use swift ui that is also possible
21:44
provided use it in a different way in this case you will see i'm including the shared code functionality the one that i was explaining way earlier than this and then i go ahead and i call the function here with the common kt file so you can also use with swift ui if you want if you have compose you can also use this work it should function without any problems
22:04
i will put more examples in this repository so you can also obviously follow this now um and that's it i guess thank you