alpha-wallet-android icon indicating copy to clipboard operation
alpha-wallet-android copied to clipboard

Proguard rules are not provided

Open mik237 opened this issue 3 years ago • 6 comments

When I set minifyEnabled true in gradle file for release build, it crashes. Please provide proper pro-guard rules for the code.

mik237 avatar Jan 26 '22 07:01 mik237

@justindg @asif-finimble do either of you have experience editing proguard rules? If so can either of you educate me/the rest of us who don't. I have noticed minifyEnabled crashes too. I'm guessing we have to protect essential areas of the app from being removed by minify. It's like we're doing the job of the compiler, and you know they say never send a man to do a machine's job.

JamesSmartCell avatar Mar 01 '22 22:03 JamesSmartCell

Well proguard basically removes classes that are not used in code and most of the times I have faced problems & crashes when request/response DTOs are removed by proguard because we manually dont instantiate many DTOs - JSON parser does it. So proguard thinks that this class is not used. So we provide a rule to exclude the package that contains DTOs and proguard won't "minify" them and leave them as it is. Generally I put @Keep annotation on DTO classes which will prevent proguard from removing them. We can also specify a rule for the same.
In case of libraries used, they provide their own proguard rules.
One more reason for crash could be the methods called from JNI and their names have changed by proguard. For eg: method getInfuraKey() would be renamed to x() by proguard for minification. But there is no native method with name x() and it will crash.

asif-finimble avatar Mar 02 '22 06:03 asif-finimble

@JamesSmartCell should I take this up? I can try inspecting the crash and update proguard rules. Lets see what @justindg suggests.

asif-finimble avatar Mar 02 '22 11:03 asif-finimble

Hi @asif-finimble yes, can you look at this. I think there are a few classes that are stripped by minify that are needed for execution - probably library classes. We probably need to identify what these are are explicitly declare them as being needed. I wonder if we can specify a whole library at a go, then we can see where the problem is. I suspect it is either 'TrustWalletCore' or keys.c, which are the two native code processes.

JamesSmartCell avatar Mar 25 '22 05:03 JamesSmartCell

OK. I'll work on it after the current tickets are done.

asif-finimble avatar Mar 29 '22 04:03 asif-finimble

@JamesSmartCell I have added proguard rules based on tests and crashes. Added rules for TrustWallet library, entities, js interfaces etc. I tested send/receive payment, wallet connect, dappbrowser switch/add ethereum chain, and so far works as expected.
Branch: https://github.com/AlphaWallet/alpha-wallet-android/tree/2352_proguard

Can you test and let me know if changes are needed?

asif-finimble avatar Apr 11 '22 11:04 asif-finimble