Racka N
07/28/2022, 5:39 AM@Serializable annotations have been removed despite adding the required rules for kotlinx.Serialization and I get a runtime crash when I initiate a network call. SLF4J also gets removed.spierce7
07/28/2022, 5:45 AMmcpiroman
07/28/2022, 8:25 AMRacka N
07/28/2022, 8:32 AMIOException warnings. Would love to take a look at your build.gradle @mcpiromanRacka N
07/28/2022, 8:35 AMmcpiroman
07/29/2022, 9:18 AMval projectJars = project.rootProject.allprojects.flatMap { proj -> proj.tasks.withType(Jar::class.java).flatMap { it.outputs.files } }
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>
val (obfuscatedFiles, notObfuscatedFiles) = allJars.partition {
it in projectJars ||
("-" + it.name).contains("-desktop-")
}
fun mapObfuscatedJarFile(file: File) =
File("${project.buildDir}/tmp/obfuscated/${file.nameWithoutExtension}.min.jar")
val obfuscate by tasks.registering(proguard.gradle.ProGuardTask::class)
compose.desktop {
application {
/* ... */
disableDefaultConfiguration()
fromFiles(obfuscate.get().outputs.files.asFileTree)
fromFiles(notObfuscatedFiles)
mainJar.set(tasks.jar.map { RegularFile { mapObfuscatedJarFile(it.archiveFile.get().asFile) } })
}
}
tasks {
obfuscate.configure {
dependsOn(jar.get())
for (file in obfuscatedFiles) {
injars(file)
outjars(mapObfuscatedJarFile(file))
}
libraryjars("${compose.desktop.application.javaHome ?: System.getProperty("java.home")}/jmods")
libraryjars(notObfuscatedFiles)
configuration("<http://proguard-rules.pro|proguard-rules.pro>")
}
}mcpiroman
07/29/2022, 9:20 AMRacka N
07/29/2022, 9:35 AMnotObfuscatedFiles part. Why are you filtering out jars with "-desktop-"?
I actually got it to stop removing my @Serializable classes but seems like there's more stuff missing because Ktor doesn't work and now I just get java.lang.RuntimeException: java.lang.NoSuchFieldException: top error when I do network calls.Racka N
07/29/2022, 9:41 AM-dontobfuscate and that seems to have solved my issue with Ktor. Though would really like to have it obfuscate things. That'll do for now. The package is now 52MB instead of the 90MB it was.
Have you managed to setup the defined obfuscate task to only run when you use the packageX tasks or createDistributable and not when you just do a simple :run task? Because right now I runs the obfuscate task even when you do gradlew :run and this can slow down development a bit since the run task doesn't even use the obfuscated jar.mcpiroman
07/30/2022, 7:24 AMWhy are you filtering out jars with "-desktop-"?Actually, I don't remember.
right now I runs the obfuscate task even when you doFor development I always use the IJ'sand this can slow down development a bit since thegradlew :runtask doesn't even use the obfuscated jar.run
Kotlin, not `Gradle`configuration (created e.g. when you click the green triangle next to the main function) and that does not trigger obfuscation. Sometimes I `runDistributable`to check whether the resulting build works. And I don't remember if I use `run`itself, but I also have a feeling that it was not slowed down.Racka N
07/30/2022, 8:13 AM:run itself definitely triggers proguard. I totally forgot about running from Main function. I always use :run and :runDistributable (for testing distributable). Oh well, I already used an environment variable to disable or enable Proguard.