arrow icon indicating copy to clipboard operation
arrow copied to clipboard

["Request"] Proguard docs

Open JorgeCastilloPrz opened this issue 5 years ago • 14 comments

Code obfuscation and shrinking is intensely used in Android through ProGuard, and libraries use to include the proper ProGuard rules in their docs to make it easier for end users. We need someone to take a careful look at it and generate initial docs about it in the Quick Start section. Probably rules per module could work good.

JorgeCastilloPrz avatar Apr 14 '19 11:04 JorgeCastilloPrz

This is interesting task, I would like to take it. What do we need as result? Keep all arrow classes? What's the goal?

rcd27 avatar Jul 22 '19 18:07 rcd27

Figure out what classes cannot be stripped. There shouldn't be many, we don't use reflection.

pakoito avatar Jul 22 '19 18:07 pakoito

Looks like there are two issues tracking this: https://github.com/arrow-kt/arrow/issues/500

LordRaydenMK avatar Oct 01 '19 21:10 LordRaydenMK

This should be transparent given it also supports proguard rules, but keep in mind Proguard is not a thing anymore, it's R8.

JorgeCastilloPrz avatar Oct 15 '19 06:10 JorgeCastilloPrz

This should be transparent given it also supports proguard rules, but keep in mind Proguard is not a thing anymore, it's R8.

True, but does R8 has its own rules or it uses Proguard ones?

rcd27 avatar Oct 15 '19 11:10 rcd27

@rcd27 R8 is compatible with Proguard so it uses the same rules 👍 see this for more info

aballano avatar Oct 19 '19 12:10 aballano

Yep as I said it's transparent.

JorgeCastilloPrz avatar Oct 19 '19 15:10 JorgeCastilloPrz

I've used standard https://android.googlesource.com/platform/sdk/+/master/files/proguard-android-optimize.txt to check how is it working. Build was successful, however app is broken (activity launches, but nothing happens). Writing here just to log progress. WIP

rcd27 avatar Nov 11 '19 20:11 rcd27

Check that you have the latest for direct and transitive dependencies!

pakoito avatar Nov 11 '19 21:11 pakoito

Check that you have the latest for direct and transitive dependencies!

It is 10.2 in the project, if you are about arrow-kt

rcd27 avatar Nov 12 '19 05:11 rcd27

I'm using arrow version 0.9.0 and if I enable code obfuscation our app fails with this exception:

java.lang.NoSuchFieldException: No field completion in class Lk/v/i/a/a; (declaration of 'k.v.i.a.a' appears in .... base.apk) at java.lang.Class.getDeclaredField(Native Method) at arrow.typeclasses.ContinuationUtilsKt$completionField$2.invoke(:7) at arrow.typeclasses.ContinuationUtilsKt$completionField$2.invoke(Unknown Source:0) at kotlin.SynchronizedLazyImpl.getValue(:74) at arrow.typeclasses.ContinuationUtilsKt.getCompletionField(Unknown Source:7) at arrow.typeclasses.ContinuationUtilsKt.getCompletion(:10) at arrow.typeclasses.ContinuationUtilsKt.getCompletionField(:19)

Is this something that is fixed in a higher version? For now we don't use obfuscation but it would be nice to understand what is happening here.

jleidgens avatar Nov 27 '19 17:11 jleidgens

Well, there are no R8/Proguard rules yet as soon as issue is still open.

rcd27 avatar Nov 27 '19 17:11 rcd27

I'm using arrow version 0.9.0 and if I enable code obfuscation our app fails with this exception:

java.lang.NoSuchFieldException: No field completion in class Lk/v/i/a/a; (declaration of 'k.v.i.a.a' appears in .... base.apk) at java.lang.Class.getDeclaredField(Native Method) at arrow.typeclasses.ContinuationUtilsKt$completionField$2.invoke(:7) at arrow.typeclasses.ContinuationUtilsKt$completionField$2.invoke(Unknown Source:0) at kotlin.SynchronizedLazyImpl.getValue(:74) at arrow.typeclasses.ContinuationUtilsKt.getCompletionField(Unknown Source:7) at arrow.typeclasses.ContinuationUtilsKt.getCompletion(:10) at arrow.typeclasses.ContinuationUtilsKt.getCompletionField(:19)

Is this something that is fixed in a higher version? For now we don't use obfuscation but it would be nice to understand what is happening here.

Although @pakoito said there is no reflection, you can see in ContinuationUtils that there is at least that which causes this problem.

I was able to use R8 adding this rule to my proguard-rules.pro to solve that specific issue: -keepnames class kotlin.coroutines.jvm.internal.BaseContinuationImpl { kotlin.coroutines.Continuation completion; }

niltsiar avatar Jun 05 '20 15:06 niltsiar

I guess this is still applicable to optics-reflect, right @JorgeCastilloPrz?

That is the only library in Arrow that relies on reflection, so should it require an arrow.optics.* configuration in proguard/R8. I am unsure how this works these days.

nomisRev avatar Apr 05 '23 07:04 nomisRev