Solved

Expo Go | Purchases SDK doesn't work during Production

  • 19 April 2023
  • 7 replies
  • 390 views

Badge +2

Hello everyone!

Everything works perfectly in Development build, but nothing related to Purchases SDK works during Production build.

 

Here’s a snippet of code which I’ll use as an example

async function checkPremium() {
    try {
      if (Platform.OS == "android") {
        Purchases.configure({ apiKey: revenuecat.google });
      } else {
        Purchases.configure({ apiKey: revenuecat.apple });
      }
      const customerInfo = await Purchases.getCustomerInfo();
      alert("customerInfo: ", customerInfo);
      return typeof customerInfo.entitlements.active["premium"] !== "undefined";
    } catch (err) {
      alert(JSON.stringify(err))
      return undefined;
    }
  }
After putting alerts in different places, it turned out I got an error at Purchases.configure part.
Note that the apiKey works and is correctly passed as an argument.
I tried to alert the error normally without JSON.stringify and it’s empty, same with JSON.stringify.
 
I’m currently testing the production build through the following command:
npx expo start --no-dev --minify
 
The same problem occurs on the published app on PlayStore, it’s been about 3 days now since it’s out.
And I can’t find a way how to debug a production build without using alerts all the time.
 
Feel free to ask for more info, any help on how to debug is appreciated too
icon

Best answer by volzey 23 April 2023, 17:40

View original

7 replies

Badge +2

I tried out Glassfy and that also gives me an error in Production, whilst everything works during Development build.

Badge +5

It sounds like you are an Android user and unfortunately I’m not familiar at all with that workflow, but I know that for iOS you can see your debug logs (i.e. console.log(...) in React Native) on a production build. It’s obviously still pretty clunky to have to redo a whole production build and install it, but if you have an issue that only happens in production, that’s one way to identify what’s going on with much better precision than using alerts.

In iOS, you have to connect the device to your Mac via USB and run the “Console” program, and you’ll see all the log messages coming from the device.

I’m sure there must be something equivalent for Android but unfortunately I don’t know what it is.

Userlevel 4
Badge +8

Hi, to assist you with this it would be great if you were able to provide debug logs as it is not really clear what could be causing this issue. 

Badge +2

Hello, thank you for your replies!

 

@asindhu At first I was trying to do console.logs and they weren’t logging anything in production so I switched to alerts. I’ll try looking into some things which I can use to get the debug logs. But still, very much thank you for your response, it’s much appreciated!

 

@Haley Pace I currently get 0 debug logs, when I alert an error, it shows nothing at all, it’s like the error is empty. I know there’s this thing:

Purchases.setDebugLogsEnabled(true);
Purchases.setup(<public_sdk_key>, <my_app_user_id>);

But when I tried it, if I remember correctly, it gave me error on the first time I called Purchases, again, the error was completely empty. (Also a question, how do you get <my_app_user_id> suppose the setDebugLogsEnabled worked)

Even the Purchases.configure({ apiKey: revenuecat.google }); gives me an empty error, there’s no issue with the API key. Could it be that there’s something wrong with the package I have itself? Something corrupt maybe? Again, thank you very much for the response!

 

Sorry for the late response.

Badge +2

@Haley Pace

Hello again! I got an error that isn’t empty.

Essentially, I made a new Expo Go project without anything on it, ran the development build with

npx expo run:android -d to check if everything’s working in Development build

Then I ran npx expo start --no-dev --minify to check if there’s an error. There was, which then I alerted and got back TypeError: Cannot read property ‘setupPurchases’ of null

So does that mean that I can only check if the app truly works after I’ve fully built it? I thought npx expo start --no-dev --minify

On my main project, no such error ever came up, there the error was empty. Well, I’ll continue to build the app with eas and hope that I get somewhere...

Badge +2

GUYS, I BUILT An APK BASES ON PREVIEW BUILD (in eas.json) AND IT SEEMS TO WORK! OMG!

Badge +2

Ok, after building production eas builds for more tens of times and changing some stuff every time, I finally got it to work! The subscription options show up.

 

It seems the reason for which the app wasn’t working was either due to something corrupt (could explain why the errors were empty and in the new project the errors actually say something) or due to the Purchases.configure({ apiKey: “...”}), as I was importing a revenuecat object from a file in constants folder, in which I extracted the API keys from .env file and assigned them to the object. Due to the build mode changing, it might’ve not worked in production.

Reply