RevenueCat / react-native-purchases

React Native in-app purchases and subscriptions made easy. Support for iOS and Android.
https://www.revenuecat.com
MIT License
740 stars 80 forks source link

purchaseStoreProduct() hangs on Android #1088

Open mihailapuste opened 1 week ago

mihailapuste commented 1 week ago

Describe the bug

Upgrading to the latest react-native-purchases from 7.2.1 to 8.2.0, I noticed that we were previously using the now deprecated purchaseProduct() function to make purchases.

export async function makePurchase(
  offering: IOfferModel,
): Promise<MakePurchaseStatusTypes> {
  try {
    const { product } = offering;

    const purchaseMade = await Purchases.purchaseProduct(
      product.identifier
    );

   .... handling

This was, and still does work perfectly fine on iOS and android. But to comply with the latest docs, I replaced this function with purchaseStoreProduct and passed the correct parameters.

export async function makePurchase(
  offering: IOfferModel,
): Promise<MakePurchaseStatusTypes> {
  try {
    const { product } = offering;

    const purchaseMade = await Purchases.purchaseStoreProduct(
      product
    );

When testing on iOS there was no issue, and I could make the purchase as before, however on android this new function causes the purchase to simply hang. No errors returned, it just seems to hang for an indefinite period. When reverting back to purchaseProduct, it works again.

Wondering if anyone else has experienced this issue, as I could not find any related issues in the comunity threads or gh tickets.

Thanks in advance!

  1. Environment
    1. Platform: android
    2. SDK version: 8.2.0
    3. OS version: Level 31
    4. Xcode/Android Studio version: AS 2023.1.1
    5. React Native version: 0.73.8
    6. SDK installation (CocoaPods + version or manual):
    7. How widespread is the issue. Percentage of devices affected.
  2. Debug logs that reproduce the issue
  3. Steps to reproduce, with a description of expected vs. actual behavior
  4. Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)

Additional context Add any other context about the problem here.

RCGitBot commented 1 week ago

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

vegaro commented 1 week ago

Can you please share some logs from the LogCat so we can see what's going on?

Thank you!

mihailapuste commented 6 days ago

Can you please share some logs from the LogCat so we can see what's going on?

Thank you!

@vegaro

Hi there So here are the relevant logcat logs. Since the app hangs, there were no logs past these that were relevant as far as I could tell.

2024-09-17 18:03:52.203 28868-29015 elabs.app.de          com.group.app.dev           E  Invalid ID 0x00000223.
2024-09-17 18:03:52.207 28868-29102 ReactNativeJS           com.group.app.dev           I  'begin_checkout', { product_id: 'com.group.app.dev.premium.subscription.annually.promo2:p1y',
                                                                                                      has_promo: false,
                                                                                                      promo_code: null,
                                                                                                      intro_screen_type: 'default',
                                                                                                      purchase_state: 'INTRO',
                                                                                                      hard_paywall_enabled: false,
                                                                                                      trial_period: null,
                                                                                                      duration: 'ANNUAL',
                                                                                                      offering: 'promo2',
                                                                                                      has_referral_user: false,
                                                                                                      ios_promotional_offer_product: null,
                                                                                                      available_discounts: undefined,
                                                                                                      selected_discount: undefined,
                                                                                                      has_completed_onboarding: false,
                                                                                                      subscription_screen_placement: 'ONBOARDING_GET_STARTED',
                                                                                                      source: 'GetStartedScreen' }
2024-09-17 18:03:52.247 28868-29104 unknown:ReactNative     com.group.app.dev           E  Caught NullPointerException when dispatching message in MessageQueueThreadHandler. This is likely caused by runnable(msg.callback) being nulled in Android Handler after dispatching and before handling (see T170239922 for more details).Currently we observe that it only happen once which is during initialisation. Due to fixing probably involve Android System code, we decide to ignore here for now and print an error message for debugging purpose in case this cause more serious issues in future.
2024-09-17 18:03:54.156 28868-29443 BufferPoolAccessor2.0   com.group.app.dev           D  bufferpool2 0x6e587b1a98 : 5(8417280 size) total buffers - 5(8417280 size) used buffers - 642/648 (recycle/alloc) - 6/649 (fetch/transfer)
2024-09-17 18:03:54.535 28868-29440 CCodecBufferChannel     com.group.app.dev           D  [c2.android.aac.decoder#901] DEBUG: elapsed: n=6 [in=0 pipeline=0 out=2]
2024-09-17 18:03:54.535 28868-29440 CCodecBufferChannel     com.group.app.dev           D  [c2.qti.avc.decoder#511] DEBUG: elapsed: n=28 [in=0 pipeline=0 out=24]
2024-09-17 18:03:54.918 28868-29452 BufferPoolAccessor2.0   com.group.app.dev           D  bufferpool2 0x6e587de528 : 5(40960 size) total buffers - 1(8192 size) used buffers - 1284/1289 (recycle/alloc) - 6/1280 (fetch/transfer)
2024-09-17 18:03:57.844 28868-29440 CCodecBufferChannel     com.group.app.dev           D  [c2.qti.avc.decoder#511] DEBUG: elapsed: n=28 [in=0 pipeline=0 out=24]
2024-09-17 18:03:57.939 28868-29452 CCodec                  com.group.app.dev           I  state->set(FLUSHING)
2024-09-17 18:03:57.940 28868-29452 CCodec                  com.group.app.dev           I  state->set(FLUSHED)
2024-09-17 18:03:57.941 28868-29420 MediaCodec              com.group.app.dev           D  keep callback message for reclaim
2024-09-17 18:03:57.941 28868-29452 CCodec                  com.group.app.dev           I  state->set(RESUMING)
2024-09-17 18:03:57.942 28868-29452 CCodecConfig            com.group.app.dev           I  query failed after returning 19 values (BAD_INDEX)
2024-09-17 18:03:57.942 28868-29452 Codec2Client            com.group.app.dev           W  query -- param skipped: index = 1342179345.
2024-09-17 18:03:57.942 28868-29452 Codec2Client            com.group.app.dev           W  query -- param skipped: index = 2415921170.
2024-09-17 18:03:57.942 28868-29452 Codec2Client            com.group.app.dev           W  query -- param skipped: index = 1610614798.
2024-09-17 18:03:57.943 28868-29452 CCodec                  com.group.app.dev           I  state->set(RUNNING)

attempt 2 with different product


2024-09-17 18:06:42.707 30171-30352 ReactNativeJS           com.group.app.dev           I  'begin_checkout', { product_id: 'com.group.app.dev.premium.subscription.quarterly.promo1b:p3m',
                                                                                                      has_promo: true,
                                                                                                      promo_code: 'promo1',
                                                                                                      intro_screen_type: 'default',
                                                                                                      purchase_state: 'ALL_PLANS',
                                                                                                      hard_paywall_enabled: false,
                                                                                                      trial_period: null,
                                                                                                      duration: 'THREE_MONTH',
                                                                                                      offering: 'promo1',
                                                                                                      has_referral_user: false,
                                                                                                      ios_promotional_offer_product: null,
                                                                                                      available_discounts: undefined,
                                                                                                      selected_discount: undefined,
                                                                                                      has_completed_onboarding: true,
                                                                                                      subscription_screen_placement: 'ONBOARDING_GET_STARTED',
                                                                                                      source: 'SubscriptionBottomBar' }
2024-09-17 18:06:42.739 30171-30353 unknown:ReactNative     com.group.app.dev           E  Caught NullPointerException when dispatching message in MessageQueueThreadHandler. This is likely caused by runnable(msg.callback) being nulled in Android Handler after dispatching and before handling (see T170239922 for more details).Currently we observe that it only happen once which is during initialisation. Due to fixing probably involve Android System code, we decide to ignore here for now and print an error message for debugging purpose in case this cause more serious issues in future.
2024-09-17 18:06:44.932 30171-30492 BufferPoolAccessor2.0   com.group.app.dev           D  bufferpool2 0x6e587b8998 : 5(8417280 size) total buffers - 5(8417280 size) used buffers - 878/884 (recycle/alloc) - 6/885 (fetch/transfer)

code

export async function makePurchase(
  offering: IOfferModel,
): Promise<MakePurchaseStatusTypes> {
  try {
    const { product } = offering;

    const purchaseMade = await Purchases.purchaseStoreProduct(
      product
    );