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
Debug Check (Recommended Usage)¶
You can easily detect whether the app is running in debug mode:
This is useful for:
- Enabling verbose logging
- Reducing Remote Config fetch interval
- Disabling analytics in debug builds
OS Version¶
Access the platform OS version:
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¶
isDynamicColorSupported = osVersion >= 31(Android 12+)
iOS¶
- Provides detailed iOS version via
exactVersion - Dynamic color is not supported
Platform Checks¶
Or use helpers:
Dynamic Color Check¶
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.