Last active
February 12, 2023 19:53
-
-
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