https://kotlinlang.org logo
c

Colton Idle

10/16/2020, 1:34 PM
Implementing/learning/reading about r8/proguard. I stumbled upon the PR from Zac Sweers to add default r8 rules to kotlin-reflect and I'm reasearching whether or not my deps that come from square require proguard rules. Is the gist of r8 that you won't have to add proguard rules to any deps unless they use reflection?
w

wasyl

10/16/2020, 2:10 PM
Many libraries, and I believe all square libraries, ship with R8 rules embedded, so you don’t need to add them manually
👍 1
Other than that mostly yes, you don’t need any R8 rules as long as R8 can infer the usage automatically, and the biggest issue usually is reflection
🙏 1
c

Colton Idle

10/16/2020, 2:12 PM
Thank you Łukasz
👍 1
w

wasyl

10/16/2020, 2:12 PM
For example, here’s what rules OkHttp ships https://github.com/square/okhttp/blob/master/okhttp/src/main/resources/META-INF/proguard/okhttp3.pro. As long as you’re using R8, they’re picked up automatically (documented in https://developer.android.com/studio/build/shrink-code under
library dependencies
)
c

Colton Idle

10/16/2020, 2:18 PM
Oof. Still looks like guava doesn't have any automatically.
z

Zac Sweers

10/18/2020, 1:20 AM
Guava doesn't embed any rules in their jar, wish they would
most libraries on the square side ship with the minimum that they need, but not necessarily all the ones needed for them to be used. With Moshi-kotlin for instance, it only keeps what's needed for it to work but you still have to keep any reflectively serialized models like any other reflective serializer would
c

Colton Idle

10/22/2020, 2:43 AM
Thanks for clarifying. Starting to get the hang of how proguard/r8 works. I just ended up removing guava. Only use a smalllllll set of it's functionality.
28 Views