expo icon indicating copy to clipboard operation
expo copied to clipboard

[SDK45] [Expo In App Purchases] [Android] Error: When Using purchaseItemAsync methods

Open lottemarines opened this issue 2 years ago • 14 comments

Summary

After updating the expo sdk from 44 to 45, I am getting the following error in the purchase process. I am not sure if it is directly related to the SDK, but I am having trouble because the error code does not bring up any research. Could you please advise?

My codes

export const purchaseProducts = async (productId: string) => {
  try {
    await purchaseItemAsync(productId);
  } catch (error) {
    console.log(error);
  }
};

My error code is here.

[Error: Encountered an exception while calling native method: Exception occurred while executing exported method purchaseItemAsync on module ExpoInAppPurchases: Attempt to invoke interface method 'java.lang.String expo.modules.core.arguments.ReadableArguments.getString(java.lang.String)' on a null object reference]

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

Android

Environment

  expo-env-info 1.0.3 environment info:
    System:
      OS: macOS 12.2.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.13.0 - ~/.nodebrew/current/bin/node
      Yarn: 1.22.17 - ~/.nodebrew/current/bin/yarn
      npm: 8.1.0 - ~/.nodebrew/current/bin/npm
      Watchman: 2022.03.21.00 - /usr/local/bin/watchman
    Managers:
      CocoaPods: 1.11.3 - /Users/ken/.rbenv/shims/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
      Android SDK:
        API Levels: 27, 28, 29, 30, 31, 32
        Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 31.0.0, 33.0.0
        System Images: android-30 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 4.1 AI-201.8743.12.41.6953283
      Xcode: 13.4/13F17a - /usr/bin/xcodebuild
    npmPackages:
      babel-preset-expo: ~9.1.0 => 9.1.0 
      expo: ^45.0.0 => 45.0.3 
      react: 17.0.2 => 17.0.2 
      react-dom: 17.0.2 => 17.0.2 
      react-native: 0.68.2 => 0.68.2 
      react-native-web: 0.17.7 => 0.17.7 
      react-navigation: ^4.4.4 => 4.4.4 
    npmGlobalPackages:
      eas-cli: 0.52.0
      expo-cli: 5.4.6
    Expo Workflow: bare

Reproducible demo

Not sure how this can be replicated.

lottemarines avatar May 26 '22 02:05 lottemarines

I have the same problem on android. The Expo SDK version is 45. (expo-in-app-purchase: 13.0.0)

gaishimo avatar May 26 '22 05:05 gaishimo

Perhaps I found the reason. It is because the details argument for Android in expo-in-app-purchase v13.

https://docs.expo.dev/versions/latest/sdk/in-app-purchases/#inapppurchasespurchaseitemasyncitemid-details

Note: both ids must be provided for payments to work on Google Play.

gaishimo avatar May 26 '22 05:05 gaishimo

struggling with the same thing, expo/react-native docs does not seem to mention how we can get it for Android users

lukasz532 avatar May 26 '22 18:05 lukasz532

The following explanation of obfuscatedAccountid and obfuscatedProfileId is helpful. https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.Builder?hl=ja#setObfuscatedAccountId(java.lang.String)

This is a mechanism to prevent fraud, but I don't think this setting should be mandatory because it is unnecessary for apps that only offer non-consumable charges 🤔

gaishimo avatar May 27 '22 00:05 gaishimo

struggling with the same thing, expo/react-native docs does not seem to mention how we can get it for Android users

The docs posted by @gaishimo indicate that these ids are up to the implementor to provide. Empty strings would technically work (as @lottemarines posted), but to avoid future regret that might arise from passing garbage into those parameters we decided to run the user id from our system through md5 and use that. If you don't have a user id from your own system maybe empty strings is the way to go (until this issue is fixed).

elliotdickison avatar May 27 '22 19:05 elliotdickison

up, having same problem with expo-in-app-purchases 13.0.0 version and expo sdk 45

artvichi avatar Jun 15 '22 17:06 artvichi

Passing empty string is working as it should be.

AlenToma avatar Jun 17 '22 09:06 AlenToma

Passing empty string is working as it should be.

for me too!

jailsonpaca avatar Jul 15 '22 00:07 jailsonpaca

Still experience this with expo-in-app-purchases 13.1.0. Has this fix been released? If not, please release it ASAP. Thank you so much

endruuu avatar Sep 06 '22 03:09 endruuu

is there any progress going on?

Bohooslav avatar Sep 19 '22 18:09 Bohooslav

The fix in https://github.com/expo/expo/pull/18272 will be released with the next SDK (SDK 47) coming this fall.

ide avatar Sep 19 '22 21:09 ide

Is there any more detailed schedule or maybe even beta?

Bohooslav avatar Sep 20 '22 05:09 Bohooslav

There will be a beta but I don't think there is yet a date announced. When the beta is available it will be announced on blog.expo.dev.

ide avatar Sep 20 '22 06:09 ide

In 13.1.0, you can avoid this error by passing details argument forcibly.

await purchaseItemAsync(productId, {
  accountIdentifiers: {
    obfuscatedAccountId: null,
    obfuscatedProfileId: null,
  } as any,
});

gaishimo avatar Sep 20 '22 08:09 gaishimo

Has anybody experienced a similar issue with finishTransactionAsync? We're getting reports of issues on Android, receiving the following error:

Error: Encountered an exception while calling native method: Exception occurred while executing exported method finishTransactionAsync on module ExpoInAppPurchases: Attempt to invoke virtual method 'void expo.modules.inapppurchases.BillingManager.acknowledgePurchaseAsync(java.lang.String, expo.modules.core.Promise)' on a null object reference

jamesedmonston avatar Nov 03 '22 13:11 jamesedmonston