librespot-android icon indicating copy to clipboard operation
librespot-android copied to clipboard

Enhancement: add obfuscation rules and use minify

Open vhaudiquet opened this issue 4 years ago • 0 comments

If this app is here to showcase how librespot can be included in an Android app, i think it would be good to show the minimal proguard rules that should be added so that you can enable 'minify' for release configurations.

I went trough the hassle of testing that for my app, here are the rules i could come up with :

# The spotify librespot player needs an 'output class'
# for it's audio output ; we need to keep that
-keep class xyz.gianlu.librespot.android.sink.AndroidSinkOutput

# librespot needs reflexion to work internally
# Here we keep the classes it needs
-keep class xyz.gianlu.librespot.mercury.MercuryRequests$GenericJson
{
    <init>(com.google.gson.JsonObject); # method <init> i.e. constructor
}
-keep class xyz.gianlu.librespot.mercury.MercuryRequests$ResolvedContextWrapper
{
    <init>(com.google.gson.JsonObject); # method <init> i.e. constructor
}
-keep class com.spotify.** {*;}
-keep class xyz.gianlu.librespot.audio.decoders.** {*;}

(from https://github.com/vhaudiquet/BladePlayer/blob/master/app/proguard-rules.pro)

I did not check what was needed for the Android Native decoder or the Tremolo decoder as i don't use them in my app for now.

It appears to be working keeping only those classes, and it cuts in half my app size. I hope it can be useful to other people, this is why i'm sharing this here (and i think it should be included in the project, either in the proguard rules file or in the readme/documentation)

vhaudiquet avatar Jan 10 '22 00:01 vhaudiquet