klaviyo / klaviyo-react-native-sdk

MIT License
4 stars 3 forks source link

Android runtime issue - Incomplete hierarchy for class ProfileKey #138

Closed MarcosAlvesTJr closed 5 months ago

MarcosAlvesTJr commented 5 months ago

Checklist

Description

I have a runtime issue with the SDK in Android devices. Upon trying to open the app it crashes instantly.

Expected behavior

App not to crash.

Actual behavior

This issue happens only in runtime, couldn't reproduce it using React Native's local development server. I also haven't detected any build issues. So far I've got the crash in the following devices: 

- Samsung Galaxy A21 S
- Xiaomi Redmi Note 10

Both on Android version 12. And that's the error stack:

com.facebook.react.common.JavascriptException:
Error: Exception in HostObject::get
for prop 'Klaviyo ReactNativeSdk':
java.lang.IllegalStateException: Incomplete
hierarchy for class ProfileKey, unresolved classes [com.klaviyo.analytics.model. Keyword], js engine:
hermes, stack:
anonymous@1:3728994
loadModulelmplementation@1:117561
guardedLoadModule@1:117116
metroRequire@1:116744
anonymous@1:3728240
loadModulelmplementation@1:117561
guardedLoadModule@1:117116
metroRequire@1:116744
anonymous@1:3700420
loadModulelmplementation@1:117561
guardedLoadModule@1:117116
metroRequire@1:116744
anonymous@1:3699847
loadModuleImplementation@1:117561
guardedLoadModule@1:117116
metroRequire@1:116744
anonymous@1:3684706
loadModulelmplementation@1:117561
guardedLoadModule@1:117116
metroRequire@1:116744
anonymous@1:3681805
loadModulelmplementation@1:117561
guardedLoadModule@1:117116
metroRequire@1:116744
anonymous@1:3015816
loadModulelmplementation@1:117561
guardedLoadModule@1:117116
metroRequire@1:116744
anonymous@1:3012690
loadModulelmplementation@1:117561
guardedLoadModule@1:117116
metroRequire@1:116744
anonymous@1:2389637

### Steps to reproduce

```markdown
1. Build a release version
2. Try opening the app

The Klaviyo React Native SDK version information

0.2.1 and 0.3.0

Environment Description

Android version 12. Devices: Samsung Galaxy A21 S, Xiaomi Redmi Note 10

evan-masseau commented 5 months ago

Thanks for reporting, we will take a look at this soon. It sounds like a problem with proguard or other code optimizer.

kennyklaviyo commented 5 months ago

@MarcosAlvesTJr Can you provide us with some more details about your setup, in particular: Java version, Android gradle version, React native version, Android compile sdk version, any relevant code in the android/build.gradle and android/app/build.gradle files, any relevant rules defined in the proguard files. Additionally, can you reproduce this issue in the example app in this repo?

MarcosAlvesTJr commented 5 months ago

@kennyklaviyo

I wasn't able to reproduce the issue using the example app, it works as expected. Could it be a Java version problem?

evan-masseau commented 5 months ago

I have limited knowledge of exactly how shrinkers work, but I do think it has to be the culprit. We make production builds with proguard enabled in our internal testing apps, and don't encounter this error. Even when I remove all com.klaviyo. imports from the kotlin code.

Can you try adding a proguard rule for the Klaviyo SDK. Obviously since I couldn't reproduce, I can't verify this, but I think this is the correct syntax:

-keep class com.klaviyo.analytics.** { *; }

Appreciate you helping us diagnose the issue!

evan-masseau commented 5 months ago

Are you using the native integration path (e.g. initializing from kotlin code) or purely react native? I've tested both ways but just curious your setup.

evan-masseau commented 5 months ago

Hey good news, I did (sort of) reproduce the error in our test app. It was a different error message (maybe that has something to do with using different Java and/or React versions) but same root cause I suspect.

In my case, it crashed upon trying to create an event. The error was a null pointer exception due to a missing class. Adding the proguard rule I recommended fixed the crash. Please report back if it fixes it for you too!

MarcosAlvesTJr commented 5 months ago

@evan-masseau I'm using only React Native integration. I added the proguard rule and it works now, thanks a lot!

evan-masseau commented 5 months ago

Glad to hear it! Thanks for your help here, this was informative for us as well. We'll add docs and also try to put in consumer proguard config for the future.