1

I have an app built with Jetbrains Compose Multiplatform

I need to generate two builds, i.e. .msi(Microsoft Software Installer) file.
One for internal use and one for external. Example: AppInternal.msi and AppExternal.msi
Because I have some sensitive code which I want to package inside internal build only.

This can be achieved in Android via build variants and product flavours:

 productFlavors {
        internal {
            dimension "version"
            buildConfigField("boolean", "IS_INTERNAL", "true")
            ...
        }
        external {
            dimension "version"
            ...    
        }
    }

And then in source code we do something like:

if (IS_INTERNAL) {
    // Perform required steps
}

Please refer to this official-documentation for more details.

However, there are no such steps provided for Desktop for Compose.
So how can we have two builds inside Jetbrains Compose Multiplatform project ?

1 Answer 1

1

You can use this for incremental compilation or: "I made a quick test with this

const val DEBUG = true Then in Vector2:

 fun slerp(b: Vector2, t: RealT): Vector2 {
        if (DEBUG) {
            require(this.isNormalized() && b.isNormalized()) { "Both this and b vector must be normalized!" }
        }
        val theta: RealT = angleTo(b)
        return rotated((theta * t))
    }

Note: if (DEBUG) is line 402.

This leads to this bytecode:

L0
    ALOAD 1
    LDC "b"
    INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkNotNullParameter (Ljava/lang/Object;Ljava/lang/String;)V
   L1
    LINENUMBER 402 L1
    NOP
   L2
    LINENUMBER 403 L2
    ALOAD 0
    INVOKEVIRTUAL godot/core/Vector2.isNormalized ()Z
    IFEQ L3
    ALOAD 1
    INVOKEVIRTUAL godot/core/Vector2.isNormalized ()Z
    IFEQ L3
   L4
    ICONST_1
    GOTO L5
   L3
    ICONST_0
   L5
    ISTORE 4
   L6
   L7
    ILOAD 4
    IFNE L8
   L9
   L10
    LINENUMBER 521 L10
   L11
    ICONST_0
    ISTORE 5
   L12
    LINENUMBER 403 L12
    LDC "Both this and b vector must be normalized!"
   L13
   L14
    LINENUMBER 403 L14
    ASTORE 5
   L15
    NEW java/lang/IllegalArgumentException
    DUP
    ALOAD 5
    INVOKEVIRTUAL java/lang/Object.toString ()Ljava/lang/String;
    INVOKESPECIAL java/lang/IllegalArgumentException.<init> (Ljava/lang/String;)V
    ATHROW
   L8
    LINENUMBER 405 L8
    ALOAD 0
    ALOAD 1
    INVOKEVIRTUAL godot/core/Vector2.angleTo (Lgodot/core/Vector2;)D
    DSTORE 4
   L16
    LINENUMBER 406 L16
    ALOAD 0
    DLOAD 4
    DLOAD 2
    DMUL
    INVOKEVIRTUAL godot/core/Vector2.rotated (D)Lgodot/core/Vector2;
    ARETURN
   L17
    LOCALVARIABLE $i$a$-require-Vector2$slerp$1 I L12 L14 5
    LOCALVARIABLE theta D L16 L17 4
    LOCALVARIABLE this Lgodot/core/Vector2; L0 L17 0
    LOCALVARIABLE b Lgodot/core/Vector2; L0 L17 1
    LOCALVARIABLE t D L0 L17 2
    MAXSTACK = 5
    MAXLOCALS = 6

As we can see we have no operation for if line, and then all require expression code.

If I set

const val DEBUG = false Then this leads to this bytecode:

 L0
    ALOAD 1
    LDC "b"
    INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkNotNullParameter (Ljava/lang/Object;Ljava/lang/String;)V
   L1
    LINENUMBER 402 L1
    NOP
   L2
    LINENUMBER 405 L2
    ALOAD 0
    ALOAD 1
    INVOKEVIRTUAL godot/core/Vector2.angleTo (Lgodot/core/Vector2;)D
    DSTORE 4
   L3
    LINENUMBER 406 L3
    ALOAD 0
    DLOAD 4
    DLOAD 2
    DMUL
    INVOKEVIRTUAL godot/core/Vector2.rotated (D)Lgodot/core/Vector2;
    ARETURN
   L4
    LOCALVARIABLE theta D L3 L4 4
    LOCALVARIABLE this Lgodot/core/Vector2; L0 L4 0
    LOCALVARIABLE b Lgodot/core/Vector2; L0 L4 1
    LOCALVARIABLE t D L0 L4 2
    MAXSTACK = 5
    MAXLOCALS = 6

" All require code is removed.

As we’re “dexifying” our jar for android and graal native image rely on jvm compiled bytecode, this should do the job !

https://discuss.kotlinlang.org/t/any-plans-for-having-conditional-compiling/1041/15

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.