A Demo Application for demonstrating code reuse in Android, iOS and JavaScript apps using Kotlin Multiplatform (KMP).
Specifications:
- 100% Kotlin for Common Kotlin Code, Android and JavaScript modules.
- 100% Swift for iOS.
- Kotlin: 1.7.10.
- Test Driven Development (TDD).
- MVVM design pattern.
- Multi Module KMP Application Setup.
- Unit Testing via Kotest and Mockk.
- Multiplatform Dependency Injection using Koin.
- Multiplatform Concurrency using Kotlin Coroutines.
- Multiplatform Database using SQLDelight.
- Multiplatform Network Client using Ktor.
- Ktlint for lint.
- Jetpack Compose for Android.
- SwiftUI for iOS.
- KVision for Web. Project Live Demo.
- CI-CD using Github Actions.
- Kermit - Better iOS Crash Report Logging on Kotlin code crashes.
- KMP Modules Deployment as libraries for external
Android
,iOS
andJavaScript
apps. - Firebase Crashlytics. Add
google-services.json
for Android andGoogleService-Info.plist
for iOS.
All advantages and freedom of native development + code re-usability in other platforms.
Module | sloc count |
---|---|
helpers | 491 |
core | 289 |
feature_pokemon_list | 428 |
Total | 1208 |
App | sloc count | exclusive code % | common code % |
---|---|---|---|
android | 210 | 17.38% | 82.62% |
ios | 130 | 10.76% | 89.24% |
Around ~80% code written for a feature can be reused for other platform using KMP.
Android | iOS | Web |
---|---|---|
- helpers - Generic helper methods for mobile apps
- core - Application specific common code which are shared by mostly all feature modules
- feature_* - Feature module
- iosUmbrellaModule - Umbrella module for ios. This module loads all sub gradle modules and creates a single framework file for adding to ios project. Also iOS specific helper code which needs kotlin access should be put here. Treat it as extension of iOS module with Kotlin support.
- android - Android host app
- ios - iOS host app
- web-kvision - Web host app
Each individual feature folder structure
-
/data (All data related files)
- /entity_1 (for e.g: Person)
- /model
- /dao
- /network
- repository
- /entity_1 (for e.g: Person)
-
/presentation (All view related files)
- /component_1 (for e.g: Person List)
- /fragment
- /viewmodel
- /adapter
- /view
- /component_1 (for e.g: Person List)
Install following plugins from Preferences -> Plugins
- Kotlin Multiplatform Mobile.
- Kotest
Lighthouse Performance: 82
Steps taken to improve performance from 50 to 82 on Web:
- Remove SQL.js Dependency (> 1 MB) for SQL based PokemonDao with WebPokemonDao, In-Memory Dao implementation, for Web.
- Overriding it in DI.
- Setup Brotli Compression in Webpack
- Use SVG Pokemon images.
Run using Android
Configuration or using gradle task installDebug
- Open
ios
folder in Mac Finder and double-clickios.xcodeproj
and run from Xcode.
- Check Project Live Demo
- Run on local machine: gradle task
web-kvision:run -t
- The KMP libraries can be directly accessed by the embedded
Android
,iOS
andJavaScript
module in this project. - If these KMP libraries is to be used as independent libraries in external apps, it can be published to maven repository.
publishToMavenLocal
task will build and upload the KMP modules as libraries in local maven server which can be used to work in externalAndroid
,iOS
andJavaScript
apps in same machine.publish
task will build and upload the KMP modules as libraries in remote maven server which can be accessed from any machine. Remote maven configuration to be added inplugins/publish.gradle
.
- For
Android
, the process is simple as adding gradle dependencies in the app to load these hosted libraries. - For
iOS
, reference can be taken from this project or follow this guide. Pro tip: Keep KMP files inside a folder and not at root level to keep it encapsulated from nativeiOS
project files and modify the configuration to support this. - For
JavaScript
, if using Kotlin Application like KVision , the process is simple as adding gradle dependencies in the app to load these hosted libraries.
- Test cases
- UI Event handling
- Dependency injection framework
- CI
- Code Generation templates
PokeAPI - The RESTful Pokémon API
All the Pokémon data you'll ever need in one place, easily accessible through a modern RESTful API.
Copyright 2022 Harshith Shetty ([email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.