Skip to content

har5hit/PokeDex-KMP

Repository files navigation

PokeDex KMP

License Android CI Web CI-CD

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 and JavaScript apps.
  • Firebase Crashlytics. Add google-services.json for Android and GoogleService-Info.plist for iOS.

Blog for more details

Why KMP?

All advantages and freedom of native development + code re-usability in other platforms.

Source Line of Code Stats:

Common Module (KMP)

Module sloc count
helpers 491
core 289
feature_pokemon_list 428
Total 1208

Host apps (Containing views and di code)

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.

Screenshots

Android iOS Web

Architecture

Overview

Module Structure

  • 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

Application Structure

Each individual feature folder structure

  • /data (All data related files)

    • /entity_1 (for e.g: Person)
      • /model
      • /dao
      • /network
      • repository
  • /presentation (All view related files)

    • /component_1 (for e.g: Person List)
      • /fragment
      • /viewmodel
      • /adapter
      • /view

Plugins

Install following plugins from Preferences -> Plugins

  • Kotlin Multiplatform Mobile.
  • Kotest

Web Performance

Lighthouse Performance: 82
Performance
Steps taken to improve performance from 50 to 82 on Web:

Run

Android

Run using Android Configuration or using gradle task installDebug

iOS

  • Open ios folder in Mac Finder and double-click ios.xcodeproj and run from Xcode.

Web

Deployment as library

  • The KMP libraries can be directly accessed by the embedded Android, iOS and JavaScript 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 external Android, iOS and JavaScript 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 in plugins/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 native iOS 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.

TODO

iOS

  • Test cases
  • UI Event handling
  • Dependency injection framework
  • CI

Common

  • Code Generation templates

Resources

Pokemon Data

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.

App Icon

License

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.

About

PokeDex using Kotlin Multiplatform

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published