state of kotlin in android florina muntenescu
play

State of Kotlin in Android Florina Muntenescu FMuntenescu - PowerPoint PPT Presentation

Kotlin 1.4 Online Event State of Kotlin in Android Florina Muntenescu FMuntenescu October, 2020 Why Android Kotlin Expressiveness Image safe area Why Android Kotlin Safety Expressiveness Image safe area Kotlin on Android in


  1. Kotlin 1.4 Online Event State of Kotlin in Android Florina Muntenescu FMuntenescu October, 2020

  2. Why Android ❤ Kotlin Expressiveness Image safe area

  3. Why Android ❤ Kotlin Safety Expressiveness Image safe area

  4. Kotlin on Android in 2020 20% Less likely to crash Source: Google Internal Data, July 2020

  5. Why Android ❤ Kotlin Safety Expressiveness Image safe area Interoperability

  6. Why Android ❤ Kotlin Safety Expressiveness Image safe area Structured Interoperability concurrency

  7. Kotlin on Android in 2020 50% More likely to be very satisfjed Source: Google Internal Data, May 2020

  8. Kotlin on Android in 2020 60% Pro Android developers use Kotlin Source: Google Internal Data, May 2020

  9. Kotlin on Android in 2020 70%+ Top 1k apps contain Kotlin code Source: Google Internal Data, May 2020

  10. Google’s contributions to Kotlin Co-leading Kotlin Foundation Contributing to the Kotlin compiler Developing Kotlin related tooling and libraries

  11. Google’s contributions to teaching Kotlin Docs - d.android.com/kotlin Samples - github.com/android Codelabs - goo.gle/kotlin-codelabs Aruicles - goo.gle/kotlin-posts Videos - goo.gle/kotlin-videos

  12. Google’s contributions to teaching Kotlin Docs - d.android.com/kotlin Samples - github.com/android Codelabs - goo.gle/kotlin-codelabs Aruicles - goo.gle/kotlin-posts Videos - goo.gle/kotlin-videos Faculty training

  13. Since last year’s Google I/O... Libraries Tools Learning Kotlin-fjrst libraries Kotlin live templates Vocabulary series New KTX releases New lint checks Samples and docs @ Nullness R8 Optimizations Kotlin/Everywhere annotations

  14. Since last year’s Google I/O... Libraries Tools Learning Kotlin-fjrst libraries Kotlin live templates Vocabulary series New KTX releases New lint checks Samples and docs @ Nullness R8 Optimizations Kotlin/Everywhere annotations

  15. Since last year’s Google I/O... Libraries Tools Learning Kotlin-fjrst libraries Kotlin live templates Vocabulary series New KTX releases New lint checks Samples and docs @ Nullness R8 Optimizations Kotlin/Everywhere annotations

  16. Since last year’s Google I/O... Libraries Tools Learning Kotlin-fjrst libraries Kotlin live templates Vocabulary series New KTX releases New lint checks Samples and docs @ Nullness R8 Optimizations Kotlin/Everywhere annotations

  17. Since last year’s Google I/O... Libraries Tools Learning Kotlin-fjrst libraries Kotlin live templates Vocabulary series New KTX releases New lint checks Samples and docs @ Nullness R8 Optimizations Kotlin/Everywhere annotations

  18. Since last year’s Google I/O... Libraries Tools Learning Kotlin-fjrst libraries Kotlin live templates Vocabulary series New KTX releases New lint checks Samples and docs @ Nullness R8 Optimizations Kotlin/Everywhere annotations

  19. Since last year’s Google I/O... Libraries Tools Learning Kotlin-fjrst libraries Kotlin live templates Vocabulary series New KTX releases New lint checks Samples and docs @ Nullness R8 Optimizations Kotlin/Everywhere annotations

  20. Since last year’s Google I/O... Libraries Tools Learning Kotlin-fjrst libraries Kotlin live templates Vocabulary series New KTX releases New lint checks Samples and docs @ Nullness R8 Optimizations Kotlin/Everywhere annotations

  21. Since last year’s Google I/O... Libraries Tools Learning Kotlin-fjrst libraries Kotlin live templates Vocabulary series New KTX releases New lint checks Samples and docs @ Nullness R8 Optimizations Kotlin/Everywhere annotations

  22. Since last year’s Google I/O... Libraries Tools Learning Kotlin-fjrst libraries Kotlin live templates Vocabulary series New KTX releases New lint checks Samples and docs @ Nullness R8 Optimizations Kotlin/Everywhere annotations

  23. Jetpack Compose Modern, declarative UI toolkit ● Built on Kotlin ● Unbundled ●

  24. Compose project structure Compose Material Surface, Buttons, Tabs, Themes Compose Foundation Android Studio Standard layouts, interactions Live preview, Apply Changes Compose Compiler Plugin Compose UI Code generation extensions Input, Measure, Layout, Drawing kotlinc Compose Runtime Upstream Kotlin compiler (1.4) Tree management, Effects Build time (development host) Runtime (on device)

  25. Jetpack Compose API Button( onClick = { /* do an action */ }, modifier = Modifier.padding(vertical = 20.dp) // default: Modifier ) { Text(text = "Click me") }

  26. Kotlin at Google Source: Google Internal Data, May 2020

  27. Kotlin at Google • > 2M lines of Kotlin code • Used on server-side • Kotlin in OSS projects: gRPC ○ ProtoBuf ○ (coming soon)

  28. Kotlin 1.4 preview

  29. Kotlin Tooling Performance “Faster Please!”

  30. Kotlin Tooling Performance Kotlin Tooling Pergormance • Incremental Annotation Processors

  31. Kotlin Tooling Performance • Incremental Annotation Processors • IDE Pergormance

  32. Kotlin Tooling Performance • Incremental Annotation Processors • IDE Pergormance • Gradle improvements

  33. Kotlin for library authors • Explicit API mode in Kotlin 1.4 • Kotlin Symbol Processing • R8 Kotlin Metadata supporu

  34. Explicit API mode • Be intentional about your public API • Explicitly declare: ○ Visibility modifjers ○ Type

  35. Explicit API mode build.gradle kotlin { // for strict mode explicitApi() // or explicitApi = 'strict' // for warning mode explicitApiWarning() // or explicitApi = 'warning' }

  36. Kotlin for library authors • Explicit API mode in Kotlin 1.4 • Kotlin Symbol Processing • R8 Kotlin Metadata supporu

  37. Kotlin Symbol Processing Developer Preview Image safe area We need your feedback! goo.gle/ksp Title safe

  38. R8 • Supporu for Kotlin metadata rewriting • Android Gradle Plugin 4.1.0-beta03

  39. AsyncTask Deprecated in Android 11 This class was deprecated in API level R (Android 11) Use the standard java.util.concurrent or Kotlin concurrency utilities instead.

  40. Async programming What should we use?

  41. Coroutines Brief overview Coroutines are the Kotlin way to do asynchronous programming . Compiler supporu is stable since Kotlin 1.3, together with a robust kotlinx.coroutines library.

  42. Coroutines Professional developers who use Coroutines have reporued seeing increased productivity Source: Google Internal Data, May 2020

  43. Coroutines viewModelScope . launch { val status = withContext(Dispatchers.IO) { val office = officeDetailsService.findOffice("US-BVE") db.officeDetails().insert(office) office.status } val isOpenText = if (status == OfficeStatus.OPEN) { "open :)" } else { "closed :(" } officeStatusLiveData. value = "Your office is $isOpenText" }

  44. Coroutines viewModelScope . launch { val status = withContext(Dispatchers.IO) { val office = officeDetailsService.findOffice("US-BVE") db.officeDetails().insert(office) office.status } val isOpenText = if (status == OfficeStatus.OPEN) { "open :)" } else { "closed :(" } officeStatusLiveData. value = "Your office is $isOpenText" }

  45. Coroutines viewModelScope . launch { val status = withContext( Dispatchers.IO ) { val office = officeDetailsService.findOffice("US-BVE") db.officeDetails().insert(office) office.status } val isOpenText = if (status == OfficeStatus.OPEN) { "open :)" } else { "closed :(" } officeStatusLiveData. value = "Your office is $isOpenText" }

  46. Coroutines viewModelScope . launch { val status = withContext(Dispatchers.IO) { val office = officeDetailsService.findOffice ("US-BVE") db.officeDetails().insert(office) office.status } val isOpenText = if (status == OfficeStatus.OPEN) { "open :)" } else { "closed :(" } officeStatusLiveData. value = "Your office is $isOpenText" }

  47. Coroutines viewModelScope . launch { val status = withContext(Dispatchers.IO) { val office = officeDetailsService.findOffice("US-BVE") db.officeDetails().insert (office) office.status } val isOpenText = if (status == OfficeStatus.OPEN) { "open :)" } else { "closed :(" } officeStatusLiveData. value = "Your office is $isOpenText" }

  48. Coroutines viewModelScope . launch { val status = withContext(Dispatchers.IO) { val office = officeDetailsService.findOffice("US-BVE") db.officeDetails().insert(office) office.status } val isOpenText = if (status == OfficeStatus.OPEN) { "open :)" } else { "closed :(" } officeStatusLiveData. value = "Your office is $isOpenText" }

  49. Kotlin coroutines are the recommended solution for async code

  50. Android 💛 coroutines Structured concurrency Non-blocking, sequential code Cancellation propagation Natural exception handling

  51. Coroutines & Jetpack

  52. Room Database queries @Dao interface UsersDao { @Insert suspend fun insertUsers(vararg users: User) @Update suspend fun updateUsers(vararg users: User) @Delete suspend fun deleteUsers(vararg users: User) @Query("SELECT * FROM users") suspend fun getUsers(): List<User> }

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend