From 8f1f049a23507e98067e8bfbbaff62e1af8aedbc Mon Sep 17 00:00:00 2001 From: Max Rumpf Date: Tue, 11 Jan 2022 15:33:50 +0100 Subject: [PATCH] Improve obfuscation docs and add ProGuard example (#1658) --- .../README.md | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tutorials/Native_distributions_and_local_execution/README.md b/tutorials/Native_distributions_and_local_execution/README.md index b8481000fd..5dad5d495a 100755 --- a/tutorials/Native_distributions_and_local_execution/README.md +++ b/tutorials/Native_distributions_and_local_execution/README.md @@ -547,6 +547,39 @@ fun main() { ## Obfuscation -To obfuscate Compose Multiplatform JVM applications standard approach for JVM application works. Using task packageUberJarForCurrentOS one could generate JAR file which could be later obfuscated using ProGuard or R8, see for example https://stackoverflow.com/questions/64355998/proguard-example-for-gradle-java-application. +To obfuscate Compose Multiplatform JVM applications the standard approach for JVM applications works. +With the task `packageUberJarForCurrentOS` one could generate a JAR file which could be later obfuscated using ProGuard or R8. -Also example in the document using Kotlin DSL would be better, as above link uses Groovy. +### ProGuard example + +``` kotlin +// build.gradle.kts + +// Add ProGuard to buildscript classpath +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("com.guardsquare:proguard-gradle:7.1.1") { + exclude("com.android.tools.build") + } + } +} + +// ... + +// Define task to obfuscate the JAR and output to .min.jar +tasks.register("obfuscate") { + val packageUberJarForCurrentOS by getting + dependsOn(packageUberJarForCurrentOS) + val files = packageUberJarForCurrentOS.outputs.files + injars(files) + outjars(files.map { file -> File(file.parentFile, "${file.nameWithoutExtension}.min.jar") }) + + val library = if (System.getProperty("java.version").startsWith("1.")) "lib/rt.jar" else "jmods" + libraryjars("${System.getProperty("java.home")}/$library") + + configuration("proguard-rules.pro") +} +```