简体   繁体   English

如何确定 kotlin-multiplatform 项目中的构建类型

[英]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. 使用expectedactual功能。 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.

相关问题 kotlin-multiplatform:如何在 Javascript 中使用 Kotlin Flow - kotlin-multiplatform : how to use Kotlin Flow in Javascript 如何在 Kotlin-Multiplatform 中正确使用两种方式绑定? - How to properly use two way binding in Kotlin-Multiplatform? 我如何使用 Ktor Client For Kotlin-multiplatform 执行这个 cURL? - how can i excute this cURL with Ktor Client For Kotlin-multiplatform? kotlin multiplatform:如何减少构建时间? - kotlin multiplatform: how to reduce build time? Kotlin 多平台项目 - Kotlin multiplatform project Android Studio:如何在 Kotlin 多平台共享模块 build.gradle.kts 中访问项目级 compileSdkVersion 和 targetSdkVersion? - Android Studio: How to access project level compileSdkVersion and targetSdkVersion in Kotlin Multiplatform shared module build.gradle.kts? 项目完成后如何将 Kotlin 项目转换为 Kotlin Multiplatform Mobile? - How to convert Kotlin project to Kotlin Multiplatform Mobile after the project completion? kotlin 多平台项目中的 kotlinOptions - kotlinOptions in kotlin multiplatform project 无法在 MacBook M1 芯片上构建 Kotlin 多平台移动项目 - Unable to build Kotlin Multiplatform mobile project on MacBook M1 chip 如何为 Kotlin Multiplatform 移动项目有效地保持 RAM 中的连续内存 - How to keep efficiently continuous memory in RAM for Kotlin Multiplatform mobile project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM