Did anyone successfully use Proguard? I'm hitting ...
# compose-desktop
m
Did anyone successfully use Proguard? I'm hitting this issue: https://github.com/Guardsquare/proguard/issues/349 but turning off that optimization I get an ever more arcane issue. Am I doing something wrong?
1
a
I had similar issue, only fix for me was to add some exclusions to proguard config as mentioned here: https://github.com/JetBrains/compose-multiplatform/issues/3947
So you will have to find out which package to keep in your proguard config, in your case it may not be
androidx.compose.**
m
-keep class androidx.compose.runtime.** { *; }
did fix one of the issues, going through them one by one
😬 1
s
Yes, Ashampoo Photos uses ProGuard. I had some difficulties in the past. I ended up with something rather radical 😄
Copy code
-dontwarn !com.ashampoo.photos.**
-keep class !com.ashampoo.photos.** { *; }
In addition to that I only needed the special rules for Multiplatform Compose and KotlinX Serialization, but nothing more.
m
I saw that suggested somewhere but wanted to avoid it. Got my application to build and mostly run now but I'm at 200 lines in my proguard file... Only some issues remaining.
s
I need no obfuscation for the third parties that are all open source anyway. 🤷‍♂️
m
Yeah but the optimization / size decrease is always nice.
s
Ashampoo Photos is around 100 MB, including the JDK. I don’t think people care until you hit a GB or so. 🙂
m
My app is at 102MB now without Proguard, I'd like it double digit. 😄
s
One day I might give it a second try to see how much performance I might gain, but reading that you already have 200 lines and still problems sounds like some effort to pay. 👀
Ashampoo Photos for Android has a proper ProGuard config, because here size really matters, but it wasn’t so problematic like the desktop version.
m
Got it fully working eventually. App download size (after packaging / compressing / etc) went down from 100.0MB to 81.3MB.
s
Nice. Maybe you share your work one day as a Gist or so. 😄
m
If it helps anyone, here is my configuration: https://gist.github.com/Nohus/34c45bc81cde78530deadf09dc498f0d Obviously it includes rules for the particular libraries that needed them in my project, but should be a good reference.
👍 2
thank you color 1
a
-keep class javax.xml.** { *; }
FYI: This is part of the JDK modules and usually not part of your application code so you should include a reference to your JDK instead to avoid unexpected issues thay are difficult to track. See https://github.com/ktorio/ktor-documentation/blob/3.0.0/codeSnippets%2Fsnippets%2Fproguard%2FREADME.md Also it looks like you're keeping some classes (excluding them from minimization) which might make the bundle size bigger, usually we keep them in case that package heavily depends on reflections and dynamic library loading.
m
you should include a reference to your JDK instead
What do you mean by this?
a
Proguard need read access to all libraries including the imports from your JDK which usually is not bundled with your application, and even if it's, it usually separated from your code. Proguard need this to avoid unexpected errors, including those in runtime. Take a look at this example code. See this example issue where I ignore/keep a Java module to be able to build without warnings, though it caused a unexpected issue.
m
That all sounds good, but my application crashes at runtime if I don't
-keep class javax.xml
.