KotlinConf 2019: Going Native by Ana Redmond
Recording brought to you by American Express. https://americanexpress.io/kotlin-jobs We often hear that Kotlin-Native is best for shared business logic and data handling. It is just as good for sharing 2D game code. With examples from a real world application, now in production, this talk will detail two key techniques we used to adapt platform-specific APIs for shared use on multiple platforms: 1. Using ‘expect’ and ‘actual’ to invoke platform-specific APIs in Kotlin. 2. Using an ‘interface’ in Kotlin Native and implementing in platform-specific language: #Swift or Kotlin. These techniques can be used to adapt any platform specific APIs for use by shared Kotlin Native code. We used this approach to adapt platform-specific APIs for drawing images and text, playing audio, handling touch events and the game loop, for use by 60+ 2D educational games. The games were originally written for native #Android in #Java using SurfaceView. They were recently converted to Kotlin-Native and published on both platforms: Android and #iOS. The code for the games is shared across platforms. As we converted and tested the games, we came across unexpected platform-specific differences. I will talk about some examples of those and the lessons we learnt, for e.g. 1. Why you shouldn’t use mutable Kotlin ‘object’ in Kotlin-Native apps. 2. Why you should use Lists in Kotlin-Native APIs, and not Arrays. 3. Be careful initializing subclass variables in overrides invoked in init. Code that we had built for educational games over the previous 6 years in Java on Android took me only 6 months to convert to Kotlin Native and publish to iOS. The code is maintainable because 80% of it is shared across multiple platforms. That would not have been possible without Kotlin-Native. Resources: KotlinConf website: https://jb.gg/fyaze5 KotlinConf on Twitter: https://twitter.com/kotlinconf Kotlin website: https://jb.gg/pxrsn6 Kotlin blog: https://jb.gg/7uc7ow Kotlin on Twitter: https://twitter.com/kotlin #KotlinConf19 #Kotlin #JetBrains About the Presenter: Ana Redmond is the Founder and Chief Technology Officer of infinut, where she designs and develops touch-screen games to teach math concepts to elementary-school children. She builds the cross-platform infrastructure for game screens, architects the data solution, and provides creative direction. She previously taught Android and Java Server programming at the University of Washington, Professional and Continuing Education, and worked professionally as a Software Developer for 15 years.