I do it like this in main.kt:
val bundleLocation = System.getProperty("compose.application.resources.dir")?.let { File(it) } ?: File(".")
LaunchedEffect(Unit) {
try {
withContext(Dispatchers.IO) {
KCEF.init(
builder = {
installDir(File(bundleLocation, "kcef-bundle")) // recommended, but not necessary
progress {
onDownloading {
println("KCEF INIT: $it%")
// use this if you want to display a download progress for example
}
onInitialized {
println("KCEF INIT: SUCCESS")
}
}
},
onRestartRequired = {
println("KCEF INIT: Restart is required.")
// all required CEF packages downloaded but the application needs a restart to load them (unlikely to happen)
},
onError = { error ->
println("KCEF ERROR: ${error?.message}")
}
)
}
} catch (e: Exception) {
println("KCEF EXCEPTION: ${e.message}")
}
}
Then I have some logs after initializing:
JCEF(42:28:299): initialized stderr logger, severity=LOGSEVERITY_DEFAULT JCEF_I(42:28:301): CefApp: set state NEW JCEF_I(42:28:479): CefApp: set state INITIALIZING JCEF_V(42:28:480): Initialize CefApp on Thread[https://github.com/KevinnZou/compose-webview-multiplatform/issues/68,CefInitialize-thread,5,main]
And if I want to add this piece of code:
Window(
onCloseRequest = ::exitApplication,
title = "project",
state = rememberWindowState().apply {
placement = WindowPlacement.Fullscreen
},
undecorated = true
) {
// now no code
}
I have a build crash with this exception:
- Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':composeApp:run'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:130) at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:293) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:128)... I have no idea, what's wrong. Please help.
There are my dependencies only for KCEF:
allprojects {
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
maven("https://jogamp.org/deployment/maven")
}
}
implementation("dev.datlag:kcef:2025.03.23")
jvmArgs("--add-opens", "java.desktop/sun.awt=ALL-UNNAMED")
jvmArgs("--add-opens", "java.desktop/java.awt.peer=ALL-UNNAMED") // recommended but not necessary
jvmArgs += listOf(
"--add-opens=java.desktop/sun.java2d=ALL-UNNAMED",
"--add-opens=java.desktop/sun.awt.windows=ALL-UNNAMED",
"-Dkcef.verbose=true",
"-Dprism.order=sw",
"-Dprism.verbose=true"
)