1 of 63

O U R S P O N S O R S

March 12th, 2024

Kotlin Multiplatform: Building Production-Ready Applications with Confidence

Porting Google's Java Logging Framework to Kotlin Multiplatform

VIE

2 of 63

Sponsors

2

VIE

3 of 63

Housekeeping

http://kotlin.wien

-XenableGarbageCollection

3

VIE

4 of 63

News

  • Find us on LinkedIn

4

VIE

5 of 63

Community Interview

VIE

6 of 63

1 Volunteer

7 easy Questions

Your favourite topic

In German or English

6

VIE

7 of 63

Community Interview

Who are you in one sentence?

How long have you been working with Kotlin?

What are you working on (in Kotlin)?

How is Kotlin used in this project?

Tell us about a Kotlin win.

Tell us about a Kotlin fail.

Any problems/wins using Java Libraries?

Kotlin Frameworks / Features:

  • Arrow
  • AtomicFu
  • Coroutines
  • Exposed
  • Gradle DSL
  • HTML DSL
  • Kodein
  • KotlinX-IO
  • Kotlin Serialization
  • Ktor
  • Ktorm
  • MockK
  • TornadoFx

7

VIE

8 of 63

Upcoming Schedule 2024

April: Java Vienna: "Deep dive into Hibernate� ORM 6.4 features" + TBA 8th April

April: Kotlin Vienna: Meet up @ Sentry.io 23rd April

May: Java Vienna Meetup - Venkat Edition! 6th May

May: KotlinConf 2024 Global Watchparty 23rd May� with Kotlin Vienna

8

VIE

9 of 63

Contact us

If you have any questions or want to get in touch with us, you are more than welcome to do so!

Our contact information:

meetup@kotlin.wien

9

VIE

10 of 63

Welcome @ Meister

Kotlin Vienna

11 of 63

Meister

Tools that Work for You

12 of 63

MindMeister

It all starts with an idea.

13 of 63

MeisterTask

Your Team. Aligned.

14 of 63

MeisterNote

Write Here. Write Now.

15 of 63

Tech

Write Here. Write Now.

16 of 63

17 of 63

KMP: Building Production-Ready Application with Confidence

18 of 63

Agenda

Introduction

KMP overview

KMP at Meister

Tips & Tools

19 of 63

Introduction

Arcadii Rubailo

    • from Moldova 🇲🇩, moved to Vienna in 2021
    • 6+ years in Android development
    • at Meister for 3+ years
    • worked on MindMeister Android
    • working on MeisterTask Android/KMP

20 of 63

Kotlin Multiplatform overview

Refresh KMP knowledge

21 of 63

KMP quiz

A simple way to stress people

  • Random questions about KMP
  • Past, present and future
  • Kahoot! -> Competitive
  • Prizes!

22 of 63

KMP at Meister

A new technology for a new product

23 of 63

MeisterTask Notes

Your Projects Need Documentation

  • Collaborative documentation for teams
  • Launched in 2021
  • No mobile applications until recent
  • Suboptimal mobile browser experience

24 of 63

Notes to Mobile

It is alive live!

25 of 63

What is shared

Native vs common

26 of 63

How it is shared

Artifacts distribution flow

27 of 63

Tips & Tools

Boost your confidence

28 of 63

Testing!

Why is it especially important for KMP?

  • No manual QA process
  • No native client to check on
  • TDD process
  • Run ./gradlew allTests

29 of 63

Testing!

Kover

  • Monitor test coverage
  • Kotlin/kotlinx-kover
  • Only JVM target for now
  • Works with Kotlin-specific features
  • Run ./gradlew koverVerify

30 of 63

Testing!

Platform-specific tests

  • Checking Koin modules in src/androidInstrumentedTest

  • Verifying Build config in src/iosTest

31 of 63

API validation

Monitor changes to your public API

  • Check native sees API
  • Avoid unintentional API changes
  • How much is exposed to native
    • kotlin { explicitApi() }
    • publicinternal
    • @HiddenFromObjC

32 of 63

API validation

Monitor changes to your public API

  • Kotlin/binary-compatibility-validator
  • Dumps public Kotlin API via ./gradlew apiDump
  • Checks for changes via ./gradlew apiCheck

33 of 63

API validation

Monitor changes to your public API

  • DevSrSouza/kmp-swift-reveal
  • Creates a Swift representation of Objective-C header
  • Uses Source Kitten under the hood
  • Doesn’t validate against previous API version

34 of 63

Publishing

What? Where? How?

  • KMMBridge helps with XCFramework distribution
  • mavenPublishArtifacts()
  • manualVersions()
  • spm()

35 of 63

Publishing

What? Where? How?

36 of 63

Publishing

Maven vs Package.swift

  • A problem with -SNAPSHOT versions
  • SPM needs a direct url to the file
  • Maven resolves it via metadata
  • Solution: force resolution of KMP XCFramework artifacts via a detached Gradle configuration
  • https://github.com/touchlab/KMMBridge/issues/217

37 of 63

Swift golden hammer

SKIE - Swift Kotlin Interface Enhancer

Generates Swift enum wrappers for both Kotlin enums and sealed classes

Allows to create interface extensions

Supports only Flow to AsyncSequence interoperability

Requires an update to support a new Kotlin version

38 of 63

Q&A

Any Questions?

39 of 63

40 of 63

Giancarlo Buenaflor (Gino)

Porting Google’s Java Logging Framework to Kotlin Multiplatform

(New Grad) Software Engineer @ Sentry

  • Flutter & Kotlin Multiplatform SDK @ Sentry
  • Google Summer of Code ‘23
  • KotlinConf. ‘24 Speaker
  • KMP Podcast/Video with Jetbrains

41 of 63

Google Summer of Code 2023

20K+ Contributors

850+ Open Source Organizations

Including Kotlin Foundation - but I need a proposal first

42 of 63

Working on a Google specific project?

Just read the Kotlin slack channel :D

43 of 63

Proposal accepted

Google & Jetbrains engineers as mentors

Several Google teams were showing interest for this project

44 of 63

What is Flogger?

Main logging framework for Java/Kotlin projects within Google

Less bytecode generated

45 of 63

What’s expected

Flogger -> KFlogger

Usable with Kotlin Multiplatform for mainly iOS and JVM

Implement basic logging functionality

Keep original Java Flogger codebase

46 of 63

Bazel / Blaze

Why Bazel? Because Google uses it

No idea how it’s supposed to work with KMP

Let’s just use Gradle -> great! but wait… Flogger uses Bazel so I need to compile Flogger in Gradle first

47 of 63

Porting Blaze to Gradle

Actually straightforward if you understand it

What dependency versions are used?

48 of 63

expect/actual typealias

typealias: provide alternative names for existing types

Cons:

  • brittle - can lead to runtime errors
  • not well documented
  • Kotlin / Java interop is not perfect
  • seems ‘hacky’?

Pros:

  • less code

49 of 63

kotlinx-datetime

JVM:

Common:

50 of 63

kotlinx-serialization

JVM:

Common:

Just ignore the errors!

51 of 63

KFlogger

JVM:

Common:

52 of 63

Caveats

  • Signatures have to match 1:1
  • Types used within the expected class also need to be typealiased
  • Kotlin Companion objects != Java static
  • Visibility modifiers
  • Doesn’t work with inner classes directly
    • Need to separate the inner class and typealias that
  • Just ignore errors and test the api

53 of 63

Testing typealiases

Test for runtime errors

54 of 63

How to typealias Java’s Class?

Java Flogger

Using KClass directly won’t work

  • It’s an interface
  • does not map 1:1 with a Java Class
  • access the Java Class through .java

55 of 63

Klass

Common

iOS

JVM

56 of 63

iOS implementation

  • Barebones implementation since Flogger is a big library
  • No reflection on Kotlin/Native

57 of 63

Testing with Truth / Kruth

Truth is Google’s testing framework for Java/Kotlin projects

Kruth -> KMP version

Only dev builds available

58 of 63

What about compatibility?

  • binary-compatibility-validator
    • As the name suggests, only binary compatibility
  • Metalava
    • Used in Android at Google
    • Source & binary compatibility
    • Has edges cases that it doesn’t cover
    • KMP support is minimal
  • No perfect solution exists yet

59 of 63

What about compatibility?

Google’s current solution: write manual tests

60 of 63

KFlogger usage

61 of 63

Internal politics

Flogger Team is very passionate about the framework

.. and they disliked the KFlogger project

gave quite some pushback

62 of 63

Completion

Only an experimental project

63 of 63

Thanks!

Feel free to ask questions!