Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R8/Proguard on RN 0.73 Java 17 AGP 8 causing Android Plaid link opens to crash #647

Open
johnnyrwest opened this issue Mar 27, 2024 · 5 comments

Comments

@johnnyrwest
Copy link

johnnyrwest commented Mar 27, 2024

The problem

We recently migrated our app from RN 0.72 -> 0.73 and with that noticed that Plaid linking on a production Android build now crashes.

Android-specific updates as a part of the upgrade:
Java 11 -> Java 17
AGP 7.4.x -> 8.0.x

Disabling r8/proguard seems to fix the issue, but ideally we don't have to turn that off.

Environment

Plaid Link React Native 10.13.1
ReactNative Version 0.73.6
Occurs on Android yes
Android OS Version 14.0.0 (34)
Android Devices/Emulators Galaxy S21 Physical, sdk_gphone64_arm64 emulator
Occurs on iOS no
iOS Version n/a
iOS Devices/Emulators n/a
Link Session ID n/a (request id - vvYPNJ8FiwD3sFK)

Steps to Reproduce

  • build .apk with proguard enabled
  • attempt to open Plaid link
  • app crash with error:

Screenshot 2024-03-27 at 11 32 13 AM

Expected Result

No crash

Screenshots

plaid.linking.android.webm

Logs

    {
      "header": {
        "logLevel": "ERROR",
        "pid": 9410,
        "tid": 9410,
        "applicationId": (app id withheld),
        "processName": (app id withheld),
        "tag": "AndroidRuntime",
        "timestamp": {
          "seconds": 1711493115,
          "nanos": 477000000
        }
      },
      "message": "FATAL EXCEPTION: main\nProcess: (app id withheld), PID: 9410\njava.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType\n\tat retrofit2.n.f(SourceFile:22)\n\tat retrofit2.h0.b(SourceFile:20)\n\tat retrofit2.g0.c(SourceFile:25)\n\tat retrofit2.g0$a.invoke(SourceFile:38)\n\tat java.lang.reflect.Proxy.invoke(Proxy.java:1006)\n\tat $Proxy14.a(Unknown Source)\n\tat com.plaid.internal.bb$b.invokeSuspend(SourceFile:35)\n\tat kotlin.coroutines.jvm.internal.a.resumeWith(SourceFile:12)\n\tat wn.t0.run(SourceFile:124)\n\tat bo.o$a.run(SourceFile:4)\n\tat do.k.run(SourceFile:3)\n\tat do.a.o0(SourceFile:1)\n\tat do.a$c.d(SourceFile:15)\n\tat do.a$c.p(SourceFile:29)\n\tat do.a$c.run(SourceFile:1)\n\tSuppressed: bo.i: [m2{Cancelling}@2e9677f, Dispatchers.Main.immediate]"
    }

Code To Reproduce Issue

Our Plaid link flow follows the exact implementation per your current docs.

Worth noting that we build using Expo 50, but they do not enable proguard by default.

We have enabled r8 for Android builds, however, with the following rule:

-keep public class com.horcrux.svg.** {*;}

Please let me know if you need any additional info here — super odd how this worked with r8 before upgrading the AGP, so wanted to at least bring this issue to attention.

Confirming it does not appear to be the same issue as #598
If anything it is most similar to this issue

@johnnyrwest johnnyrwest changed the title R8 Proguard on RN 0.73 Java 17 AGP 8 causing Android Plaid link opens to crash R8/Proguard on RN 0.73 Java 17 AGP 8 causing Android Plaid link opens to crash Mar 27, 2024
@melissaosullivan
Copy link
Collaborator

Hi @johnnyrwest,

Thanks for reporting this. Could you try adding the following to your app's proguard-rules.pro:

-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken

Please let me know if this fixes the problem.

@johnnyrwest
Copy link
Author

-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken

Hi @melissaosullivan — thanks for looking into this! I have added these rules and attempted a fresh build, but unfortunately I am still crashing with the same error:

2024-03-28 09:45:13.885 13530-13530 AndroidRuntime          (withheld)                      E  FATAL EXCEPTION: main
                                                                                                    Process: (withheld), PID: 13530
                                                                                                    java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
                                                                                                    	at retrofit2.HttpServiceMethod.parseAnnotations(SourceFile:22)
                                                                                                    	at retrofit2.ServiceMethod.parseAnnotations(SourceFile:20)
                                                                                                    	at retrofit2.Retrofit.loadServiceMethod(SourceFile:25)
                                                                                                    	at retrofit2.Retrofit$1.invoke(SourceFile:38)
                                                                                                    	at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
                                                                                                    	at $Proxy14.a(Unknown Source)
                                                                                                    	at com.plaid.internal.bb$b.invokeSuspend(SourceFile:35)
                                                                                                    	at kotlin.coroutines.jvm.internal.a.resumeWith(SourceFile:12)
                                                                                                    	at wn.t0.run(SourceFile:124)
                                                                                                    	at bo.o$a.run(SourceFile:4)
                                                                                                    	at do.k.run(SourceFile:3)
                                                                                                    	at do.a.n0(SourceFile:1)
                                                                                                    	at do.a$c.d(SourceFile:15)
                                                                                                    	at do.a$c.p(SourceFile:29)
                                                                                                    	at do.a$c.run(SourceFile:1)
                                                                                                    	Suppressed: bo.i: [m2{Cancelling}@6787121, Dispatchers.Main.immediate]

Clicking into the error in Logcat takes me to the retrofit-2.8.2-sources.jar > retrofit2 > HttpServiceMethod.java file if that helps any, with the culprit line of:

import java.lang.reflect.Method;

Not sure if that is helpful at this point but please let me know if I can surface any other details!

@johnnyrwest
Copy link
Author

@melissaosullivan not sure if I should close or if it's still worth looking at on the Plaid side, but I was able to try adding the proguard rules provided in this stack overflow ticket and open the Plaid link successfully without a crash 🙏

# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items). 
 -keep,allowobfuscation,allowshrinking interface retrofit2.Call 
 -keep,allowobfuscation,allowshrinking class retrofit2.Response 
  
 # With R8 full mode generic signatures are stripped for classes that are not 
 # kept. Suspend functions are wrapped in continuations where the type argument 
 # is used. 
 -keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation 

@Juan2662
Copy link

retrofit just released 2.11.0 version to solve this issue, can we update it too ?
image

@melissaosullivan
Copy link
Collaborator

retrofit just released 2.11.0 version to solve this issue, can we update it too ?

Hi @Juan2662, Looking at the description for 2.11.0 retrofit update, this will have no impact on the issue reported in this thread. This thread is about a proguard crash that occurs with proguard strict mode in proguard enabled builds. The crash occurs because code used by the SDK is stripped out. The proguard rules prevent the code from being stripped out and so that’s why adding rules this fixes the crash.

The retrofit update seems to provide a more detailed parsing exception to non primary callers, but this more detailed parsing exception would still be an exception. So this upgrade would not remove the presence of an exception, and would not fix the bug described in this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants