6

I am currently working on a Compose Multiplatform project. As a mobile app developer, I am able to build APK file for Android and IPA file for iOS.

Now, I want to generate output for desktop applications (DMG for macOS and EXE for Windows) and web applications.

What I tried?

I created the simple hello world project from official KMP Wizard

https://kmp.jetbrains.com/#newProject

I used Fleet IDE to run the application, my project running on all the platforms. No problem in the code.

I checked the official website but couldn't find detailed instructions on how to create these output files.

2

2 Answers 2

7

I found an answer for Desktop applications from Phil Dukhov suggestion,

https://github.com/JetBrains/compose-multiplatform/blob/master/tutorials/Native_distributions_and_local_execution/README.md#basic-usage

Desktop Application Output

Step 1: Add Jetbrains compose plugin

import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
    kotlin("jvm")
    id("org.jetbrains.compose") // this line
}

Step 2: Configure desktop distribution formats

compose.desktop {
    application {
        mainClass = "MainKt"

        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb,TargetFormat.Exe)
            packageName = "com.twt.ajaja"
            packageVersion = "1.0.0"
        }
    }
}

Step 3: Open the terminal and put your project path

cd /path/to/your/project

Step 4: Execute build generation (I am using mac, so I can take only mac build)

./gradlew packageDmg

Note: As of June 12, 2024, cross-compilation is not supported. This means you can only create the .dmg package on macOS. To create .msi, .deb, or .exe packages, you must run the corresponding tasks on Windows or Linux systems respectively.

Step 5: After a build, output binaries can be found in ${project.buildDir}/compose/binaries.

Example:

YourComposeProject/composeApp/build/compose/binaries/main/dmg/your_app.dmg

Web Application Output

Step 1: Configure the webpack config in your gradle file. If you create the project through KMP Wizard, you can skip this step

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
    moduleName = "composeApp"
    browser {
        commonWebpackConfig {
            outputFileName = "composeApp.js"
            devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
                static = (static ?: mutableListOf()).apply {
                    // Serve sources to debug inside browser
                    add(project.projectDir.path)
                }
            }
        }
    }
    binaries.executable()
}

Step 2: Open the terminal at your project path

./gradlew wasmJsBrowserDistribution

Step 3: You can find the wasm output in following path

~YourProjectPath/composeApp/build/dist/wasmJs/productionExecutable 
Sign up to request clarification or add additional context in comments.

3 Comments

I have exported it using the command you mentioned , i got html js files, how to run it without gradle command, i mean what if i want to host it like typical html css js web app? pls help @RanjithKumar
@CodingDevil I am not familiar with web app development. Pls ask a new question, so someone who expert on this will answer you.
hey, i got the solution : official docs: kotlinlang.org/docs/… youtube video: youtu.be/4IQ726Y0Jfc @Ranjithkumar
0

For Desktop, we need to create the Native Distributions & for the Web We need to create the Production Webpack.

For Desktop, you can need to write ./gradlew runDistributable to create the distrbutables those will run directly without any installation on Mac, Windows & Linux. But remember Onething, If you want to create .dmg then you need to run above command on the Macbook or iMac. If you want to create Native Distribution .msi for Windows then you need to run above command on Windows & same of linux too.

If you want to add the custom icons then you need to add this inside your build.gradle.kts

compose.desktop {
application {
    nativeDistributions {
        macOS {
            iconFile.set(project.file("icon.icns"))
        }
        windows {
            iconFile.set(project.file("icon.ico"))
        }
        linux {
            iconFile.set(project.file("icon.png"))
        }
    }
}

}

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.