stripe / stripe-react-native

React Native library for Stripe.
https://stripe.dev/stripe-react-native
MIT License
1.27k stars 265 forks source link

Android: R8 Minifying missing classes ERROR #1700

Open MichalSmaliraITM opened 3 months ago

MichalSmaliraITM commented 3 months ago

Describe the bug Production build of android fails with error:

> Task :app:minifyReleaseWithR8 FAILED
AGPBI: {"kind":"error","text":"Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in X/android/app/build/outputs/mapping/release/missing_rules.txt.","sources":[{}]}
AGPBI: {"kind":"error","text":"Missing class com.stripe.android.pushProvisioning.PushProvisioningActivity$g (referenced from: void com.reactnativestripesdk.pushprovisioning.PushProvisioningProxy$createActivityEventListener$listener$1.onActivityResult(android.app.Activity, int, int, android.content.Intent))\nMissing class com.stripe.android.pushProvisioning.PushProvisioningActivityStarter$Args (referenced from: void com.reactnativestripesdk.pushprovisioning.DefaultPushProvisioningProxy.beginPushProvisioning(android.app.Activity, java.lang.String, com.reactnativestripesdk.pushprovisioning.EphemeralKeyProvider))\nMissing class com.stripe.android.pushProvisioning.PushProvisioningActivityStarter$Error (referenced from: void com.reactnativestripesdk.pushprovisioning.PushProvisioningProxy$createActivityEventListener$listener$1.onActivityResult(android.app.Activity, int, int, android.content.Intent))\nMissing class com.stripe.android.pushProvisioning.PushProvisioningActivityStarter (referenced from: void com.reactnativestripesdk.pushprovisioning.DefaultPushProvisioningProxy.beginPushProvisioning(android.app.Activity, java.lang.String, com.reactnativestripesdk.pushprovisioning.EphemeralKeyProvider))\nMissing class com.stripe.android.pushProvisioning.PushProvisioningEphemeralKeyProvider (referenced from: void com.reactnativestripesdk.pushprovisioning.DefaultPushProvisioningProxy.beginPushProvisioning(android.app.Activity, java.lang.String, com.reactnativestripesdk.pushprovisioning.EphemeralKeyProvider) and 1 other context)","sources":[{}],"tool":"R8"}
Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in X/android/app/build/outputs/mapping/release/missing_rules.txt.

Missing class com.stripe.android.pushProvisioning.PushProvisioningActivity$g (referenced from: void com.reactnativestripesdk.pushprovisioning.PushProvisioningProxy$createActivityEventListener$listener$1.onActivityResult(android.app.Activity, int, int, android.content.Intent))
Missing class com.stripe.android.pushProvisioning.PushProvisioningActivityStarter$Args (referenced from: void com.reactnativestripesdk.pushprovisioning.DefaultPushProvisioningProxy.beginPushProvisioning(android.app.Activity, java.lang.String, com.reactnativestripesdk.pushprovisioning.EphemeralKeyProvider))
Missing class com.stripe.android.pushProvisioning.PushProvisioningActivityStarter$Error (referenced from: void com.reactnativestripesdk.pushprovisioning.PushProvisioningProxy$createActivityEventListener$listener$1.onActivityResult(android.app.Activity, int, int, android.content.Intent))
Missing class com.stripe.android.pushProvisioning.PushProvisioningActivityStarter (referenced from: void com.reactnativestripesdk.pushprovisioning.DefaultPushProvisioningProxy.beginPushProvisioning(android.app.Activity, java.lang.String, com.reactnativestripesdk.pushprovisioning.EphemeralKeyProvider))
Missing class com.stripe.android.pushProvisioning.PushProvisioningEphemeralKeyProvider (referenced from: void com.reactnativestripesdk.pushprovisioning.DefaultPushProvisioningProxy.beginPushProvisioning(android.app.Activity, java.lang.String, com.reactnativestripesdk.pushprovisioning.EphemeralKeyProvider) and 1 other context)

ASM Instrumentation process wasn't able to resolve some classes, this means that
the instrumented classes might contain corrupt stack frames. Make sure the
dependencies that contain these classes are on the runtime or the provided
classpath. Otherwise, the jvm might fail to load the corrupt classes at runtime
when running in a jvm environment like unit tests.

Classes that weren't resolved:
> com.google.common.util.concurrent.ListenableFuture

To Reproduce Steps to reproduce the behavior:

  1. Create RN repo with RN version 0.74.1
  2. Install "@stripe/stripe-react-native": "^0.38.1",
  3. Add Provider component
  4. Run Android prod build
  5. See error

Expected behavior App is built without error

Additional context Integration works properly on both android and iOS emulators in debug mode, no errors or warnings. iOS Prod build works fine as well.

sgjesse commented 3 months ago

I am from the R8 team, and this looks like a missing dependency. The classes mentioned are references in the input, but not present. If these classes are in an optional dependency, then adding the rules generated in X/android/app/build/outputs/mapping/release/missing_rules.txt to your proguardFiles (see https://developer.android.com/build/shrink-code#enable) should work.

MichalSmaliraITM commented 3 months ago

Thanks @sgjesse I've made it as a workaround right away I do however expect stripe team to look into it to either fix or adjust troubleshooting section to include info about that!

Orteu commented 2 months ago

can you guys show the changes made to make it work? I'm stuck here

MichalSmaliraITM commented 2 months ago

@Orteu adding

-dontwarn com.stripe.**

will silence R8 warnings that became errors in AGP 8+

sgjesse commented 2 months ago

While adding -dontwarn is a workaround, the stripe team should ensure that these are not present when depending on the library. Either by adding explicit -dontwarn 's to the consumer keep runes (if this is by design optional dependencies) or add the required transitive dependencies to the POM.

udayaprakashjayaraman commented 2 months ago

Im using react native expo and anyone can help me on how can i resolve this?? @sgjesse where i need to add -dontwarn in my react native expo application can you share that info please?

sgjesse commented 2 months ago

I am not familiar with the Expo project setup, and cannot give any info on where Proguard configuration rules are located.

divyanshu-bantr commented 1 month ago

@udayaprakashjayaraman Were you able to fix this?

udayaprakashjayaraman commented 1 month ago

@udayaprakashjayaraman Were you able to fix this?

@divyanshu-bantr with a workaround, I created new project and replaced my existing code on that and installed required packages and it started working for me.

divyanshu-bantr commented 1 month ago

@udayaprakashjayaraman What version of stripe-react-native are you using for the new project?

Edit - I upgraded my expo project to SDK50 and this has been an issue ever since, seems like this version is the compatible one but the issue still remains. I also tried 0.37.0, no luck

divyanshu-bantr commented 1 month ago

Quick fix - I removed these valuesenableProguardInReleaseBuilds: true and enableShrinkResourcesInReleaseBuilds: true, from the expo-build-properties plugin in app.config

This isn't perfect since minifying step does not occur and the final build is larger in size. Also, this is avoiding the errors rather than fixing them

bkjp-dev commented 3 days ago

Where you able to fix this? having the same issue with expo managed project

divyanshu-bantr commented 1 day ago

@bkjp-dev I have disabled Proguard in release builds for now. Not ideal and the google play console also gives a warning when you upload the aab. It is what it is for now..