[英]How to determine build type in kotlin-multiplatform project
I'm working on a multiplaform project, iOS and JVM (I'm not targeting Android directly).我正在开发一个多平台项目,iOS 和 JVM(我不直接针对 Android)。 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?由于没有可用的
BuildConfig
类,我如何从commonMain
知道构建类型?
Not a direct answer to the question, but for android/ios one can define a property like this:不是这个问题的直接答案,但对于 android/ios 可以定义这样的属性:
in commonMain:共同点:
expect val isDebug: Boolean
in androidMain:在androidMain中:
actual val isDebug = BuildConfig.DEBUG
in iosMain:在 iosMain 中:
actual val isDebug = Platform.isDebugBinary
Use expected
and actual
functions. 使用
expected
和actual
功能。 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. 因此,在
common
,您可以创建类似于expect fun isDebugEnabled(): Bool
,然后在iOS中使用iOS专用API来实现它,类似于Android。
https://kotlinlang.org/docs/reference/platform-specific-declarations.html https://kotlinlang.org/docs/reference/platform-specific-declarations.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.