themis: [question] [v.0.13.1] [android] getting IncompatibleClassChangeError when trying to bind .aar in C# project [SOLVED by adding ProGuard rules]
Describe the bug
Getting Java.Lang.IncompatibleClassChangeError: no non-static method "Lcom/cossacklabs/themis/SecureCellSeal;.decrypt([B[B)[B" in Release configuration in C# android project.
When decrypting “obfuscated” string constant on app start.
Any ideas? Have you seen anything like this in some java or kotlin android project?
To Reproduce
On app start I try to decrypt an “obfuscated” string constant
_secureCell = SecureCell.SealWithKey(masterKeyData);
_secureCell.Decrypt(cipherTextBytes, context);
Getting an error in Release configuration:
Java.Lang.IncompatibleClassChangeError: no non-static method "Lcom/cossacklabs/themis/SecureCellSeal;.decrypt([B[B)[B"
[orion.mobile] at Java.Interop.JniEnvironment+InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature) [0x0005b] in <42d2b7086f0a46efb99253c5db1ecca9>:0
[orion.mobile] at Android.Runtime.JNIEnv.GetMethodID (System.IntPtr kls, System.String name, System.String signature) [0x00007] in <3080427739614e60a939a88bf3f838d5>:0
[orion.mobile] at Com.Cossacklabs.Themis.SecureCell+ISealInvoker.Decrypt (System.Byte[] p0, System.Byte[] p1) [0x00017] in <cd618986d1ce4194b63cdd3366dad291>:0
[orion.mobile] at Themis.Droid.CellSealDroid.UnwrapData (Themis.ISecureCellData cipherTextData, System.Byte[] context) [0x0007e] in <a492e7118e094c3296442a386fe5d80e>:0
[orion.mobile] --- End of inner exception stack trace ---
Expected behavior
N/A - this issue is a question
Environment (please complete the following information):
- OS: Android 10, build 00WW_2_250
- Hardware: Nokia 7.2
- Themis version: 0.13.1
- Installation way:
- via package manager
- built from source
Additional context
Sorry for asking in a wrong place if I’m violating any of your policies with this ticket.
I’ve spent a while debugging it and am a bit desperate at the moment.
I know you do not support that C# and Xamarin.Forms but filing this question just in case you’ve seen a similar issue in some java or kotlin android project.
Unable to share a sample project
since that does not reproduce on https://github.com/dodikk/themis-xamarin-prototype/tree/bugfix/v0.13.2/droid-strip-symbols Only in a project under NDA, unfortunately.
- I’ve checked the data I’m getting the failure on. It has been encrypted with
wasm-themisCLI tools. Also I can decrypt the data collected from my app’s exception (again, withwasm-themisCLI tools) - The same app code and bindings work in
debugconfiguration apkseems to haveSecureCellandSecureCellSealclass symbols (checked via “profile apk” UI in android studio)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 25 (5 by maintainers)
aarwithcurland generated xamarin bindings on top of it. No significant diff between the correspondingcsprojfiles (C# projects) discovered.The C# code of binding/wrapper projects is identical (for “sample” and “real” projects). That code is available in
dodikk/themis-xamarin-prototyperepository.aarbinary as the “sample project”.N/A. In my case that was justcurl. Copying the same binary on the file system does not help either./cc @vixentael
@vixentael , I have updated
developbranch of the demo project. Both the project and readme. https://github.com/dodikk/themis-xamarin-prototype/tree/developWill update the default branch of demo repository later, after more testing.
@vixentael sure. Of course I’ll do that. Also I was planning to document this stuff in the sample’s readme.
Do you accept pull requests to your documentation?
@vixentael , could you please share the URL of the corresponding repo?
As far as I’ve understood so far… Native android devs might run into such issue as well. So documenting this pitfall (in the Installing JavaThemis for Android development) guide might make sense. Unless either
mavenorgradledeals withproguardautomatically by defaultdocumented in this ticketas is good enough@vixentael sure thing it is possible. But I cannot use
Nonesince that would bloat theapksize with the entiremonoruntime. Which is highly unwanted (ok fordebugand in-house; but bad forreleaseandplaymarket).Also, xamarin allows specifying manually “which symbols should stay” (see the link below). But I’m viewing that as “weapon of last resort” since that approach would be rather time-consuming (just like writing a
makefilewithout those cmake or autotools helpers). So I’m hoping to find an easier fix and still “on a quest” to find one… https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/linker[UPD] this docs page of MSDN seems relevant and helpful
I’m trying the guides below to check the “troubles from C# world”
But no success fo far.
Things start to break when C# apk size optimizer (which they call “linker” for some reason) is set to more aggressive mode (
None==>Sdk Assemblies Onlymodes mentioned in ). So the high-level hypothesis"the apk size optimizer is stripping too much"looks like the best candidate. On the other hand, the symbols mentioned in the exception are there in theapkP.S. This comment is not a question but rather an update on “what I’ve discovered so far”
Ok. Then I’ll try other things before applying your toolchain to my app’s build environment. Thanks for providing context, @ilammy
[UPD] a link to
cossacklabs/android-buildjust un case for future readers of this topic https://github.com/cossacklabs/dockerfiles/blob/master/android-build/Dockerfile#L26Same results on
x64 - Nexus 5 - Android Pieemulator (both for the “real project” and for the prototype; on CipherText data from “real app”) /cc @vixentael[UPD] same results on
Samsung SM-J200Handandroid v5.1.1hardwareThat same data from the “real project” does not break my “sample project”. Checked on the very same
nokiadevice./cc @vixentael