Skip to content

Platform Class

The Platform class provides platform-specific information inside shared code in a clean and type-safe way.

It exposes:

  • OS version
  • Debug state
  • App information (version code, version name, app name)
  • Dynamic color support

You can easily detect whether the app is running in debug mode:

if (platform.debug) {
    // Debug-only logic (logging, test flags, mock configs)
}

This is useful for:

  • Enabling verbose logging
  • Reducing Remote Config fetch interval
  • Disabling analytics in debug builds

OS Version

Access the platform OS version:

val osVersion = platform.osVersion

Android

  • Returns Build.VERSION.SDK_INT

iOS

  • Returns major OS version as Int
  • Full version is available via exactVersion
platform.ifIos { ios->
    val major = ios.exactVersion.major
    val minor = ios.exactVersion.minor
    val patch = ios.exactVersion.patch
}

App Info

val versionCode = platform.appInfo.version
val versionName = platform.appInfo.versionName
val appName = platform.appInfo.appName

AppInfo contains shared metadata for both platforms.


Platform Types

Platform is a sealed class with two implementations:

Android

Platform.Android(
    osVersion: Int,
    debug: Boolean,
    appInfo: AppInfo
)
  • isDynamicColorSupported = osVersion >= 31 (Android 12+)

iOS

Platform.Ios(
    osVersion: Int,
    debug: Boolean,
    appInfo: AppInfo,
    exactVersion: IosVersion
)
  • Provides detailed iOS version via exactVersion
  • Dynamic color is not supported

Platform Checks

if (platform.isAndroid) {
    // Android logic
}

if (platform.isIos) {
    // iOS logic
}

Or use helpers:

platform.ifAndroid { android->
    // Android-only code
}

platform.ifIos { ios->
    // iOS-only code
}

Dynamic Color Check

if (platform.isDynamicColorSupported) {
    // Enable dynamic colors (Android 12+)
}

This keeps shared code platform-aware, centralized, and clean without scattering platform checks across the codebase.


Support My Project ☕️

If you find this project useful, consider supporting it by buying me a coffee. Your support will help me to continue working on this project and add more features.