This is an example project with a set of solutions to typical problems, demonstrating the creation of an application for the desktop (JVM) using Kotlin Multiplatform.
- Project architecture - Clean Architecture
- UI layer architecture - Compose + MVVM
- Dependency Injection
- Local database (SQL)
- Shared preferences (with custom classes storage)
- HTTP API usage
- WebSocket API usage
- Proguard configuration (with obfuscation)
- Two-layer screen navigation (screen flows and screens)
- App-wide dialogs and snackbars
- Images loading from network
- Material 3 theme configuration
- Dark/Light theme with auto and manual selection
- Strings localization
- Launch arguments
- Screen-scoped hotkeys
- Basic PDF viewer
- Various custom UI elements
- HTTP - dog.ceo
- WebSocket - websocket.org
This project was created and tested using IntelliJ IDEA. All further instructions are provided for this IDE.
In IDE:
Run -> Edit Configurations -> + (Add New Configuration) -> Gradle
Under the Run
header add these arguments in input field, then save the configuration:
desktopRun -DmainClass=ru.rznnike.demokmp.app.MainKt --quiet
At the line Environment variables
add DEBUG=true
to change debug mode flag automatically on launch.
You can run a Kotlin application with arguments that will be passed to the main() function.
Create run configuration with arguments like that:
desktopRun --args="'foo foo2' bar" -DmainClass=ru.rznnike.demokmp.app.MainKt --quiet
This example will run the program with two arguments: "foo foo2" and "bar".
& ".\ru.rznnike.demokmp.exe" "foo foo2" bar
This project is configured to create builds for Windows and Linux. If you want to build it for macOS, update the nativeDistributions
section in build.gradle.kts
accordingly.
To create a distributable build, run createDistributable
(without Proguard) or createReleaseDistributable
(with Proguard) Gradle task.
To create an installer, run packageDistributionForCurrentOS
or packageReleaseDistributionForCurrentOS
accordingly.
Note: you can build your application only for the OS you are currently using. If, for example, you use Windows and need to create a build for Linux, consider doing it in a virtual machine.
Note 2: there is a dummy android
target in the project configuration. It's not configured correctly (and doesn't have the proper sources to work). This target is only added to fix a bug in the KSP plugin where it will not work if there is only one target in the project configuration.