caprica / vlcj

Java framework for the vlc media player
http://www.capricasoftware.co.uk/projects/vlcj
1.1k stars 260 forks source link

Document proguard rules #1210

Open mikedawson opened 5 months ago

mikedawson commented 5 months ago

Hi,

When I use Proguard on my project (I'm using VLCJ in a Compose/Desktop JVM application), the discovery providers (which are loaded via Java SPI) are removed.

I think the following rules are needed:

# Not always compiling on Mac
-dontwarn com.apple.eawt.**

# Keep DiscoveryDirectoryProviders loaded via SPI
#-keep class * implements uk.co.caprica.vlcj.factory.discovery.provider.DiscoveryDirectoryProvider { *; }
#-keep interface uk.co.caprica.vlcj.factory.discovery.provider.DiscoveryDirectoryProvider { *; }

The keep rule specified here https://www.guardsquare.com/manual/configuration/examples#native is also required. I think most Proguard setups have that, but might be good to mention.

caprica commented 5 months ago

The eawt stuff is obsolete now.

caprica commented 5 months ago

So this is purely for purposes of minification, not obfuscation, right?

What I mean is, vlcj is Open Source so there's no point to obfuscate the source code as such. Making a small bundle size is fair enough I suppose.

mikedawson commented 5 months ago

Thanks for the super quick reply! Yes the main point is the bundle size. Secondary reason is performance gain. My jars (also open source) are about 157MB before shrinking and obfuscation, and about 78MB afterwards (I documented a bit of it here on this article).

mikedawson commented 5 months ago

Just to clarify: we are using obfuscation, only because it further shrinks the bundle size and should improve performance of remaining code. I find without obfuscation enabled, my jars are about 12MB bigger.

caprica commented 5 months ago

Sure, that's what I suspected.

I am happy to add something to document this. But in the immediate term I need to think about a bit more because the upcoming version of vlcj has some more stuff that will need to be excluded.

mikedawson commented 5 months ago

Adding docs would be great, thanks! On Android, libraries can publish proguard rules that are consumed automatically. Unfortunately, that hasn't hit the JVM world yet.

caprica commented 5 months ago

is there any value just putting a proguard config file (or partial config file) in the main repo itself I wonder?

mikedawson commented 5 months ago

I think putting in the repo (convention is META-INF/library-name.pro e.g. META-INF/vlcj.pro) would make sense. I think it would still need mentioned somewhere in the docs. On Android, those rules can be consumed automatically. On JVM, they need to be copy/pasted in manually.