lazysodium-java icon indicating copy to clipboard operation
lazysodium-java copied to clipboard

jna 5.17.0 Incompatibility with lazysodium-java 5.2.0

Open ParaskP7 opened this issue 6 months ago • 2 comments

Hi team, in this woocommerce-android open-source project of ours, which is using this EncryptedLogging open-source library of ours, after updating jna to 5.17.0 and lazysodium-android to 5.2.0 to get that library 16 KB page size compatible (see libs.versions.toml), we are now getting the below crashes:

Structure.getFieldOrder() on class com.goterl.lazysodium.interfaces.SecretStream$State$ByReference
returns names ([_pad, k, nonce]) which do not match declared field names ([_pad, k])

and/or...

Structure.getFieldOrder() on class com.goterl.lazysodium.interfaces.SecretStream$State$ByReference
returns names ([_pad, k, nonce]) which do not match declared field names ([_pad, nonce])

...plus other combinations like that, ie [_pad], [k, nonce], versus [_pad, k, nonce], although less frequent... 🤔

It seems that lazysodium-java 5.2.0's SecretStream$State$ByReference structure declares fields [_pad, k, nonce] but jna 5.17.0 only recognizes [_pad, k] and/or [_pad, nonce] due to changes in how jna handles Structure field declarations.

Any ideas on that? 🤔

Many thanks for helping out! 🙏

ParaskP7 avatar Aug 19 '25 08:08 ParaskP7

Have you recently turned on R8 minification for your app? I got errors similar to that due to R8 optimizing out parts of JNA (which lazysodium is built on), and I fixed it by adding the proguard rules that JNA suggest here https://github.com/java-native-access/jna/blob/master/www/FrequentlyAskedQuestions.md#jna-on-android

angusholder avatar Aug 31 '25 17:08 angusholder

Thanks for the reply @angusholder , much appreciated! 🙇

Have you recently turned on R8 minification for your app?

Unfortunately, this is not it, woocommerce-android been having minifyEnabled = true for years now. 🤷

I got errors similar to that due to R8 optimizing out parts of JNA (which lazysodium is built on)...

👍

...and I fixed it by adding the proguard rules that JNA suggest here https://github.com/java-native-access/jna/blob/master/www/FrequentlyAskedQuestions.md#jna-on-android

Unfortunately, this too is not it, on this EncryptedLogging library of ours, which is the library using JNA, we do have such consumer-rules.pro ProGuard rules: 🤔

consumer-rules.pro

# https://github.com/java-native-access/jna/blob/master/www/FrequentlyAskedQuestions.md#jna-on-android
-dontwarn java.awt.*
-keep class com.sun.jna.* { *; }
-keepclassmembers class * extends com.sun.jna.* { public *; }

ParaskP7 avatar Sep 01 '25 11:09 ParaskP7