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

Android crash #24

Closed
nuzelac opened this issue Feb 27, 2020 · 6 comments
Closed

Android crash #24

nuzelac opened this issue Feb 27, 2020 · 6 comments

Comments

@nuzelac
Copy link

nuzelac commented Feb 27, 2020

Hi,

I have migrated IAP to RevenueCat in my app. iOS works fine, but Android works only on 1st launch after deleting the app from test device. Looks like there's some bogus data in SharedPreferences. Any suggestions what I could try?

E/AndroidRuntime(30679): FATAL EXCEPTION: pool-8-thread-1
E/AndroidRuntime(30679): Process: net.poopmap, PID: 30679
E/AndroidRuntime(30679): java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Set
E/AndroidRuntime(30679): 	at android.app.SharedPreferencesImpl.getStringSet(SharedPreferencesImpl.java:293)
E/AndroidRuntime(30679): 	at com.revenuecat.purchases.DeviceCache.getPreviouslySentHashedTokens$purchases_release(DeviceCache.kt:100)
E/AndroidRuntime(30679): 	at com.revenuecat.purchases.DeviceCache.cleanPreviouslySentTokens(DeviceCache.kt:127)
E/AndroidRuntime(30679): 	at com.revenuecat.purchases.Purchases$updatePendingPurchaseQueue$1.run(Purchases.kt:926)
E/AndroidRuntime(30679): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(30679): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(30679): 	at java.lang.Thread.run(Thread.java:764)
@nuzelac
Copy link
Author

nuzelac commented Feb 27, 2020

Please disregard, this is happening because I'm using flutter's shared_preferences plugin, which converts Set to List when you read from it. By default that plugin uses its own shared prefs xml but I forked it to read default shared prefs so that's why it interferes with RevenueCat.

@nuzelac nuzelac closed this as completed Feb 27, 2020
@diegocom
Copy link

@nuzelac Hi, I have the same problem. I need to read the Android default shared preferences and not the flutter ones, but after reading them the app will crash on subsequent launches. How did you solve?

@nuzelac
Copy link
Author

nuzelac commented Dec 23, 2020

Hi @diegocom I'm running a fork of shared_preferences plugin so that I can read default Android prefs.
This migration of Set to List in getAllPrefs method will cause the crash on next launch so I simply ignore this migration when prefix length 0 (e.g. I'm trying to read all prefs, not just Flutter ones).

You can check my commit here:
nuzelac/plugins@ae51d83

@diegocom
Copy link

@nuzelac Great, it works! You saved my day

@vegaro
Copy link
Contributor

vegaro commented Jan 8, 2021

Is there anything we can do on our side to prevent this from happening for future developers? I am not sure I completely understand what's going on 😆 @nuzelac @diegocom

@nuzelac
Copy link
Author

nuzelac commented Jan 8, 2021

@vegaro Hah, it's a very specific issue, I had to look through my old commits to see how I fixed this. 😀

The thing is, Flutter's shared_preferences plugin doesn't allow you to read any arbitrary prefs from Android, it adds a Flutter specific prefix by default and will only read prefs with the prefix. I think it will also use separate XML, but not certain about that.
I had a Xamarin app that used prefs and wanted to read these back when I migrated my app to Flutter.

If you hack around it (to make this prefix optional) you can read anything but the getter has some internal logic that converts Set to List serialized into String. This will touch RC prefs data and crash your SDK on launch next time.

https://github.com/flutter/plugins/blob/master/packages/shared_preferences/shared_preferences/android/src/main/java/io/flutter/plugins/sharedpreferences/MethodCallHandlerImpl.java#L181-L196

Honestly, I wouldn't expect you to handle this case gracefully since it's not usual behavior 🤔

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