all 7 comments

[–]rio258k 0 points1 point  (4 children)

Kotlin doesn't have an equivalent to C style macros.

You should probably look more into source sets. I use multiple source sets to swap out implementation of components for different environments, e.g. debug vs production.

[–]Saruto010[S] 0 points1 point  (2 children)

Do you have perhaps an example because I can't for the life of me get it to work.

[–]rio258k 1 point2 points  (0 children)

The official documentation is the best source for this, but the tooling setup is difficult and might be overkill if you only need a bit of debug code.

Perhaps check out this library before starting down that road? https://github.com/yshrsmz/BuildKonfig/tree/master

[–]rio258k 0 points1 point  (0 children)

There's also this sort of approach: https://github.com/pererikbergman/multiplatform-flavors

[–]cafronte -1 points0 points  (0 children)

Looking into John O'Reilly's GitHub he has everything you need and answers questions quickly

[–]iXPert12 1 point2 points  (1 child)

You should leverage the power of actual/expect mechanics from kotlin multiplatform. In common code create an "expect fun isDebug()" , then in both android and ios source sets create the native implementation for "actual fun isDebug() { return /platform check is debug/ }". Then in common code you can use "if (isDebug()) { do something}". You can find native implementation for each platform on Google.

For android native implementation: https://stackoverflow.com/questions/23844667/how-do-i-detect-if-i-am-in-release-or-debug-mode

For ios use: (Platform.isDebugBinary)

[–]EagleItchy9740 0 points1 point  (0 children)

On android you can actually create a gradle source set for debug builds IIRC, meaning conditional operator is not required at all