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 - Add @Keep to JNI methods to preserve them during proguard obfuscate/shrink
Summary: Add @Keep to JNI methods to preserve them during proguard obfuscate/shrink
Status: WAITING
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.0
Hardware: All Android (All)
: P2 enhancement
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-24 18:34 UTC by Anthony @ POW Games
Modified: 2020-03-06 11:09 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ?