I'm working on a multiplaform project, iOS and JVM (I'm not targeting Android directly). Depending on the build type (debug or release) I want to configure the logging level (ie to print only errors in release). Since there is no a BuildConfig
class available, how can I know from commonMain
the build type?
Not a direct answer to the question, but for android/ios one can define a property like this:
in commonMain:
expect val isDebug: Boolean
in androidMain:
actual val isDebug = BuildConfig.DEBUG
in iosMain:
actual val isDebug = Platform.isDebugBinary
Use expected
and actual
functions. So in the common
, you create something like expect fun isDebugEnabled(): Bool
, then in iOS you implement it by using iOS specific API, similarly for Android.
https://kotlinlang.org/docs/reference/platform-specific-declarations.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.