Does anybody have the proguard setup <outlined in ...
# compose-desktop
s
Does anybody have the proguard setup outlined in the tutorial set up in a real project (I'm getting some errors in the buildscript, so maybe some details aren't 100% working and needs some polishing?) In particular I'm getting "Unresolved reference" for 
val packageUberJarForCurrentOS by getting
m
Try
val packageUberJarForCurrentOS by tasks.getting
. I'm not sure how it is supposed to work without
tasks.
but OTOH I've seen such examples.
s
that seems to work, do you want to propose the update to the tutorial yourself or are you OK if I do it?
m
totally ok if you do taht
Btw are you going to use native distribution with it? I'd like to do that but looks not possible (easily) with the described approach.
s
ideally, yes, but I haven't gotten this far yet. Ah, you mean it's not going to be easy because that approach will produce a minified jar, but it is not this jar that is going to be packaged to *.deb, *.dmg etc?
👍 1
another thing that would probably be very useful in the tutorial are proguard
-keep
rules that are typically required in order for compose, skia et al to keep working
for example I'm currently facing
Copy code
java.lang.NoSuchMethodError: <init>
        at org.jetbrains.skia.impl.Library._nAfterLoad(Native Method)
        at org.jetbrains.skia.impl.Library$Companion._nAfterLoad(Library.jvm.kt)
        at org.jetbrains.skiko.Library.load(Library.kt:66)
        at org.jetbrains.skia.impl.Library$Companion.staticLoad(Library.jvm.kt:12)
        at org.jetbrains.skia.Data.<clinit>(Data.kt:60)
and I haven't yet figured out what to do
j
btw I noticed this in the tutorial: ProGuard version 7.2.0 was released recently and also the dependency exclude for Android build tools should no longer be required https://github.com/JetBrains/compose-jb/pull/1777
👍 1
s
This proguard configuration seems to work:
Copy code
-dontoptimize
-dontobfuscate

-dontwarn org.jetbrains.skiko.**
-dontwarn org.jetbrains.skia.**
-dontwarn kotlinx.**

-keepdirectories **
-keepattributes InnerClasses
-keepclasseswithmembers public class de.mobanisto.test.MainKt {
    public static void main(java.lang.String[]);
}
-keepclasseswithmembers class org.jetbrains.skia.** { *; }
-keepclasseswithmembers class org.jetbrains.skiko.** { *; }
-keep class * implements org.jetbrains.skia.shaper.RunHandler { *; }

-keep class com.sun.jna.** { *; }
-keep class * implements com.sun.jna.** { *; }
the app seems to run fine with that. I still get this stacktrace during start up, which doesn't seem to to any harm though:
Copy code
java.lang.NoSuchMethodError: commitLine
        at org.jetbrains.skia.impl.Library._nAfterLoad(Native Method)
        at org.jetbrains.skia.impl.Library$Companion._nAfterLoad(Library.jvm.kt)
        at org.jetbrains.skiko.Library.load(Library.kt:66)
        at org.jetbrains.skiko.SkiaLayer.<clinit>(SkiaLayer.jvm.kt:29)
        at androidx.compose.ui.awt.ComposeLayer.<init>(ComposeLayer.desktop.kt:73)
        at androidx.compose.ui.awt.ComposeWindowDelegate.<init>(ComposeWindowDelegate.desktop.kt:44)
        at androidx.compose.ui.awt.ComposeWindow.<init>(ComposeWindow.desktop.kt:47)
        at androidx.compose.ui.awt.ComposeWindow.<init>(ComposeWindow.desktop.kt:44)
        at androidx.compose.ui.window.Window_desktopKt$Window$3.invoke(Window.desktop.kt:161)
        at androidx.compose.ui.window.Window_desktopKt$Window$3.invoke(Window.desktop.kt:156)
        at androidx.compose.ui.window.Window_desktopKt$Window$10$1.invoke(Window.desktop.kt:367)
        at androidx.compose.ui.window.Window_desktopKt$Window$10$1.invoke(Window.desktop.kt:366)
        at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$2.invoke(AwtWindow.desktop.kt:75)
        at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$2.invoke(AwtWindow.desktop.kt:74)
        at androidx.compose.runtime.DisposableEffectImpl.onRemembered(Effects.kt:81)
        at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers(Composition.kt:802)
        at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:647)
        at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:763)
        at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:433)
        at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2.invokeSuspend(Application.desktop.kt:220)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
        at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
        at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
        at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
would still be nice to find out what's going on there. I've set up a minimalistic project for testing this. Also created a ticket there: https://github.com/sebkur/test-proguard/issues/1
🎉 1
but it's strange even if I add frantic rules like this:
Copy code
-keepclasseswithmembers,includedescriptorclasses class *
-keepclasseswithmembers,includedescriptorclasses class * {*;}
-keepclasseswithmembers,includedescriptorclasses class **,** {*;}
-keepclasseswithmembers,includedescriptorclasses interface **,** {*;}
-keepclasseswithmembers,includedescriptorclasses enum **,** {*;}
that exception still keeps coming up. The resulting jar definitely contains all the classes the original one does (although they're all smaller, so proguard apparently still did something to them. whatever it is, it looks like it's the cause for the exception)
j
I tried out your sample. this rule seems to help with the exception:
Copy code
-keep class org.jetbrains.skia.shaper.RunHandler {
    public <methods>;
}
s
Great, thanks, looks like I was really confused about
-keep
vs
-keepclasseswithmembers
Btw are you going to use native distribution with it? I'd like to do that but looks not possible (easily) with the described approach.
We probably need to change the input for the native distribution tasks. Not sure if thats possible. Maybe a workaround could be to let the proguard task replace the unminified jar with the minified one when it's done?
m
Ya, that's what has to be done. It should be possible somehow. Maybe just a new task in the pipeline. The relevant sources of the CfD gradle tasks are here: https://github.com/JetBrains/compose-jb/tree/master/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose
j
I'm not sure if it's required in this case, but if any changes are needed in the ProGuardTask itself to improve the integration, feel free to open an issue / PR about it and we'll see how we can help https://github.com/Guardsquare/proguard
❤️ 1