Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proguard removes jdk providers #51

Open
acmpo6ou opened this issue Oct 20, 2024 · 1 comment
Open

Proguard removes jdk providers #51

acmpo6ou opened this issue Oct 20, 2024 · 1 comment
Milestone

Comments

@acmpo6ou
Copy link

Hello.

I have a KMP project with Desktop and Android as target OSes. I have this in my dependencies (the latest 4.0.0 version):

implementation(libs.cryptography.core)
implementation(libs.cryptography.provider.jdk)

I'm using ProGuard:

compose.desktop {
    application {
        // ...
        buildTypes.release.proguard {
            obfuscate = true
        }
    }
}

If I compile a release uber jar:

./gradlew packageReleaseUberJarForCurrentOS

Running it will result in this error message (the app doesn't crash, but the decryption doesn't happen either):

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: No providers registered. Please provide a dependency or register provider explicitly
	at dev.whyoleg.cryptography.e.b(Unknown Source)
	at kotlin.SynchronizedLazyImpl.getValue(Unknown Source)
	at d.d.e.k.a(Unknown Source)
	at d.d.e.k.a(Unknown Source)
	at d.d.e.p.invokeSuspend(Unknown Source)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source)
	at kotlinx.coroutines.W.run(Unknown Source)
	at kotlinx.coroutines.c.a.a(Unknown Source)
	at kotlinx.coroutines.c.d.run(Unknown Source)
	Suppressed: kotlinx.coroutines.internal.h: [CoroutineName(d.d.e.a:d.d.e.k:default), aU{Cancelling}@2ab8b3b7, Dispatchers.Main]

The debug build works perfectly fine, as well as a release build for Android.

To fix the above issue, I had to add this to my proguard file (compose-desktop.pro):

-keep class dev.whyoleg.cryptography.*
-keep class dev.whyoleg.cryptography.providers.jdk.*

and this to my build.gradle.kts:

compose.desktop {
    application {
        // ...
        buildTypes.release.proguard {
            obfuscate = true
            configurationFiles.from(project.file("compose-desktop.pro"))
        }
    }
}
@whyoleg
Copy link
Owner

whyoleg commented Oct 29, 2024

Hey!
Thanks for filling the issue, yeah, we will need to provide pro guard rules for the library out of the box, similar to have it's done in kotlinx.coroutines or similar.
The reason for this, is that providers are loaded via JDK ServiceLoader, and so class name is important.

Additionally integration test will need to be added

@whyoleg whyoleg added this to the 0.4.1 milestone Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants