Android proguard issue in a multi-module project

Hello,

I added SQLCipher to my project and it worked as intended while debugging but app always crash at startup in the release version with this exception java.lang.NoSuchFieldError: no "J" field "mNativeHandle" in class "Lnet/sqlcipher/database/SQLiteDatabase;" or its superclasses

I tried disabling proguard then running a release build and it worked fine (since that’s the only difference between a debug and a release build).

I also tried the solutions proposed by the community here including:

  • adding these two lines in proguard rules
-keep,includedescriptorclasses class net.sqlcipher.** { *; }
-keep,includedescriptorclasses interface net.sqlcipher.** { *; }

but that didn’t work

  • adding the whole proguard rules file mentioned here proguard rules file
    and that also didn’t work

so I tried starting a new project with room and added SQLCipher to it and the release version worked. the only difference between my project and that new one is that mine is a multi-module one while the new sample had only the app module. To make sure this was the issue, I added a new module to that new project and indeed the release build crashed at startup in that case. I am using version 4.5.3. what am I missing here?

P.S: the change in proguard rules file was in 2 modules only (the app module and the module with room dependency)

Hi @Gesraha,

It’s not clear whether you added ProGuard to the new project that worked, or not. Can you clarify this?

Hi @developernotes

Thanks for the quick response. yes I added ProGuard to the new project.

It’s worth mentioning that in the new project, either adding the two lines or adding the whole file I mentioned earlier makes no difference. App runs normally in both cases but only if it includes just the app module.

Just a follow-up reply. any ideas what am I doing wrong here?
am I missing something or is the library simply not supporting multi-modules? if so, are there any plans to support them in the future?

Hi @Gesraha,

If you are using ProGuard in your library module, are you setting consumerProguardFiles within the defaultConfig based on the Android documentation [1]?


  1. Membuat library Android  |  Android Studio  |  Android Developers ↩︎

That was indeed what I was missing. I was setting the proguard-rules file alone.

Setting gradle to use consumer file then adding the two lines to consumer file instead of proguard-rules file worked like a charm.

Thanks a million :grin:

Hi @Gesraha,

Excellent, I’m glad to hear that solved the issue!