Skip to content

About

Feature flags for multi-module Kotlin Android projects

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Laboratory ⚗️ — KMP fork

Maven Central

Fork notice. This is a Kotlin Multiplatform fork of MiSikora/laboratory. The original project — authored by Michał Sikora — is Android-only and the canonical source of the design, documentation, and changelog. Please consult the original project website for conceptual docs; this README covers only what differs in the KMP fork.

Feature flags for Kotlin Multiplatform projects — one SDK that works on Android, iOS, and JVM from commonMain.

What changed vs. the original

  • One SDK artifact (laboratory) replaces the per-module :runtime / :data-store / :shared-preferences split from 2.x. DataStore (Okio) is the only storage backend; SharedPreferences support has been removed.
  • Public API uses KClass<out Feature<*>> instead of Class<out Feature<*>>. Call sites change from AuthType::class.java to AuthType::class. Breaking vs. the original 2.x.
  • A new Compose Multiplatform debug inspector (:inspector-cmp) is available for both Android and iOS. On iOS it's exposed as a single-call UIViewController factory.
  • The Android Hyperion plugin and the original Views inspector are kept, Android-only, unchanged behaviorally — Android consumers who use Hyperion keep the exact UX they had on 2.x.
  • The Gradle plugin now supports Kotlin Multiplatform consumers: generated flag sources land in commonMain.

Distribution

The fork is distributed via Maven Central under the io.github.vudzkostek namespace. No CocoaPods — because KMP consumers (both Android and iOS targets inside a shared Kotlin module) resolve the per-target klibs through Gradle, so CocoaPods is only needed for pure-Swift consumers who don't use KMP. If that becomes a need later, we can add a GitHub-Release-hosted XCFramework + hand-maintained podspec.

Setup

// settings.gradle.kts
dependencyResolutionManagement {
  repositories {
    mavenCentral()
    google()
  }
}

pluginManagement {
  repositories {
    mavenCentral()
    gradlePluginPortal()
  }
}

Consume from a KMP shared module

// shared/build.gradle.kts
plugins {
  kotlin("multiplatform")
  id("io.github.vudzkostek.laboratory") version "<VERSION>"
}

kotlin {
  sourceSets {
    commonMain.dependencies {
      // SDK — gives you Feature, Laboratory, Storage, FeatureFactory on all platforms.
      implementation("io.github.vudzkostek:laboratory:<VERSION>")

      // Compose Multiplatform debug inspector. Pull it into a debug-only variant if your build
      // supports that (e.g. a dedicated commonDebugMain source set).
      implementation("io.github.vudzkostek:inspector-cmp:<VERSION>")
    }
    androidMain.dependencies {
      // Android-only Hyperion debug menu entry (optional). Pulls in the original Views inspector.
      debugImplementation("io.github.vudzkostek:laboratory-hyperion-plugin:<VERSION>")
    }
  }
}

laboratory {
  packageName = "com.example.flags"
  feature("AuthType") {
    withDefaultOption("Fingerprint")
    withOption("None")
    withOption("Retina")
    withOption("Face")
  }
  featureFactory()
}

Replace <VERSION> with a published release (e.g. 1.0.1). The gradle plugin uses the same version for its generated api(...) dep by default; override via a laboratory.libraryCoordinate project property if you ever publish Laboratory somewhere else.

Define a feature flag

enum class AuthType : Feature<AuthType> {
  None, Fingerprint, Retina, Face;

  override val defaultOption get() = Fingerprint
}

Use it (common code, works on Android + iOS)

val laboratory = Laboratory.builder()
    .localStorage(storage)                       // Storage.dataStore(context) on Android, Storage.dataStore() on iOS
    .featureFactory(FeatureFactory.generated())  // generated by the Gradle plugin
    .build()

val current = laboratory.experiment<AuthType>()
laboratory.setOption(AuthType.Face)

laboratory.observe<AuthType>()
    .onEach { option -> println("AuthType: $option") }
    .launchIn(scope)

Show the debug inspector

Android — via Compose (any Compose host):

setContent {
  LaboratoryInspector(
    configuration = LaboratoryConfiguration(
      laboratory = laboratory,
      featureFactories = mapOf("Features" to FeatureFactory.generated()),
    ),
  )
}

Android — via Hyperion: The Hyperion menu entry is automatic once you add the hyperion-plugin dep. It opens the original Views inspector — identical UX to the 2.x release.

iOS — from your KMP shared module:

// shared/src/iosMain/.../DebugTools.kt
fun showLaboratory(
    laboratory: Laboratory,
    factory: FeatureFactory,
): UIViewController = LaboratoryViewController(
    configuration = LaboratoryConfiguration(
        laboratory = laboratory,
        featureFactories = mapOf("Features" to factory),
    ),
)

Call it from Swift via your own umbrella framework:

let vc = SharedKt.showLaboratory(laboratory: lab, factory: factory)
present(vc, animated: true)

Samples

  • samples/basic, samples/default-option, samples/multi-module — original Android samples, updated for the KClass API, still using the Views inspector + Hyperion.
  • samples/kmp — new KMP sample demonstrating Android + iOS consumption through the shared SDK and the Compose inspector.

Migration path

The underlying migration plan lives in KMP_MIGRATION_PLAN.md — six phases, each independently buildable, with session notes for the context behind each decision.

License

Copyright 2020 Michał Sikora
Copyright 2026 Artur Kosta (KMP fork contributions)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

About

Feature flags for multi-module Kotlin Android projects

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages