I'm trying to add `proguard` to my `Compose Deskto...
# compose-desktop
p
I'm trying to add
proguard
to my
Compose Desktop
app for obfuscating the code. I got a lot of
proguard
errors after enabling it, but after a lot of research I get rid of all of them adding a lot of
proguard
rules. Now the release distributable builds, and after installing it correctly, when I try to run it gives this error:
Failed to launch JVM
and closes. I can't know why because I don't find any log on the system with information about what is happening. Any idea? I'm adding how I enable proguard in the thread.
There is the code I use to enable proguard:
Copy code
buildTypes.release.proguard {
    isEnabled.set(true)
    version.set("7.5.0")
    configurationFiles.from(project.file("<http://compose-desktop.pro|compose-desktop.pro>"))
}
m
You can call the gradle task runReleaseDistributable. Maybe you get some useful error messages.
p
great idea Michael, I didn't know that runing that way was possible, I got this error:
Copy code
Task :composeApp:runReleaseDistributable
Exception in thread "main" java.lang.ClassFormatError: Invalid index 4 in LocalVariableTable in class file androidx/compose/ui/unit/IntOffset
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
        at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(Unknown Source)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        at androidx.compose.ui.graphics.painter.BitmapPainter.<init>(BitmapPainter.kt:73)
        at org.jetbrains.compose.resources.ImageResourcesKt.painterResource(ImageResources.kt:44)
        at com.mypackage.ComposableSingletons$MainKt$lambda-1$1.invoke(main.kt:1046)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:116)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
        at androidx.compose.ui.window.Application_desktopKt$application$1$1.invoke(Application.desktop.kt:117)
        at androidx.compose.ui.window.Application_desktopKt$application$1$1.invoke(Application.desktop.kt:116)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:116)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
        at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1$1.invoke(Application.desktop.kt:233)
        at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1$1.invoke(Application.desktop.kt:232)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:380)
        at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1.invoke(Application.desktop.kt:223)
        at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1.invoke(Application.desktop.kt:221)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
        at androidx.compose.runtime.ActualJvm_jvmKt__ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:36)
        at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(Unknown Source)
        at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3595)
        at androidx.compose.runtime.ComposerImpl.composeContent$runtime(Composer.kt:3522)
        at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:743)
        at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:1122)
        at androidx.compose.runtime.CompositionImpl.composeInitial(Composition.kt:649)
        at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:635)
        at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2.invokeSuspend(Application.desktop.kt:221)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
        at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
        at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Unknown Source)
        at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
maybe do exist a way to tell proguard to preserve everything but my packages?
I mean... to obfuscate nothing, but my classes
I tryed with -keep class !com.mypackage.** { *; } but I got the same error than when non adding any rules:
Copy code
Warning: there were 231 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
m
This is my ProGuard configuration which I use in my projects.
Copy code
buildTypes.release {
    proguard {
        version.set("7.6.1")
        isEnabled.set(false) // Don't set to true until <https://github.com/Guardsquare/proguard/issues/443> is fixed.
        optimize.set(false)
        obfuscate.set(false)
        configurationFiles.from(project.file("<http://compose-desktop.pro|compose-desktop.pro>"))
    }
}
Recent ProGuard versions are buggy and I just don’t have that much time to waste. I decided to trade a larger installer bundle agains a reliably working application.
p
but Michael, if I do that, what does proguard?
that seems to disable it completly, so it's the same that not using it?
My objective is to learn how to obfuscate the source code, and I think that if you disable proguard with these parameters, the code will not be obfuscated
m
That’s right but I prefer to have a working application instead of a crashing application. It happened too often to me that ProGuard introduced errors which I did not have without it. Just take the one from the comment above for example. I simply can’t use it until this bug is fixed. In your stack trace above you get a
ClassFormatError
which looks very suspicious to me. ProGuard fiddles with the class files itself but does not always get it right. I don’t know whether that’s the case here but it looks like it.
p
do you know how to solve that? or maybe... how to tell proguard that DOESN'T TOUCH anything but my own package classes, to obfuscate only my code, but leave untouched everything else?
🚫 1
ok thank you Michael