We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5004

Summary: Add @Keep to JNI methods to preserve them during proguard obfuscate/shrink
Product: SDL Reporter: Anthony @ POW Games <ant>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: WAITING --- QA Contact: Sam Lantinga <slouken>
Severity: enhancement    
Priority: P2 CC: sylvain.becker
Version: HG 2.0   
Hardware: All   
OS: Android (All)   

Description Anthony @ POW Games 2020-02-24 18:34:17 UTC
At present, the only way to build a successful APK with proguard is to add the following line to the rules:

-keep public class org.libsdl.app.** { public *; }

This works, but leaves the entire Android SDL Java code unoptimised. 

I've found the @Keep keyword (import android.support.annotation.Keep;) works really well to preserve the methods for JNI. If we add them to all the JNI methods, it should allow us to run a full proguard optimization.

Not vital - but very useful for developers wanting to reduce their APK size.
Comment 1 Anthony @ POW Games 2020-02-24 18:35:52 UTC
Another alternative is to list every JNI in proguard-rules.pro, but there are a lot of them and it'd be something more to manage (and maybe forget to update).
Comment 2 Sam Lantinga 2020-03-02 23:17:04 UTC
Can you provide a tested patch? I'd like to add that for 2.0.13.
Are there any build environment dependencies?

Thanks!
Comment 3 Sylvain 2020-03-06 11:09:40 UTC
I wonder whether adding "import android.support.annotation.Keep;" would increase size.

Does it need to add some gradle dependency ?

Do you have an example of a proguard line to keep the method ?