Skip to content

Instantly share code, notes, and snippets.

@mcpiroman
Last active February 12, 2023 19:53
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mcpiroman/cf511c5f9312a59e8f821706738eeab3 to your computer and use it in GitHub Desktop.
Save mcpiroman/cf511c5f9312a59e8f821706738eeab3 to your computer and use it in GitHub Desktop.
Compose for Desktop with Proguard setup
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
buildscript {
dependencies {
classpath("com.guardsquare:proguard-gradle:7.2.1")
}
}
repositories {
mavenCentral()
}
plugins {
kotlin("jvm") version "1.6.10"
id("org.jetbrains.compose") version "1.1.1"
}
dependencies {
implementation(compose.desktop.currentOs)
}
val obfuscate by tasks.registering(proguard.gradle.ProGuardTask::class)
fun mapObfuscatedJarFile(file: File) =
File("${project.buildDir}/tmp/obfuscated/${file.nameWithoutExtension}.min.jar")
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
}
disableDefaultConfiguration()
fromFiles(obfuscate.get().outputs.files.asFileTree)
mainJar.set(tasks.jar.map { RegularFile { mapObfuscatedJarFile(it.archiveFile.get().asFile) } })
}
}
obfuscate.configure {
dependsOn(tasks.jar.get())
val allJars = tasks.jar.get().outputs.files + sourceSets.main.get().runtimeClasspath.filter { it.path.endsWith(".jar") }
.filterNot { it.name.startsWith("skiko-awt-") && !it.name.startsWith("skiko-awt-runtime-") } // walkaround https://github.com/JetBrains/compose-jb/issues/1971
for (file in allJars) {
injars(file)
outjars(mapObfuscatedJarFile(file))
}
libraryjars("${compose.desktop.application.javaHome ?: System.getProperty("java.home")}/jmods")
configuration("proguard-rules.pro")
}
-keepclasseswithmembers public class MainKt {
public static void main(java.lang.String[]);
}
-dontwarn kotlinx.coroutines.debug.*
-keep class kotlin.** { *; }
-keep class kotlinx.coroutines.** { *; }
-keep class org.jetbrains.skia.** { *; }
-keep class org.jetbrains.skiko.** { *; }
-assumenosideeffects public class androidx.compose.runtime.ComposerKt {
void sourceInformation(androidx.compose.runtime.Composer,java.lang.String);
void sourceInformationMarkerStart(androidx.compose.runtime.Composer,int,java.lang.String);
void sourceInformationMarkerEnd(androidx.compose.runtime.Composer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment