Last active
June 6, 2024 05:03
-
-
Save mcpiroman/cf511c5f9312a59e8f821706738eeab3 to your computer and use it in GitHub Desktop.
Compose for Desktop with Proguard setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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
Saw this through a comment that references this Gist on Compose Desktop repository,
I'm not sure why you're excluding all Kotlin imports from minimizations using
-keep class kotlin.** { *; }
in case you're using
-dontwarn kotlin.**
I suggest using
injars(sourceSets.main.get().compileClasspath)
instead in your Proguard task, in my case, this solves the warnings issue from Kotlin imports without ignoring the warnings or having them at all.