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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to Expo In App purchases for android default.connectAsync not defined. #7900

Closed
zelin opened this issue Apr 18, 2020 · 25 comments

Comments

@zelin
Copy link

zelin commented Apr 18, 2020

馃悰 Bug Report

Unable to connect to InAppPurchases following the documentation.

Environment

Expo CLI 3.17.21 environment info:
System:
OS: macOS 10.15.2
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.13.0 - /usr/local/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.12.0 - /usr/local/bin/npm
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5900203
Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild
npmPackages:
expo: ^36.0.2 => 36.0.2
react: ~16.9.0 => 16.9.0
react-native: https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz => 0.61.4
react-navigation: ^4.3.7 => 4.3.7
npmGlobalPackages:
expo-cli: 3.17.21

Android

Steps to Reproduce

I performed

npm install expo-in-app-purchases
npm install react-native-unimodules

In my LoadingScreen.js

import * as InAppPurchases from 'expo-in-app-purchases';

componentDidMount() {		
     this.getDetails()
}

getDetails = async () => {
			const history = await InAppPurchases.connectAsync();
}

Actual Behavior

I am getting
undefined is not an object (evaluating '_ExpoInAppPurchases.default.connectAsync')
if I use

await InAppPurchases.connectAsync();

however if i simply do

await connectAsync();

I get

Can't find variable: connectAsync

@byCedric
Copy link
Member

Hi @zelin! It looks like something is going on with the module transpiler. What's happening here is that it's trying to import the default exported value from expo-in-app-purchases, instead of all methods. Unfortunately, without a small repro I'm not sure what's going on here. But there are some things that you could try:

// This normally should work
import * as InAppPurchases from 'expo-in-app-purchases';

// You can try importing the method only, see if it works
import { connectAsync } from 'expo-in-app-purchases';

// Or even the old-school `require`
const InAppPurchases = require('expo-in-app-purchases');

Hope it helps!

@fulljsdev259
Copy link

I am facing the same issue, please help thanks.

@fulljsdev259
Copy link

@zelin are you doing it with expo kit ?

@zelin
Copy link
Author

zelin commented Apr 30, 2020

@fulljsdev259 Yes, you have to eject expo to bare workflow. Only then it will work unfortunately.

@fulljsdev259
Copy link

fulljsdev259 commented Apr 30, 2020

@zelin is your app working now ?
if yes, can you please please share your code.
thanks in advanced.

@andrewhook
Copy link

+1

@andrewhook
Copy link

andrewhook commented May 19, 2020

So I am not getting this error on iOS (simulator) when running my app using Expo Client, however, I do get it on Android (simulator/physical device).

@andrewhook
Copy link

Update: if I build a release APK using Android Studio and install on a physical device, I am able to connect to the Play Store and get products!

@kabam-srayner
Copy link

kabam-srayner commented Mar 26, 2021

Has there been any movement on this? I am completely unable to connect to the store. The below is what I ran and what showed up in my terminal after hitting the button on my physical device.

//@ts-check
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
import { connectAsync } from 'expo-in-app-purchases'

export default function App() {

  useEffect(() => {
    console.log("Test App Started")
  }, [])

  const [name, setName] = useState("Me")
  // const [items, setItems] = useState([])

  const connectButtonAction = async (evnt) => {
    console.log("Connecting to The Store")
    await connectAsync()
  }

  return (
    <View style={styles.container}>
      <Text>Author: {name}</Text>
      <Text>Test App!</Text>
      <StatusBar style="auto" />
      <Button
        onPress={connectButtonAction}
        title="Connect to Store"
        color="#841584"
        accessibilityLabel="Connect to the store"
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#ffeec0',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Results in:

Test App Started
Connecting to The Store

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_ExpoInAppPurchases.default.connectAsync')]
at http://192.168.1.17:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:138285:73 in connectAsync$
at http://192.168.1.17:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:138272:37 in connectAsync
at node_modules/react-native/Libraries/Pressability/Pressability.js:691:17 in _performTransitionSideEffects
at node_modules/react-native/Libraries/Pressability/Pressability.js:628:6 in _receiveSignal
at node_modules/react-native/Libraries/Pressability/Pressability.js:524:8 in responderEventHandlers.onResponderRelease
at [native code]:null in forEach
at [native code]:null in callFunctionReturnFlushedQueue

Any and all help would be greatly appreciated.

@dorapax-lab
Copy link

+1

@dorapax-lab
Copy link

Is there any workaround for this without ejecting expo to bare workflow ?

@dorapax-lab
Copy link

Hi @zelin! It looks like something is going on with the module transpiler. What's happening here is that it's trying to import the default exported value from expo-in-app-purchases, instead of all methods. Unfortunately, without a small repro I'm not sure what's going on here. But there are some things that you could try:

// This normally should work
import * as InAppPurchases from 'expo-in-app-purchases';

// You can try importing the method only, see if it works
import { connectAsync } from 'expo-in-app-purchases';

// Or even the old-school `require`
const InAppPurchases = require('expo-in-app-purchases');

Hope it helps!

@byCedric I have tried these and none of that worked for me :(

@gwalshington
Copy link

gwalshington commented Apr 2, 2021

I'm having the same issue on iOS, in the bare workflow after ejecting from expo. I'm on a physical devise, and logged in as a test connect user.
From the example, this line

  async componentDidMount() {
    const history = await connectAsync();
 }

returns undefined.

I currently have this in a test component on the dashboard of my app. If I go to another page, and come back, I get the error

Possible Unhandled Promise Rejection (id: 5):
Error: Already connected to App Store

So... it is connecting? Why is the initial connectAsync() coming back undefined?
I can't get past this.

UPDATE-
I decided to try and implement react-native-iap with this example and it worked the first try. This, to me, confirms it's not an issue with the set up (ie. device vs simulator, test account, etc.), it's an issue with the connectAsync() call in expo-in-app-purchases.

@dorapax-lab
Copy link

dorapax-lab commented Apr 3, 2021

@gwalshington react-native-iap has native modules which will work only in bare workflow (Expo does not support native modules). As for my understanding if you are working on react-native-iap definitely you need to eject from expo.

Check this thread for more details.

But expo-in-app-purchases is an expo bundle and it should work with expo client. I haven't tried this on IOS expo client (tried this only on Android expo client).

As per @andrewhook 's comment expo-in-app-purchases is working on IOS expo client.

@gwalshington
Copy link

@dorapax-lab It's already ejected, which is why react-native-iap works. Worked out of the box - could not get expo-in-app-purchases to work. I stand by my previous comment that connecting was returning undefined with expo's iap. I've decided not to use that package for this reason, but from what I can tell there are many others experiencing this issue.

@dorapax-lab
Copy link

dorapax-lab commented May 3, 2021

This is expo sdk's current limitation and for now only solution is bare work :/ .

There鈥檚 a feature request for managed workflow and it鈥檚 marked as Planned: https://expo.canny.io/feature-requests/p/in-app-purchases

@gwalshington FYI
With EAS CLI you can build and submit native project in just a few commands.
to learn more: https://www.youtube.com/watch?v=7E6zsRpfT4U
docs: http://docs.expo.io/eas

Let's hope this will be prioritised and implemented soon.
Also don't forget to give a thumbs up for above feature request.

@gwalshington
Copy link

@dorapax-lab no shit. in a month, please tell me again it's only available in bare workflow.

@danieltgfischer
Copy link

I tried both plugins expo-in-app-purchases and react-native-iap. On rn-iap it returns Possible Unhandled Promise Rejection (id: 3): Error: E_IAP_NOT_AVAILABL and at the expo it return [Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_ExpoInAppPurchases.default.connectAsync')]. I'm using ejected expo or bare workflow, the same setup.

@captivatingLunatic
Copy link

I am struggling with the same issues with @danieltgfischer, please advise.

@danieltgfischer
Copy link

@captivatingLunatic So apparently I was running my app with expo start even after ejecting it, so I rebuild it with yarn android and it worked perfectly BUT it throws an error when I try to test the purchase of an item. The optional oldItem option is causing this problem, I saw people who solved it by changing the BillingClient version to the same as Expo In App Purchase. This is an error because in November 2021 all BillingClient versions should be 4 and Expo is 2. Someone else removed setOldSku in BillingManager in Expo InAppPurchase folder, I tried this solution but in my case it didn't work. Anyway, I'll try react-native-iap again. Any updates, please let me know. Thanks

@captivatingLunatic
Copy link

@danieltgfischer thanks for the advice, but I could not find anyway to change BillingClient version. Please let me know if there is any path or file for doing it.
My app is also ejected from the start. I tried to build it with Android Studio, but it could not complete the build for somewhat reason.. I'll try this option once more whenever I find a better pc

@danieltgfischer
Copy link

danieltgfischer commented Jul 14, 2021

@captivatingLunatic, change BillingClint version here. If you are going to use react-native-iap, I using version 7.0.2 and it works very well!
Cheers!

@captivatingLunatic
Copy link

For those who experience problems in future with Expo InAppPurchases and react-native-iap as"E_IAP_NOT_AVAILABLE", I applied Daniel's advices and build my app with Expo first. This did not worked directly, so I did many many minor changes after reading instructions of react-native-iap. They also did not worked, until I did the build with Android Studio. Now it is working, so you need to use react-native-iap and build your app with Android Studio to avoid these problems.

@github-actions
Copy link
Contributor

This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

@github-actions github-actions bot added the stale label Feb 17, 2022
@github-actions
Copy link
Contributor

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants