Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). Depending on the build type (debug or release) I want to configure the logging level (i.e. to print only errors in release). Since there is no a BuildConfig class available, how can I know from commonMain the build type?

like image 951
Diego Palomar Avatar asked Jan 18 '19 13:01

Diego Palomar


People also ask

Is Kotlin good for multiplatform?

With Kotlin Multiplatform, you can create different multiplatform projects for multiple platforms, including web, desktop, and other native platforms. Kotlin applications will work on different operating systems, such as macOS, Windows, Linux, Android, iOS, watchOS, and others.

Is Kotlin multiplatform production ready?

KMP gives us an unprecedented opportunity to share business logic written in Kotlin between Android and iOS native mobile applications. The technology has already proven itself a production-ready solution applied by many large, medium, and small companies, even though it's only in the alpha stage.

Is Kotlin a crossplatform?

With Kotlin Multiplatform Mobile, you can build cross-platform mobile applications and share common code between Android and iOS, such as business logic, connectivity, and more.


1 Answers

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
like image 86
josias Avatar answered Oct 09 '22 21:10

josias